6.1.178-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 127/1067 netfilter: ctnetlink: use nf_ct_exp_net() in expectation dump
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pratham Gupta <[email protected]>
commit a7f57320bbbc67e347bf5fff4b4a9bab980d5956 upstream.
Commit 02a3231b6d82 ("netfilter: nf_conntrack_expect: store netns and zone in expectation") introduced exp->net so RCU-only expectation paths no longer need to dereference exp->master for netns lookups.
Commit 3db5647984de ("netfilter: nf_conntrack_expect: skip expectations in other netns via proc") updated the proc path accordingly, but ctnetlink_exp_dump_table() still
compares against nf_ct_net(exp->master).
Use nf_ct_exp_net(exp) here as well so the netlink dump path matches the rest of the March 2026 expectation netns/RCU cleanup.
--- net/netfilter/nf_conntrack_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -3152,7 +3152,7 @@ restart:if (l3proto && exp->tuple.src.l3num != l3proto)continue ; -if (!net_eq (nf_ct_net (exp->master), net)) +if (!net_eq (nf_ct_exp_net (exp), net))continue ;if (cb->args[1 ]) {
Greg Kroah-Hartman
maintainerPATCH 101/1067 6lowpan: fix NHC entry use-after-free on error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
commit 1720db928e5a58ca7d75ac1d514c3b73fd7061a7 upstream.
lowpan_nhc_do_uncompression() looks up an NHC descriptor while holding lowpan_nhc_lock. If the descriptor has no uncompress callback, the error path drops the lock before printing nhc->name.
lowpan_nhc_del() removes descriptors under the same lock and then relies on synchronize_net() before the owning module can be unloaded. That only waits for net RX RCU readers. lowpan_header_decompress() is also exported and can be reached from callers that are not necessarily covered by the net core RX critical section, for example the Bluetooth 6LoWPAN L2CAP receive path.
This leaves a race where one task drops lowpan_nhc_lock in the error path, another task unregisters and frees the matching descriptor after synchronize_net() returns, and the first task then dereferences nhc->name for the warning.
With the post-unlock window widened, KASAN reports:
BUG: KASAN: slab-use-after-free in lowpan_nhc_do_uncompression+0x1f4/0x220 Read of size 8 lowpan_nhc_do_uncompression lowpan_header_decompress
Fix this by printing the warning before dropping lowpan_nhc_lock, so the descriptor name is read while unregister is still excluded. The malformed packet is still rejected with -ENOTSUPP.
--- net/6lowpan/nhc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/6lowpan/nhc.c +1 -1
@@ -117,9 +117,9 @@ int lowpan_nhc_do_uncompression(struct sreturn ret; } }else { -spin_unlock_bh (&lowpan_nhc_lock);netdev_warn (dev,"received nhc id for %s which is not implemented.\n" , nhc->name); +spin_unlock_bh (&lowpan_nhc_lock);return -ENOTSUPP ; } }else {
Greg Kroah-Hartman
maintainerPATCH 128/1067 netfilter: ebtables: module names must be null-terminated
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 084d23f818321390509e9738a0b08bbf46df6425 upstream.
We need to explicitly check the length, else we may pass non-null terminated string to request_module().
--- net/bridge/netfilter/ebtables.c | 3 +++ 1 file changed, 3 insertions(+)
net/bridge/netfilter/ebtables.c +3 -0
@@ -402,6 +402,9 @@ ebt_check_match(struct ebt_entry_match * left - sizeof(struct ebt_entry_match) < m->match_size)return -EINVAL ; +if (strnlen (m->u.name,XT_EXTENSION_MAXNAMELEN ) ==XT_EXTENSION_MAXNAMELEN ) +return -EINVAL ; + match =xt_find_match (NFPROTO_BRIDGE , m->u.name, m->u.revision);if (IS_ERR (match) || match->family !=NFPROTO_BRIDGE ) {if (!IS_ERR (match))
Greg Kroah-Hartman
maintainerPATCH 129/1067 netfilter: ebtables: terminate table name before find_table_lock()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
commit a622d2e9608c9dff47fc2e5759ac7aa3a836b45d upstream.
update_counters() and compat_update_counters() forward a user-supplied 32-byte table name to find_table_lock() without NUL-terminating it. On a lookup miss, find_inlist_lock() calls try_then_request_module(..., "%s%s", "ebtable_", name), and vsnprintf() reads past the name field and the stack object until it hits a zero byte.
BUG: KASAN: stack-out-of-bounds in string (lib/vsprintf.c:648 lib/vsprintf.c:730) Read of size 1 at addr ffff8880119dfb20 by task exploit/147 Call Trace: ... string (lib/vsprintf.c:648 lib/vsprintf.c:730) vsnprintf (lib/vsprintf.c:2945) __request_module (kernel/module/kmod.c:150) do_update_counters.isra.0 (net/bridge/netfilter/ebtables.c:371 net/bridge/netfilter/ebtables.c:380) update_counters (net/bridge/netfilter/ebtables.c:1440) do_ebt_set_ctl (net/bridge/netfilter/ebtables.c:2573) nf_setsockopt (net/netfilter/nf_sockopt.c:101) ip_setsockopt (net/ipv4/ip_sockglue.c:1424) raw_setsockopt (net/ipv4/raw.c:847) __sys_setsockopt (net/socket.c:2393) ...
compat_do_replace() shares the same unterminated name via compat_copy_ebt_replace_from_user(); terminate it there too so all find_table_lock() callers behave alike. The other callers already terminate the name after the copy.
--- net/bridge/netfilter/ebtables.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bridge/netfilter/ebtables.c +6 -0
@@ -1433,6 +1433,8 @@ static int update_counters(struct net *nif (copy_from_sockptr (&hlp, arg,sizeof (hlp)))return -EFAULT ; + hlp.name[sizeof (hlp.name) -1 ] ='\0' ; +if (len !=sizeof (hlp) + hlp.num_counters *sizeof (struct ebt_counter ))return -EINVAL ;
@@ -2272,6 +2274,8 @@ static int compat_copy_ebt_replace_from_memcpy (repl, &tmp, offsetof(struct ebt_replace , hook_entry)); + repl->name[sizeof (repl->name) -1 ] ='\0' ; +/* starting with hook_entry, 32 vs. 64 bit structures are different */ for (i =0 ; i <NF_BR_NUMHOOKS ; i++) repl->hook_entry[i] =compat_ptr (tmp.hook_entry[i]);
@@ -2394,6 +2398,8 @@ static int compat_update_counters(structif (copy_from_sockptr (&hlp, arg,sizeof (hlp)))return -EFAULT ; + hlp.name[sizeof (hlp.name) -1 ] ='\0' ; +/* try real handler in case userland supplied needed padding */ if (len !=sizeof (hlp) + hlp.num_counters *sizeof (struct ebt_counter ))return update_counters (net, arg, len);
Greg Kroah-Hartman
maintainerPATCH 130/1067 Bluetooth: btmtksdio: fix infinite loop in btmtksdio_txrx_work()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sergey Senozhatsky <[email protected]>
commit a257407e2bbbb099ed427719a50563f67fa366d8 upstream.
Every once in a while we see a hung btmtksdio_flush() task:
INFO: task kworker/u17:0:189 blocked for more than 122 seconds. __cancel_work_timer+0x3f4/0x460 cancel_work_sync+0x1c/0x2c btmtksdio_flush+0x2c/0x40 hci_dev_open_sync+0x10c4/0x2190 [..]
It all boils down to incorrect time_is_before_jiffies() usage in btmtksdio_txrx_work(). The btmtksdio_txrx_work() loop is expected to be terminated if running for longer than 5*HZ. However the timeout check is twisted: time_is_before_jiffies(old_jiffies + 5*HZ) evaluates to true when old_jiffies + 5*HZ is in the past i.e. when a timeout has occurred. Using OR with time_is_before_jiffies(txrx_timeout) means that:
- before the 5-second timeout: the condition is int_status || false, so it loops as long as there are pending interrupts.
- after the 5-second timeout: the condition becomes int_status || true, which is always true.
When the loop becomes infinite btmtksdio_txrx_work() loop never terminates and never releases the SDIO host.
Fix loop termination condition to actually enforce a 5*HZ timeout.
--- drivers/bluetooth/btmtksdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bluetooth/btmtksdio.c +1 -1
@@ -605,7 +605,7 @@ static void btmtksdio_txrx_work(struct wif (btmtksdio_rx_packet (bdev, rx_size) <0 ) bdev->hdev->stat.err_rx++; } - }while (int_status ||time_is_before_jiffies (txrx_timeout)); + }while (int_status &&time_is_after_jiffies (txrx_timeout));/* Enable interrupt */ sdio_writel (bdev->func,C_INT_EN_SET ,MTK_REG_CHLPCR ,0 );
Greg Kroah-Hartman
maintainerPATCH 131/1067 Bluetooth: bnep: pin L2CAP connection during netdev registration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yousef Alhouseen <[email protected]>
commit bb067a99a0356196c0b89a95721985485ebce5a5 upstream.
bnep_add_connection() reads the L2CAP connection without holding the channel lock, then passes its HCI device to register_netdev(). Controller teardown can clear and release that connection concurrently, leaving the network device registration path to dereference a freed parent device.
Take a reference to the L2CAP connection while holding the channel lock. Retain it until register_netdev() has taken the parent device reference.
--- net/bluetooth/bnep/core.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
net/bluetooth/bnep/core.c +21 -6
@@ -562,14 +562,18 @@ static int bnep_session(void *arg)return 0 ; } -static struct device *bnep_get_device (struct bnep_session *session) +static struct l2cap_conn *bnep_get_conn (struct bnep_session *session) { -struct l2cap_conn *conn =l2cap_pi (session->sock->sk)->chan->conn; +struct l2cap_chan *chan =l2cap_pi (session->sock->sk)->chan; +struct l2cap_conn *conn; -if (!conn || !conn->hcon) -return NULL ; +l2cap_chan_lock (chan); + conn = chan->conn; +if (conn) +l2cap_conn_get (conn); +l2cap_chan_unlock (chan); -return &conn->hcon->dev; +return conn; }static struct device_type bnep_type = {
@@ -581,6 +585,7 @@ int bnep_add_connection(struct bnep_connu32 valid_flags =BIT (BNEP_SETUP_RESPONSE );struct net_device *dev;struct bnep_session *s, *ss; +struct l2cap_conn *conn =NULL ;u8 dst[ETH_ALEN ], src[ETH_ALEN ];int err;
@@ -640,10 +645,18 @@ int bnep_add_connection(struct bnep_connbnep_set_default_proto_filter (s);#endif -SET_NETDEV_DEV (dev,bnep_get_device (s)); + conn =bnep_get_conn (s); +if (!conn) { + err = -ENOTCONN ; + goto failed; + } + +SET_NETDEV_DEV (dev, &conn->hcon->dev);SET_NETDEV_DEVTYPE (dev, &bnep_type); err =register_netdev (dev); +l2cap_conn_put (conn); + conn =NULL ;if (err) goto failed;
@@ -665,6 +678,8 @@ int bnep_add_connection(struct bnep_connreturn 0 ; failed: +if (conn) +l2cap_conn_put (conn);up_write (&bnep_session_sem);free_netdev (dev);return err;
Greg Kroah-Hartman
maintainerPATCH 132/1067 Bluetooth: fix UAF in bt_accept_dequeue()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yousef Alhouseen <[email protected]>
commit 4bd0b274054f2679f28b70222b607bb0afc3ab9a upstream.
bt_accept_get() takes a temporary reference before dropping the accept queue lock. bt_accept_dequeue() currently drops that reference before bt_accept_unlink(), leaving only the queue reference.
bt_accept_unlink() drops the queue reference. The subsequent sock_hold() therefore accesses freed memory if it was the final reference, as observed by KASAN during listening L2CAP socket cleanup.
Retain the temporary queue-walk reference through unlink and hand it to the caller on success. Drop it explicitly on the closed and not-yet-connected paths.
--- net/bluetooth/af_bluetooth.c | 17 +++-------------- net/bluetooth/l2cap_sock.c | 4 ++-- 2 files changed, 5 insertions(+), 16 deletions(-)
net/bluetooth/af_bluetooth.c +3 -14
@@ -305,7 +305,7 @@ struct sock *bt_accept_dequeue(struct so restart:for (sk =bt_accept_get (parent,NULL ); sk; sk = next) { -/* Prevent early freeing of sk due to unlink and sock_kill */ +/* The reference from bt_accept_get() keeps sk alive. */ lock_sock (sk);/* Check sk has not already been unlinked via
@@ -321,13 +321,11 @@ restart: next =bt_accept_get (parent, sk); -/* sk is safely in the parent list so reduce reference count */ -sock_put (sk); -/* FIXME: Is this check still needed */ if (sk->sk_state ==BT_CLOSED ) {bt_accept_unlink (sk);release_sock (sk); +sock_put (sk);continue ; }
@@ -337,16 +335,6 @@ restart:if (newsock)sock_graft (sk, newsock); -/* Hand the caller a reference taken while sk is -* still locked. bt_accept_unlink() just dropped -* the accept-queue reference; without this hold a -* concurrent teardown (e.g. l2cap_conn_del() -> -* l2cap_sock_kill()) could free sk between -* release_sock() and the caller using it. Every -* caller drops this with sock_put() when done. -*/ -sock_hold (sk); -release_sock (sk);if (next)sock_put (next);
@@ -354,6 +342,7 @@ restart: }release_sock (sk); +sock_put (sk); }return NULL ;
net/bluetooth/l2cap_sock.c +2 -2
@@ -1465,8 +1465,8 @@ static void l2cap_sock_cleanup_listen(st/* Close not yet accepted channels. * -* bt_accept_dequeue() now returns sk with an extra reference held -* (taken while sk was still locked) so a concurrent l2cap_conn_del() +* bt_accept_dequeue() returns sk with its temporary queue-walk +* reference held, so a concurrent l2cap_conn_del() * -> l2cap_sock_kill() cannot free sk under us. * * cleanup_listen() runs under the parent sk lock, so unlike
Greg Kroah-Hartman
maintainerPATCH 133/1067 Bluetooth: L2CAP: validate option length before reading conf opt value
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 687617555cedfb74c9e3cb85d759b908dcb17856 upstream.
l2cap_get_conf_opt() derives the option length from the attacker-controlled opt->len field and immediately dereferences opt->val (as u8, get_unaligned_le16() or get_unaligned_le32(), or a raw pointer for the default case) before any caller has confirmed that opt->len bytes are present in the buffer. The callers (l2cap_parse_conf_req(), l2cap_parse_conf_rsp() and l2cap_conf_rfc_get()) only detect a malformed option afterwards, once the running length has gone negative, by which point the out-of-bounds read has already executed.
An existing post-hoc length check keeps the garbage value from being consumed, so this is not a data leak in the current control flow. It is still a validate-after-use ordering bug: up to 4 bytes are read past the end of the buffer before it is known to contain them, and it is fragile to future changes in the callers.
Fix it at the source. Pass the end of the buffer into l2cap_get_conf_opt() and refuse to touch opt->val unless the full option (header + value) fits. Each caller computes an end pointer once before the loop and checks the return value directly instead of inferring the error from a negative length.
--- net/bluetooth/l2cap_core.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)
net/bluetooth/l2cap_core.c +28 -8
@@ -3188,13 +3188,24 @@ fail:return NULL ; } -static inline int l2cap_get_conf_opt (void **ptr,int *type,int *olen, -unsigned long *val) +static inline int l2cap_get_conf_opt (void **ptr,void *end,int *type, +int *olen,unsigned long *val) {struct l2cap_conf_opt *opt = *ptr;int len; +/* opt->len is attacker-controlled. Validate that the full option +* (header + value) actually fits in the buffer before touching +* opt->val, otherwise the switch below reads past the end of the +* caller's buffer. +*/ +if (end - *ptr <L2CAP_CONF_OPT_SIZE ) +return -EINVAL ; + len =L2CAP_CONF_OPT_SIZE + opt->len; +if (end - *ptr < len) +return -EINVAL ; + *ptr += len; *type = opt->type;
@@ -3600,6 +3611,7 @@ static int l2cap_parse_conf_req(struct lvoid *ptr = rsp->data;void *endptr = data + data_size;void *req = chan->conf_req; +void *req_end = req + chan->conf_len;int len = chan->conf_len;int type, hint, olen;unsigned long val;
@@ -3613,9 +3625,11 @@ static int l2cap_parse_conf_req(struct lBT_DBG ("chan %p" , chan);while (len >=L2CAP_CONF_OPT_SIZE ) { - len -=l2cap_get_conf_opt (&req, &type, &olen, &val); -if (len <0 ) +int ret =l2cap_get_conf_opt (&req, req_end, &type, &olen, &val); + +if (ret <0 )break ; + len -= ret; hint = type &L2CAP_CONF_HINT ; type &=L2CAP_CONF_MASK ;
@@ -3849,6 +3863,7 @@ static int l2cap_parse_conf_rsp(struct lstruct l2cap_conf_req *req = data;void *ptr = req->data;void *endptr = data + size; +void *rsp_end = rsp + len;int type, olen;unsigned long val;struct l2cap_conf_rfc rfc = { .mode =L2CAP_MODE_BASIC };
@@ -3857,9 +3872,11 @@ static int l2cap_parse_conf_rsp(struct lBT_DBG ("chan %p, rsp %p, len %d, req %p" , chan, rsp, len, data);while (len >=L2CAP_CONF_OPT_SIZE ) { - len -=l2cap_get_conf_opt (&rsp, &type, &olen, &val); -if (len <0 ) +int ret =l2cap_get_conf_opt (&rsp, rsp_end, &type, &olen, &val); + +if (ret <0 )break ; + len -= ret;switch (type) {case L2CAP_CONF_MTU :
@@ -4112,6 +4129,7 @@ static void l2cap_conf_rfc_get(struct l2 {int type, olen;unsigned long val; +void *rsp_end = rsp + len;/* Use sane default values in case a misbehaving remote device * did not send an RFC or extended window size option. */
@@ -4130,9 +4148,11 @@ static void l2cap_conf_rfc_get(struct l2return ;while (len >=L2CAP_CONF_OPT_SIZE ) { - len -=l2cap_get_conf_opt (&rsp, &type, &olen, &val); -if (len <0 ) +int ret =l2cap_get_conf_opt (&rsp, rsp_end, &type, &olen, &val); + +if (ret <0 )break ; + len -= ret;switch (type) {case L2CAP_CONF_RFC :
Greg Kroah-Hartman
maintainerPATCH 134/1067 net: Drop the lock in skb_may_tx_timestamp()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
commit 983512f3a87fd8dc4c94dfa6b596b6e57df5aad7 upstream.
skb_may_tx_timestamp() may acquire sock::sk_callback_lock. The lock must not be taken in IRQ context, only softirq is okay. A few drivers receive the timestamp via a dedicated interrupt and complete the TX timestamp from that handler. This will lead to a deadlock if the lock is already write-locked on the same CPU.
Taking the lock can be avoided. The socket (pointed by the skb) will remain valid until the skb is released. The ->sk_socket and ->file member will be set to NULL once the user closes the socket which may happen before the timestamp arrives.
If we happen to observe the pointer while the socket is closing but before the pointer is set to NULL then we may use it because both pointer (and the file's cred member) are RCU freed.
Drop the lock. Use READ_ONCE() to obtain the individual pointer. Add a matching WRITE_ONCE() where the pointer are cleared.
[ adapted sk_set_socket() in include/net/sock.h to fix the conflict from
not having commit 5d6b58c932ec ("net: lockless sock_i_ino()") and the additional previous changes required by it.
It comes down to just now having the lines of
if (sock) {
WRITE_ONCE(sk->sk_uid, SOCK_INODE(sock)->i_uid);
WRITE_ONCE(sk->sk_ino, SOCK_INODE(sock)->i_ino);
}below the changed line. ]
--- include/net/sock.h | 2 +- net/core/skbuff.c | 23 ++++++++++++++++++----- net/socket.c | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-)
include/net/sock.h +1 -1
@@ -2181,7 +2181,7 @@ static inline int sk_rx_queue_get(const struct sock *sk)static inline void sk_set_socket (struct sock *sk,struct socket *sock) { - sk->sk_socket = sock; +WRITE_ONCE (sk->sk_socket, sock); }static inline wait_queue_head_t *sk_sleep (struct sock *sk)
net/core/skbuff.c +18 -5
@@ -4948,15 +4948,28 @@ static void __skb_complete_tx_timestamp(struct sk_buff *skb,static bool skb_may_tx_timestamp (struct sock *sk,bool tsonly) { -bool ret; +struct socket *sock; +struct file *file; +bool ret = false;if (likely (READ_ONCE (sysctl_tstamp_allow_data) || tsonly))return true; -read_lock_bh (&sk->sk_callback_lock); - ret = sk->sk_socket && sk->sk_socket->file && -file_ns_capable (sk->sk_socket->file, &init_user_ns,CAP_NET_RAW ); -read_unlock_bh (&sk->sk_callback_lock); +/* The sk pointer remains valid as long as the skb is. The sk_socket and +* file pointer may become NULL if the socket is closed. Both structures +* (including file->cred) are RCU freed which means they can be accessed +* within a RCU read section. +*/ +rcu_read_lock (); + sock =READ_ONCE (sk->sk_socket); +if (!sock) + goto out; + file =READ_ONCE (sock->file); +if (!file) + goto out; + ret =file_ns_capable (file, &init_user_ns,CAP_NET_RAW ); +out: +rcu_read_unlock ();return ret; }
net/socket.c +1 -1
@@ -666,7 +666,7 @@ static void __sock_release(struct socket *sock, struct inode *inode)iput (SOCK_INODE (sock));return ; } - sock->file =NULL ; +WRITE_ONCE (sock->file,NULL ); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 135/1067 ksmbd: add permission checks for FSCTL_DUPLICATE_EXTENTS_TO_FILE
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
commit 388e4139db27a9e3612c9d356b826f5b1ff6a9e3 upstream.
The FSCTL_DUPLICATE_EXTENTS_TO_FILE arm of smb2_ioctl() overwrites the destination file's data via vfs_clone_file_range() with neither the share-level KSMBD_TREE_CONN_FLAG_WRITABLE check nor a per-handle fp->daccess check that the other write-bearing arms carry. A client can overwrite destination data on a read-only share, or from a handle opened with only FILE_WRITE_ATTRIBUTES (which still yields an FMODE_WRITE filp). FILE_WRITE_ATTRIBUTES-only destination handle overwrote the file's data via the clone. Add both checks, matching the FSCTL_SET_SPARSE permission fix; require FILE_WRITE_DATA since this writes data.
--- fs/smb/server/smb2pdu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/server/smb2pdu.c +11 -0
@@ -8033,6 +8033,17 @@ int smb2_ioctl(struct ksmbd_work *work) goto dup_ext_out; } +if (!test_tree_conn_flag (work->tcon, +KSMBD_TREE_CONN_FLAG_WRITABLE )) { + ret = -EACCES ; + goto dup_ext_out; + } + +if (!(fp_out->daccess &FILE_WRITE_DATA_LE )) { + ret = -EACCES ; + goto dup_ext_out; + } + src_off =le64_to_cpu (dup_ext->SourceFileOffset); dst_off =le64_to_cpu (dup_ext->TargetFileOffset); length =le64_to_cpu (dup_ext->ByteCount);
Greg Kroah-Hartman
maintainerPATCH 136/1067 ksmbd: add a permission check for FSCTL_SET_ZERO_DATA
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
commit 3320ba068198adc144c89d6661b805acce01735b upstream.
FSCTL_SET_ZERO_DATA in smb2_ioctl() destroys file data via ksmbd_vfs_zero_data() -> vfs_fallocate(PUNCH_HOLE/ZERO_RANGE) after checking only the share-level KSMBD_TREE_CONN_FLAG_WRITABLE, with no per-handle access check. A handle opened with only FILE_WRITE_ATTRIBUTES still yields an FMODE_WRITE filp (FILE_WRITE_ATTRIBUTES is part of FILE_WRITE_DESIRE_ACCESS_LE, so smb2_create_open_flags() opens it O_WRONLY), so the vfs_fallocate FMODE_WRITE check does not stop it; only the missing fp->daccess gate would. Reproduced on mainline 7.1-rc7 with KASAN by an authenticated SMB client: a FILE_WRITE_ATTRIBUTES-only handle zeroed 4096 bytes of file data it had no FILE_WRITE_DATA right to (6/6; a FILE_READ_DATA-only handle was correctly denied).
This is the unfixed sibling of commit cc57232cae23 ("ksmbd: fix FSCTL permission bypass by adding a permission check for FSCTL_SET_SPARSE"). Because SET_ZERO_DATA writes data (not an attribute), require FILE_WRITE_DATA.
--- fs/smb/server/smb2pdu.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/smb/server/smb2pdu.c +6 -0
@@ -7958,6 +7958,12 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; } +if (!(fp->daccess &FILE_WRITE_DATA_LE )) { +ksmbd_fd_put (work, fp); + ret = -EACCES ; + goto out; + } + ret =ksmbd_vfs_zero_data (work, fp, off, len);ksmbd_fd_put (work, fp);if (ret <0 )
Greg Kroah-Hartman
maintainerPATCH 137/1067 ksmbd: serialize QUERY_DIRECTORY requests per file
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit be6d26bf27499977c746abc163659915082348d8 upstream.
smb2_query_dir() stores a pointer to its stack-allocated private data in the ksmbd_file readdir_data. Concurrent QUERY_DIRECTORY requests using the same file handle can overwrite this pointer while an iterate_dir() callback is still using it, resulting in a stack use-after-free.
Add a per-file mutex and hold it while accessing the shared directory enumeration state. The lock covers scan restart, dot entry state, readdir_data setup and iteration, and response construction. This prevents another request from replacing readdir_data.private before the current request has finished using it and also serializes the shared file position.
--- fs/smb/server/smb2pdu.c | 4 ++++ fs/smb/server/vfs_cache.c | 1 + fs/smb/server/vfs_cache.h | 2 ++ 3 files changed, 7 insertions(+)
fs/smb/server/smb2pdu.c +4 -0
@@ -4126,6 +4126,8 @@ int smb2_query_dir(struct ksmbd_work *woksmbd_debug (SMB ,"Search pattern is %s\n" , srch_ptr); } +mutex_lock (&dir_fp->readdir_lock); +if (srch_flag &SMB2_REOPEN || srch_flag &SMB2_RESTART_SCANS ) {ksmbd_debug (SMB ,"Restart directory scan\n" );generic_file_llseek (dir_fp->filp,0 ,SEEK_SET );
@@ -4230,6 +4232,7 @@ no_buf_len: goto err_out; } +mutex_unlock (&dir_fp->readdir_lock);kfree (srch_ptr);ksmbd_fd_put (work, dir_fp);ksmbd_revert_fsids (work);
@@ -4237,6 +4240,7 @@ no_buf_len: err_out:pr_err ("error while processing smb2 query dir rc = %d\n" , rc); +mutex_unlock (&dir_fp->readdir_lock);kfree (srch_ptr); err_out2:
fs/smb/server/vfs_cache.c +1 -0
@@ -574,6 +574,7 @@ struct ksmbd_file *ksmbd_open_fd(structINIT_LIST_HEAD (&fp->node);INIT_LIST_HEAD (&fp->lock_list);spin_lock_init (&fp->f_lock); +mutex_init (&fp->readdir_lock);atomic_set (&fp->refcount,1 ); fp->filp = filp;
fs/smb/server/vfs_cache.h +2 -0
@@ -8,6 +8,7 @@#include <linux/file.h> #include <linux/fs.h> +#include <linux/mutex.h> #include <linux/rwsem.h> #include <linux/spinlock.h> #include <linux/idr.h>
@@ -103,6 +104,7 @@ struct ksmbd_file {/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data; +struct mutex readdir_lock;int dot_dotdot[2 ];unsigned int f_state;bool reserve_lease_break;
Greg Kroah-Hartman
maintainerPATCH 102/1067 tipc: fix out-of-bounds read in broadcast Gap ACK blocks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Page <[email protected]>
commit 2b66974a1b6134a4bbc3bfed181f7418f688eb54 upstream.
A broadcast PROTOCOL/STATE_MSG can carry a Gap ACK blocks record in its data area. tipc_get_gap_ack_blks() only verifies that the record's len field is self-consistent with its ugack_cnt/bgack_cnt counts (sz == struct_size(p, gacks, ugack_cnt + bgack_cnt)); it does not check that the record actually fits in the message data area, msg_data_sz().
The unicast caller tipc_link_proto_rcv() bounds it ("if (glen > dlen) break;"), but the broadcast caller tipc_bcast_sync_rcv() discards the returned size, so tipc_link_advance_transmq() copies the record off the receive skb with an attacker-controlled count:
this_ga = kmemdup(ga, struct_size(ga, gacks, ga->bgack_cnt), GFP_ATOMIC);
A TIPC neighbour that negotiated TIPC_GAP_ACK_BLOCK triggers it with one ordinary broadcast STATE_MSG (msg_bc_ack_invalid() clear), sized so its data area is short, carrying a Gap ACK record with len = 0x400, bgack_cnt = 0xff and ugack_cnt = 0. len then equals struct_size(p, gacks, 255), so the consistency check passes and ga is non-NULL; kmemdup() reads struct_size(ga, gacks, 255) = 1024 bytes out of the much smaller skb:
BUG: KASAN: slab-out-of-bounds in kmemdup_noprof+0x48/0x60 Read of size 1024 at addr ffff0000c7030d38 by task poc864/69 Call trace: kmemdup_noprof+0x48/0x60 tipc_link_advance_transmq+0x86c/0xb80 tipc_link_bc_ack_rcv+0x19c/0x1e0 tipc_bcast_sync_rcv+0x1c4/0x2c4 tipc_rcv+0x85c/0x1340 tipc_l2_rcv_msg+0xac/0x104 The buggy address belongs to the object at ffff0000c7030d00 which belongs to the cache skbuff_small_head of size 704 The buggy address is located 56 bytes inside of allocated 704-byte region [ffff0000c7030d00, ffff0000c7030fc0)
The copied-out bytes are subsequently consumed as gap/ack values, but the read is already out of bounds at the kmemdup() regardless of how they are used.
The unicast STATE path drops such a message: "if (glen > dlen) break;" skips the rest of STATE_MSG handling and the skb is freed. Make the broadcast path drop it too. tipc_bcast_sync_rcv() now bounds the record against msg_data_sz() and, when it does not fit, reports it back through tipc_node_bc_sync_rcv() to tipc_rcv() so the skb is discarded rather than processed. ga is not cleared on this path: ga == NULL already means "legacy peer without Selective ACK", a distinct legitimate state.
--- net/tipc/bcast.c | 22 ++++++++++++++-------- net/tipc/bcast.h | 2 +- net/tipc/node.c | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 12 deletions(-)
net/tipc/bcast.c +14 -8
@@ -497,12 +497,13 @@ void tipc_bcast_ack_rcv(struct net *net,*/ int tipc_bcast_sync_rcv (struct net *net,struct tipc_link *l,struct tipc_msg *hdr, -struct sk_buff_head *retrq) +struct sk_buff_head *retrq,bool *valid) {struct sk_buff_head *inputq = &tipc_bc_base (net)->inputq;struct tipc_gap_ack_blks *ga;struct sk_buff_head xmitq;int rc =0 ; +u16 glen;__skb_queue_head_init (&xmitq);
@@ -510,13 +511,18 @@ int tipc_bcast_sync_rcv(struct net *net,if (msg_type (hdr) !=STATE_MSG ) {tipc_link_bc_init_rcv (l, hdr); }else if (!msg_bc_ack_invalid (hdr)) { -tipc_get_gap_ack_blks (&ga, l, hdr, false); -if (!sysctl_tipc_bc_retruni) - retrq = &xmitq; - rc =tipc_link_bc_ack_rcv (l,msg_bcast_ack (hdr), -msg_bc_gap (hdr), ga, &xmitq, - retrq); - rc |=tipc_link_bc_sync_rcv (l, hdr, &xmitq); + glen =tipc_get_gap_ack_blks (&ga, l, hdr, false); +if (glen >msg_data_sz (hdr)) { +/* Malformed Gap ACK blocks; caller drops the msg */ + *valid = false; + }else { +if (!sysctl_tipc_bc_retruni) + retrq = &xmitq; + rc =tipc_link_bc_ack_rcv (l,msg_bcast_ack (hdr), +msg_bc_gap (hdr), ga, &xmitq, + retrq); + rc |=tipc_link_bc_sync_rcv (l, hdr, &xmitq); + } }tipc_bcast_unlock (net);
net/tipc/bcast.h +1 -1
@@ -97,7 +97,7 @@ void tipc_bcast_ack_rcv(struct net *net, struct tipc_msg *hdr);int tipc_bcast_sync_rcv (struct net *net,struct tipc_link *l,struct tipc_msg *hdr, -struct sk_buff_head *retrq); +struct sk_buff_head *retrq,bool *valid);int tipc_nl_add_bc_link (struct net *net,struct tipc_nl_msg *msg,struct tipc_link *bcl);int tipc_nl_bc_link_set (struct net *net,struct nlattr *attrs[]);
net/tipc/node.c +12 -3
@@ -1833,12 +1833,15 @@ static void tipc_node_mcast_rcv(struct t }static void tipc_node_bc_sync_rcv (struct tipc_node *n,struct tipc_msg *hdr, -int bearer_id,struct sk_buff_head *xmitq) +int bearer_id,struct sk_buff_head *xmitq, +bool *valid) {struct tipc_link *ucl;int rc; - rc =tipc_bcast_sync_rcv (n->net, n->bc_entry.link, hdr, xmitq); + rc =tipc_bcast_sync_rcv (n->net, n->bc_entry.link, hdr, xmitq, valid); +if (!*valid) +return ;if (rc &TIPC_LINK_DOWN_EVT ) {tipc_node_reset_links (n);
@@ -2142,12 +2145,18 @@ rcv:/* Ensure broadcast reception is in synch with peer's send state */ if (unlikely (usr ==LINK_PROTOCOL )) { +bool valid = true; +if (unlikely (skb_linearize (skb))) {tipc_node_put (n); goto discard; } hdr =buf_msg (skb); -tipc_node_bc_sync_rcv (n, hdr, bearer_id, &xmitq); +tipc_node_bc_sync_rcv (n, hdr, bearer_id, &xmitq, &valid); +if (!valid) { +tipc_node_put (n); + goto discard; + } }else if (unlikely (tipc_link_acked (n->bc_entry.link) != bc_ack)) {tipc_bcast_ack_rcv (net, n->bc_entry.link, hdr); }
Greg Kroah-Hartman
maintainerPATCH 138/1067 ksmbd: fix UAF of struct file_lock in SMB2_LOCK deferred-lock cancellation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Davide Ornaghi <[email protected]>
commit d20d1c8ba5765d1d12eefc0aee6385ab3f240e1e upstream.
When a blocking byte-range lock request is deferred in the FILE_LOCK_DEFERRED path, ksmbd registers the asynchronous work into the connection's async_requests list via setup_async_work(). The cancel callback smb2_remove_blocked_lock() holds a reference to the flock.
If the lock waiter is subsequently woken up but the work state is no longer KSMBD_WORK_ACTIVE (e.g., due to a concurrent cancellation), the cleanup path calls locks_free_lock(flock) without dequeuing the work from the async_requests list. Concurrently, smb2_cancel() walks the list under conn->request_lock and invokes the cancel callback, which then dereferences the already freed 'flock'. This leads to a slab-use-after-free inside __wake_up_common.
Fix this by restructuring the cleanup logic after the worker returns from ksmbd_vfs_posix_lock_wait(). Move list_del(&smb_lock->llist) and release_async_work(work) to the top of the cleanup block. This guarantees that the async work is completely dequeued and serialized under conn->request_lock before locks_free_lock(flock) is called, rendering the flock unreachable for any concurrent smb2_cancel().
--- fs/smb/server/smb2pdu.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
fs/smb/server/smb2pdu.c +16 -18
@@ -7229,29 +7229,27 @@ skip:list_del (&work->fp_entry);spin_unlock (&fp->f_lock); -if (work->state !=KSMBD_WORK_ACTIVE ) { -list_del (&smb_lock->llist); -locks_free_lock (flock); +list_del (&smb_lock->llist); +release_async_work (work); + +if (work->state ==KSMBD_WORK_ACTIVE ) + goto retry; -if (work->state ==KSMBD_WORK_CANCELLED ) { - rsp->hdr.Status = -STATUS_CANCELLED ; -kfree (smb_lock); -smb2_send_interim_resp (work, -STATUS_CANCELLED ); - work->send_no_response =1 ; - goto out; - } +locks_free_lock (flock); - rsp->hdr.Status = -STATUS_RANGE_NOT_LOCKED ; +if (work->state ==KSMBD_WORK_CANCELLED ) { + rsp->hdr.Status =STATUS_CANCELLED ;kfree (smb_lock); - goto out2; +smb2_send_interim_resp (work, +STATUS_CANCELLED ); + work->send_no_response =1 ; + goto out; } -list_del (&smb_lock->llist); -release_async_work (work); - goto retry; + rsp->hdr.Status = +STATUS_RANGE_NOT_LOCKED ; +kfree (smb_lock); + goto out2; }else if (!rc) {list_add (&smb_lock->llist, &rollback_list);spin_lock (&work->conn->llist_lock);
Greg Kroah-Hartman
maintainerPATCH 139/1067 ksmbd: require source read access for duplicate extents
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit cedff600f1642aa982178503552f0d007bc829c8 upstream.
FSCTL_DUPLICATE_EXTENTS_TO_FILE passes the source file directly to vfs_clone_file_range() or vfs_copy_file_range() without checking the SMB access mask granted to the source handle. A handle opened with attribute access can consequently be used to copy file contents into an attacker-readable destination.
Require FILE_READ_DATA on the source handle before either VFS operation, matching other ksmbd data-copy paths.
--- fs/smb/server/smb2pdu.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/smb/server/smb2pdu.c +4 -0
@@ -8051,6 +8051,10 @@ int smb2_ioctl(struct ksmbd_work *work) ret = -EACCES ; goto dup_ext_out; } +if (!(fp_in->daccess &FILE_READ_DATA_LE )) { + ret = -EACCES ; + goto dup_ext_out; + } src_off =le64_to_cpu (dup_ext->SourceFileOffset); dst_off =le64_to_cpu (dup_ext->TargetFileOffset);
Greg Kroah-Hartman
maintainerPATCH 140/1067 ksmbd: add a WRITE_DAC/WRITE_OWNER check to SMB2 SET_INFO SECURITY
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
commit 44df157a1183a7f746caa970c169255da5ac61f8 upstream.
commit cc57232cae23 ("ksmbd: fix FSCTL permission bypass by adding a permission check for FSCTL_SET_SPARSE") added a fp->daccess gate to fsctl_set_sparse and noted that "similar handle-level checks exist in other functions but are missing here." The SMB2 SET_INFO SECURITY arm is one of the missing ones, and the most security-relevant: smb2_set_info_sec() calls set_info_sec() with no per-handle access check.
set_info_sec() (fs/smb/server/smbacl.c) re-permissions the file: it rewrites owner/group/mode via notify_change(), rewrites the POSIX ACL via set_posix_acl(), and on KSMBD_SHARE_FLAG_ACL_XATTR shares removes and rewrites the Windows security descriptor via ksmbd_vfs_set_sd_xattr(). Every other persistent-mutation arm of the sibling handler smb2_set_info_file() checks fp->daccess first (FILE_WRITE_DATA / FILE_DELETE / FILE_WRITE_EA / FILE_WRITE_ATTRIBUTES); the SECURITY arm — which mutates the access control itself — is the only one with no gate.
A client can therefore open a handle with FILE_WRITE_ATTRIBUTES only (no FILE_WRITE_DAC / FILE_WRITE_OWNER) and use SMB2_SET_INFO with InfoType SMB2_O_INFO_SECURITY to rewrite the file's DACL and owner, granting itself access the handle's daccess never carried. Unlike the FSCTL data arms this is a metadata/xattr operation, so there is no FMODE_WRITE VFS backstop — the missing fp->daccess check is the entire gate.
Setting a security descriptor is the WRITE_DAC / WRITE_OWNER operation, so require at least one of those on the handle before re-permissioning the file. -EACCES is mapped to STATUS_ACCESS_DENIED by smb2_set_info().
--- fs/smb/server/smb2pdu.c | 3 +++ 1 file changed, 3 insertions(+)
fs/smb/server/smb2pdu.c +3 -0
@@ -6117,6 +6117,9 @@ static int smb2_set_info_sec(struct ksmb fp->saccess |=FILE_SHARE_DELETE_LE ; +if (!(fp->daccess & (FILE_WRITE_DAC_LE |FILE_WRITE_OWNER_LE ))) +return -EACCES ; +return set_info_sec (fp->conn, fp->tcon, &fp->filp->f_path, pntsd, buf_len, false, true); }
Greg Kroah-Hartman
maintainerPATCH 141/1067 ksmbd: run set info with opener credentials
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit b383bcad3d2fe634b26efbce53e22bbb5753a520 upstream.
SMB2 SET_INFO handlers call path-based VFS helpers after checking the access mask granted to the SMB handle. Those helpers perform their owner, inode permission and LSM checks using the current ksmbd worker credentials.
Run the complete SET_INFO dispatch with the credentials captured when the handle was opened. This also removes the separate security information credential setup and keeps all SET_INFO classes under one credential scope.
Direct override_creds() is used because it can nest with the request credential overrides already used by rename and link helpers.
--- fs/smb/server/smb2pdu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
fs/smb/server/smb2pdu.c +3 -5
@@ -6132,6 +6132,7 @@ static int smb2_set_info_sec(struct ksmb*/ int smb2_set_info (struct ksmbd_work *work) { +const struct cred *saved_cred;struct smb2_set_info_req *req;struct smb2_set_info_rsp *rsp;struct ksmbd_file *fp =NULL ;
@@ -6173,6 +6174,7 @@ int smb2_set_info(struct ksmbd_work *wor goto err_out; } + saved_cred =override_creds (fp->filp->f_cred);switch (req->InfoType) {case SMB2_O_INFO_FILE :ksmbd_debug (SMB ,"GOT SMB2_O_INFO_FILE\n" );
@@ -6180,19 +6182,15 @@ int smb2_set_info(struct ksmbd_work *worbreak ;case SMB2_O_INFO_SECURITY :ksmbd_debug (SMB ,"GOT SMB2_O_INFO_SECURITY\n" ); -if (ksmbd_override_fsids (work)) { - rc = -ENOMEM ; - goto err_out; - } rc =smb2_set_info_sec (fp,le32_to_cpu (req->AdditionalInformation), (char *)req +le16_to_cpu (req->BufferOffset),le32_to_cpu (req->BufferLength)); -ksmbd_revert_fsids (work);break ;default : rc = -EOPNOTSUPP ; } +revert_creds (saved_cred);if (rc <0 ) goto err_out;
Greg Kroah-Hartman
maintainerPATCH 142/1067 ksmbd: add per-handle permission check to FILE_LINK_INFORMATION
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
commit 13f3942f2bf45856bb751faed2f0c4618f41ca20 upstream.
The FILE_LINK_INFORMATION arm of smb2_set_info_file() calls smb2_create_link() with no per-handle fp->daccess check. On the ReplaceIfExists path smb2_create_link() unlinks an existing file at the target name (ksmbd_vfs_remove_file) and creates a hardlink (ksmbd_vfs_link); neither helper checks daccess. A handle opened with FILE_READ_DATA only (no FILE_DELETE, no FILE_WRITE_DATA) can therefore delete an arbitrary file in the share and plant a hardlink over its name.
The sibling delete/move arms in the same switch already gate:FILE_RENAME_INFORMATION and FILE_DISPOSITION_INFORMATION both require FILE_DELETE_LE; FILE_FULL_EA_INFORMATION requires FILE_WRITE_EA_LE. Gate the link arm the same way as its closest analogue (rename), since it mutates the namespace and, on replace, deletes an existing entry.
This is a sibling of commit cc57232cae23 ("ksmbd: fix FSCTL permission bypass by adding a permission check for FSCTL_SET_SPARSE").
--- fs/smb/server/smb2pdu.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/smb/server/smb2pdu.c +5 -0
@@ -6060,6 +6060,11 @@ static int smb2_set_info_file(struct ksm }case FILE_LINK_INFORMATION : { +if (!(fp->daccess &FILE_DELETE_LE )) { +pr_err ("no right to delete : 0x%x\n" , fp->daccess); +return -EACCES ; + } +if (buf_len <sizeof (struct smb2_file_link_info ))return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 143/1067 smb: client: Fix next buffer leak in receive_encrypted_standard()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 1c6267a1d5cf4c73b656f8181b310cbbb3e4767b upstream.
receive_encrypted_standard() allocates next_buffer before checking whether the number of compound PDUs already reached MAX_COMPOUND. If the limit check fails, the function returns immediately and the newly allocated next_buffer is not assigned to server->smallbuf/server->bigbuf, making it leaked.
Move the MAX_COMPOUND check before allocating next_buffer.
--- fs/smb/client/smb2ops.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/smb/client/smb2ops.c +6 -4
@@ -5189,6 +5189,12 @@ receive_encrypted_standard(struct TCP_Se one_more: shdr = (struct smb2_hdr *)buf; next_cmd =le32_to_cpu (shdr->NextCommand); + +if (*num_mids >=MAX_COMPOUND ) { +cifs_server_dbg (VFS ,"too many PDUs in compound\n" ); +return -1 ; + } +if (next_cmd) {if (WARN_ON_ONCE (next_cmd > pdu_length))return -1 ;
@@ -5212,10 +5218,6 @@ one_more: mid_entry->resp_buf_size = server->pdu_size; } -if (*num_mids >=MAX_COMPOUND ) { -cifs_server_dbg (VFS ,"too many PDUs in compound\n" ); -return -1 ; - } bufs[*num_mids] = buf; mids[(*num_mids)++] = mid_entry;
Greg Kroah-Hartman
maintainerPATCH 144/1067 smb: client: use unaligned reads in parse_posix_ctxt()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit b86467cd2691192ad4809a5a6e922fc24b8e9839 upstream.
The server controls create-context DataOffset, so the POSIX context data pointer may be misaligned on strict-alignment architectures. Use get_unaligned_le32() when reading nlink, reparse_tag, and mode.
--- fs/smb/client/smb2pdu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/smb2pdu.c +3 -3
@@ -2130,9 +2130,9 @@ parse_posix_ctxt(struct create_context *memset (posix,0 ,sizeof (*posix)); - posix->nlink =le32_to_cpu (*(__le32 *)(beg +0 )); - posix->reparse_tag =le32_to_cpu (*(__le32 *)(beg +4 )); - posix->mode =le32_to_cpu (*(__le32 *)(beg +8 )); + posix->nlink =get_unaligned_le32 (beg); + posix->reparse_tag =get_unaligned_le32 (beg +4 ); + posix->mode =get_unaligned_le32 (beg +8 ); sid = beg +12 ; sid_len =posix_info_sid_size (sid, end);
Greg Kroah-Hartman
maintainerPATCH 103/1067 staging: vme_user: bound slave read/write to the kern_buf size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Tautschnig <[email protected]>
commit 9f32f38265014fac7f5dc9490fb01a638ce6e121 upstream.
The SLAVE-path helpers buffer_to_user() and buffer_from_user() copy 'count' bytes into/out of the fixed-size kern_buf (size_buf == PCI_BUF_SIZE == 0x20000, 128 KiB) using *ppos as the offset, without bounding *ppos + count against size_buf.
vme_user_write()/vme_user_read() only clamp count to the VME window size (image_size = vme_get_size(resource)), which VME_SET_SLAVE sets from the user-supplied slave.size -- validated against the VME address space (up to VME_A32_MAX = 4 GiB), not against PCI_BUF_SIZE. When the window exceeds 128 KiB, a write()/read() copies past the kern_buf allocation.
Clamp count against size_buf in both helpers, with an early return when *ppos is already at/after the buffer end. *ppos is >= 0 here (the caller rejects negative offsets), so size_buf - *ppos cannot wrap. This mirrors the existing clamp in the MASTER-path helpers resource_to_user() / resource_from_user(), and matches the read()/write() convention of a short transfer at end-of-buffer.
Found by static analysis (CodeQL taint tracking + CBMC bounded model checking) and confirmed dynamically under KASAN with the vme_fake bridge:
BUG: KASAN: slab-out-of-bounds in _copy_from_user+0x2d/0x80
Write of size 262144 at addr ffff888004100000 by task trigger/68
_copy_from_user+0x2d/0x80
vme_user_write+0x13e/0x240 [vme_user]
vfs_write+0x1b8/0x7a0
ksys_write+0xb8/0x150--- drivers/staging/vme_user/vme_user.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/staging/vme_user/vme_user.c +22 -0
@@ -153,6 +153,17 @@ static ssize_t buffer_to_user(unsigned i {void *image_ptr; +/* +* The slave window (image_size) can exceed the fixed kern_buf +* (size_buf == PCI_BUF_SIZE), so bound the copy to kern_buf. +* *ppos is >= 0 here (checked by the caller), so the +* subtraction below cannot wrap. +*/ +if (*ppos >= image[minor].size_buf) +return 0 ; +if (count > image[minor].size_buf - *ppos) + count = image[minor].size_buf - *ppos; + image_ptr = image[minor].kern_buf + *ppos;if (copy_to_user (buf, image_ptr, (unsigned long )count))return -EFAULT ;
@@ -165,6 +176,17 @@ static ssize_t buffer_from_user(unsigned {void *image_ptr; +/* +* The slave window (image_size) can exceed the fixed kern_buf +* (size_buf == PCI_BUF_SIZE), so bound the copy to kern_buf. +* *ppos is >= 0 here (checked by the caller), so the +* subtraction below cannot wrap. +*/ +if (*ppos >= image[minor].size_buf) +return 0 ; +if (count > image[minor].size_buf - *ppos) + count = image[minor].size_buf - *ppos; + image_ptr = image[minor].kern_buf + *ppos;if (copy_from_user (image_ptr, buf, (unsigned long )count))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 104/1067 smb: client: restrict implied bcc[0] exemption to responses without data area
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shoichiro Miyamoto <[email protected]>
commit 53b7c271f06be4dd5cfc8c6ef552a8355c891a7f upstream.
smb2_check_message() has a long-standing quirk that accepts a response whose calculated length is one byte larger than the bytes actually received ("server can return one byte more due to implied bcc[0]"). This was introduced to accommodate servers that omit the trailing bcc[0] overlap byte when no data area is present.
However, the exemption is applied unconditionally, regardless of whether the command actually carries a data area (has_smb2_data_area[]). When a response with a data area is subject to the +1 exemption, the reported data can extend one byte beyond the bytes actually received, yet smb2_check_message() still accepts it. The subsequent decoder then reads past the end of the receive buffer. This is reachable during NEGOTIATE and SESSION_SETUP, before the session is established.
The resulting out-of-bounds reads are visible under KASAN when mounting against a non-conforming server; both the SPNEGO/negTokenInit and the NTLMSSP challenge decoders are affected:
BUG: KASAN: slab-out-of-bounds in asn1_ber_decoder+0x16a7/0x1b00 Read of size 1 at addr ffff8880084d67c0 by task mount.cifs/81 CPU: 1 UID: 0 PID: 81 Comm: mount.cifs Not tainted 7.1.0-rc6 #1 Call Trace: <TASK> dump_stack_lvl+0x4e/0x70 print_report+0x157/0x4c9 kasan_report+0xce/0x100 asn1_ber_decoder+0x16a7/0x1b00 decode_negTokenInit+0x19/0x30 SMB2_negotiate+0x31d9/0x4c90 cifs_negotiate_protocol+0x1f2/0x3f0 cifs_get_smb_ses+0x93f/0x17e0 cifs_mount_get_session+0x7f/0x3a0 cifs_mount+0xb4/0xcf0 cifs_smb3_do_mount+0x23a/0x1500 smb3_get_tree+0x3b0/0x630 vfs_get_tree+0x82/0x2d0 fc_mount+0x10/0x1b0 path_mount+0x50d/0x1de0 __x64_sys_mount+0x20b/0x270 do_syscall_64+0xee/0x590 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Allocated by task 85: kmem_cache_alloc_noprof+0x106/0x380 mempool_alloc_noprof+0x116/0x1e0 cifs_small_buf_get+0x31/0x80 allocate_buffers+0x10d/0x2b0 cifs_demultiplex_thread+0x1d5/0x1d50 kthread+0x2c6/0x390 ret_from_fork+0x36e/0x5a0 ret_from_fork_asm+0x1a/0x30 The buggy address is located 0 bytes to the right of allocated 448-byte region [ffff8880084d6600, ffff8880084d67c0) which belongs to the cache cifs_small_rq of size 448 BUG: KASAN: slab-out-of-bounds in kmemdup_noprof+0x36/0x50 Read of size 329 at addr ffff88800726c678 by task mount.cifs/89 CPU: 0 UID: 0 PID: 89 Comm: mount.cifs Tainted: G B 7.1.0-rc6 #1 Call Trace: <TASK> dump_stack_lvl+0x4e/0x70 print_report+0x157/0x4c9 kasan_report+0xce/0x100 kasan_check_range+0x10f/0x1e0 __asan_memcpy+0x23/0x60 kmemdup_noprof+0x36/0x50 decode_ntlmssp_challenge+0x457/0x680 SMB2_sess_auth_rawntlmssp_negotiate+0x6f0/0xcb0 SMB2_sess_setup+0x219/0x4f0 cifs_setup_session+0x248/0xaf0 cifs_get_smb_ses+0xf79/0x17e0 cifs_mount_get_session+0x7f/0x3a0 cifs_mount+0xb4/0xcf0 cifs_smb3_do_mount+0x23a/0x1500 smb3_get_tree+0x3b0/0x630 vfs_get_tree+0x82/0x2d0 fc_mount+0x10/0x1b0 path_mount+0x50d/0x1de0 __x64_sys_mount+0x20b/0x270 do_syscall_64+0xee/0x590 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Allocated by task 93: kmem_cache_alloc_noprof+0x106/0x380 mempool_alloc_noprof+0x116/0x1e0 cifs_small_buf_get+0x31/0x80 allocate_buffers+0x10d/0x2b0 cifs_demultiplex_thread+0x1d5/0x1d50 kthread+0x2c6/0x390 ret_from_fork+0x36e/0x5a0 ret_from_fork_asm+0x1a/0x30 The buggy address is located 120 bytes inside of allocated 448-byte region [ffff88800726c600, ffff88800726c7c0) which belongs to the cache cifs_small_rq of size 448
Restrict the +1 exemption to responses that have no data area, so that it still covers the bcc[0] omission it was meant for. When a data area is present, the +1 discrepancy instead means the reported data length overruns the received buffer, so the response must be rejected.
--- fs/smb/client/smb2misc.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
fs/smb/client/smb2misc.c +26 -6
@@ -18,6 +18,8 @@#include "nterr.h" #include "cached_dir.h" +static unsigned int __smb2_calc_size (void *buf,bool *have_data); +static int check_smb2_hdr (struct smb2_hdr *shdr,__u64 mid) {
@@ -143,6 +145,7 @@ smb2_check_message(char *buf, unsigned iint command;__u32 calc_len;/* calculated length */ __u64 mid; +bool have_data;/* If server is a channel, select the primary channel */ pserver =CIFS_SERVER_IS_CHAN (server) ? server->primary_server : server;
@@ -226,7 +229,8 @@ smb2_check_message(char *buf, unsigned i } } - calc_len =smb2_calc_size (buf); + have_data = false; + calc_len =__smb2_calc_size (buf, &have_data);/* For SMB2_IOCTL, OutputOffset and OutputLength are optional, so might * be 0, and not a real miscalculation */
@@ -245,8 +249,13 @@ smb2_check_message(char *buf, unsigned i/* Windows 7 server returns 24 bytes more */ if (calc_len +24 == len && command ==SMB2_OPLOCK_BREAK_HE )return 0 ; -/* server can return one byte more due to implied bcc[0] */ -if (calc_len == len +1 ) +/* +* Server can return one byte more due to implied bcc[0]. +* Allow it only when there is no data area; if data_length > 0 +* the +1 gap indicates an overreported data length rather than +* the bcc[0] omission. +*/ +if (calc_len == len +1 && !have_data)return 0 ;/*
@@ -407,14 +416,17 @@ smb2_get_data_area_len(int *off, int *le/* * Calculate the size of the SMB message based on the fixed header * portion, the number of word parameters and the data portion of the message. +* If have_data is non-NULL, it is set to true when a non-empty data area was +* found (data_length > 0), allowing callers to distinguish the implied bcc[0] +* case (no data area) from an overreported data length. */ -unsigned int -smb2_calc_size (void *buf) +static unsigned int +__smb2_calc_size (void *buf,bool *have_data) {struct smb2_pdu *pdu = buf;struct smb2_hdr *shdr = &pdu->hdr;int offset;/* the offset from the beginning of SMB to data area */ -int data_length;/* the length of the variable length data area */ +int data_length =0 ;/* the length of the variable length data area */ /* Structure Size has already been checked to make sure it is 64 */ int len =le16_to_cpu (shdr->StructureSize);
@@ -447,9 +459,17 @@ smb2_calc_size(void *buf) } calc_size_exit:cifs_dbg (FYI ,"SMB2 len %d\n" , len); +if (have_data) + *have_data = (data_length >0 );return len; } +unsigned int +smb2_calc_size (void *buf) +{ +return __smb2_calc_size (buf,NULL ); +} +/* Note: caller must free return buffer */ __le16 *cifs_convert_path_to_utf16 (const char *from,struct cifs_sb_info *cifs_sb)
Greg Kroah-Hartman
maintainerPATCH 105/1067 staging: vme_user: fix location monitor leak in fake bridge
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao-Qun Huang <[email protected]>
commit e8422d89e8af41d87f0e9db564be8e2634f4c602 upstream.
fake_init() allocates a location monitor resource and links it into fake_bridge->lm_resources. The init error path frees this list, but fake_exit() only frees the slave and master resource lists. Loading and unloading the module therefore triggers a kmemleak warning:
unreferenced object 0xffff8b8b82aebe40 (size 64):
comm "init", pid 1, jiffies 4294894572
backtrace (crc c1e013ef):
kmemleak_alloc+0x4e/0x90
__kmalloc_cache_noprof+0x338/0x430
0xffffffffc0602246
do_one_initcall+0x4f/0x320
do_init_module+0x68/0x270
load_module+0x2a3b/0x2d90Free the lm_resources list in fake_exit() as well, before fake_bridge is freed.
--- drivers/staging/vme_user/vme_fake.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/staging/vme_user/vme_fake.c +8 -0
@@ -1253,6 +1253,7 @@ static void __exit fake_exit(void) {struct list_head *pos =NULL ;struct list_head *tmplist; +struct vme_lm_resource *lm;struct vme_master_resource *master_image;struct vme_slave_resource *slave_image;int i;
@@ -1283,6 +1284,13 @@ static void __exit fake_exit(void)fake_crcsr_exit (fake_bridge);/* resources are stored in link list */ +list_for_each_safe (pos, tmplist, &fake_bridge->lm_resources) { + lm = list_entry(pos, struct vme_lm_resource, list); +list_del (pos); +kfree (lm); + } + +/* resources are stored in link list */ list_for_each_safe (pos, tmplist, &fake_bridge->slave_resources) { slave_image = list_entry(pos, struct vme_slave_resource, list);list_del (pos);
Greg Kroah-Hartman
maintainerPATCH 106/1067 staging: vme_user: fix location monitor leak in tsi148 bridge
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao-Qun Huang <[email protected]>
commit 151edde741f8bc7f2931c5f44ab376d32b0c8beb upstream.
tsi148_probe() allocates a location monitor resource and links it into tsi148_bridge->lm_resources. The probe error path frees this list, but tsi148_remove() only frees the dma, slave and master resource lists, so the location monitor resource is leaked on device unbind or module unload.
Free the lm_resources list in tsi148_remove() as well, before tsi148_bridge is freed.
--- drivers/staging/vme_user/vme_tsi148.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/staging/vme_user/vme_tsi148.c +8 -0
@@ -2548,6 +2548,7 @@ static void tsi148_remove(struct pci_dev {struct list_head *pos =NULL ;struct list_head *tmplist; +struct vme_lm_resource *lm;struct vme_master_resource *master_image;struct vme_slave_resource *slave_image;struct vme_dma_resource *dma_ctrlr;
@@ -2606,6 +2607,13 @@ static void tsi148_remove(struct pci_devtsi148_crcsr_exit (tsi148_bridge, pdev);/* resources are stored in link list */ +list_for_each_safe (pos, tmplist, &tsi148_bridge->lm_resources) { + lm = list_entry(pos, struct vme_lm_resource, list); +list_del (pos); +kfree (lm); + } + +/* resources are stored in link list */ list_for_each_safe (pos, tmplist, &tsi148_bridge->dma_resources) { dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);list_del (pos);
Greg Kroah-Hartman
maintainerPATCH 107/1067 media: staging: ipu3-imgu: Add range check for imgu_css_cfg_acc_stripe
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
commit c32fe4c4918c9aa49f61359e3b42619c4d8686de upstream.
If the driver's stripe information is invalid it can result in an integer underflow. Add a range check to avoid this kind of error.
This patch fixes the following smatch error:drivers/staging/media/ipu3/ipu3-css-params.c:1792 imgu_css_cfg_acc_stripe() warn: 'acc->stripe.bds_out_stripes[0]->width - 2 * f' 4294967168 can't fit into 65535 'acc->stripe.bds_out_stripes[1]->offset'
--- drivers/staging/media/ipu3/ipu3-css-params.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/media/ipu3/ipu3-css-params.c +6 -2
@@ -1770,6 +1770,8 @@ static int imgu_css_cfg_acc_stripe(struc acc->stripe.bds_out_stripes[0 ].width =ALIGN (css_pipe->rect[IPU3_CSS_RECT_BDS ].width, f); }else { +u32 offset; +/* Image processing is divided into two stripes */ acc->stripe.bds_out_stripes[0 ].width = acc->stripe.bds_out_stripes[1].width =
@@ -1788,8 +1790,10 @@ static int imgu_css_cfg_acc_stripe(struc acc->stripe.bds_out_stripes[1 ].width += f; }/* Overlap between stripes is IPU3_UAPI_ISP_VEC_ELEMS * 4 */ - acc->stripe.bds_out_stripes[1 ].offset = - acc->stripe.bds_out_stripes[0 ].width -2 * f; + offset = acc->stripe.bds_out_stripes[0 ].width -2 * f; +if (offset >65535 ) +return -EINVAL ; + acc->stripe.bds_out_stripes[1 ].offset = offset; } acc->stripe.effective_stripes[0].height =
Greg Kroah-Hartman
maintainerPATCH 98/1067 hwrng: virtio: clamp device-reported used.len at copy_data()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit e3046eeada299f917a8ad883af4434bfb86556b1 upstream.
random_recv_done() stores the device-reported used.len directly into vi->data_avail. copy_data() then indexes vi->data[] using vi->data_idx (advanced by previous copy_data() calls) and issues a memcpy() without re-validating either value against the posted buffer size sizeof(vi->data) (SMP_CACHE_BYTES bytes, typically 32 or 64).
A malicious or buggy virtio-rng backend can set used.len beyond sizeof(vi->data), steering the memcpy() past the end of the inline array into adjacent kmalloc-1k slab bytes. hwrng_fillfn() mixes those bytes into the guest RNG, and guest root can also observe them directly via /dev/hwrng.
Concrete impact is inside the guest:
- Memory-safety / hardening: any virtio-rng backend that over-reports used.len causes the driver to read past vi->data into unrelated slab contents. hwrng_fillfn() is a kernel thread that runs as soon as the device is probed; no guest userspace interaction is required to first-trigger the OOB.
- Cross-boundary leak (confidential-compute threat model): a malicious hypervisor cooperating with a malicious or compromised guest root userspace can use /dev/hwrng as a leak channel for guest-kernel heap data. The host sets a large used.len, guest root reads /dev/hwrng, and the returned bytes contain guest kernel slab contents that were adjacent to vi->data. In practice, confidential-compute guests (SEV-SNP, TDX) usually disable virtio-rng entirely, so this path is narrow, but the fix is still worth carrying because the underlying memory-safety bug contaminates the guest RNG on any host.
KASAN confirms the OOB on a 7.1-rc4 guest whose virtio-rng backend has been patched to report used.len = 0x10000:
BUG: KASAN: slab-out-of-bounds in virtio_read+0x394/0x5d0 Read of size 64 at addr ffff88800ae0ba20 by task hwrng/52 Call Trace: __asan_memcpy+0x23/0x60 virtio_read+0x394/0x5d0 hwrng_fillfn+0xb2/0x470 kthread+0x2cc/0x3a0 Allocated by task 1: probe_common+0xa5/0x660 virtio_dev_probe+0x549/0xbc0 The buggy address belongs to the object at ffff88800ae0b800 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 0 bytes to the right of allocated 544-byte region [ffff88800ae0b800, ffff88800ae0ba20)
Same class of bug as commit c04db81cd028 ("net/9p: Fix buffer overflow in USB transport layer"), which hardened usb9pfs_rx_complete() against unchecked device-reported length in the USB 9p transport.
With the clamp at point of use and array_index_nospec() in place, the same harness boots cleanly: copy_data() returns zero for the bogus report, the device-supplied bytes after data_idx are discarded, and the driver issues a fresh request.
Message-ID: <[email protected]>
--- drivers/char/hw_random/virtio-rng.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/char/hw_random/virtio-rng.c +21 -2
@@ -7,6 +7,7 @@#include <asm/barrier.h> #include <linux/err.h> #include <linux/hw_random.h> +#include <linux/nospec.h> #include <linux/scatterlist.h> #include <linux/spinlock.h> #include <linux/virtio.h>
@@ -66,8 +67,26 @@ static void request_entropy(struct virtrstatic unsigned int copy_data (struct virtrng_info *vi,void *buf,unsigned int size) { - size = min_t(unsigned int, size, vi->data_avail); -memcpy (buf, vi->data + vi->data_idx, size); +unsigned int idx, avail; + +/* +* vi->data_avail was set from the device-reported used.len and +* vi->data_idx was advanced by previous copy_data() calls. A +* malicious or buggy virtio-rng backend can drive either past +* sizeof(vi->data). Clamp at point of use and harden the index +* with array_index_nospec() so the memcpy() below cannot be +* steered into adjacent slab memory, including under +* speculation. +*/ + avail = min_t(unsigned int, vi->data_avail, sizeof(vi->data)); +if (vi->data_idx >= avail) { + vi->data_avail =0 ; +request_entropy (vi); +return 0 ; + } + size = min_t(unsigned int, size, avail - vi->data_idx); + idx =array_index_nospec (vi->data_idx,sizeof (vi->data)); +memcpy (buf, vi->data + idx, size); vi->data_idx += size; vi->data_avail -= size;if (vi->data_avail ==0 )
Greg Kroah-Hartman
maintainerPATCH 146/1067 smb: client: mask server-provided mode to 07777 in modefromsid
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Norbert Manthey <[email protected]>
commit e3d9c7160d483fc8f9e225aafad8ecbbc43f3151 upstream.
When modefromsid is active, parse_dacl() applies the server-provided sub_auth[2] value from the NFS mode SID to cf_mode without masking to 07777. Apply the correct masking, same as in the read path.
--- fs/smb/client/cifsacl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifsacl.c +1 -1
@@ -887,7 +887,7 @@ static void parse_dacl(struct cifs_acl **/ fattr->cf_mode &= ~07777 ; fattr->cf_mode |= -le32_to_cpu (ppace[i]->sid.sub_auth[2 ]); +le32_to_cpu (ppace[i]->sid.sub_auth[2 ]) &07777 ;break ; }else {if (compare_sids (&(ppace[i]->sid), pownersid) ==0 ) {
Greg Kroah-Hartman
maintainerPATCH 155/1067 HID: wacom: stop hardware after post-start probe failures
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit ec2612b8ad9e642596db011dd8b6568ef1edeaa1 upstream.
wacom_parse_and_register() starts HID hardware before registering inputs and initializing pad LEDs/remotes. Those later steps can fail, but their error paths currently release Wacom resources without stopping the HID hardware.
Route post-hid_hw_start() failures through hid_hw_stop() before releasing driver resources.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/hid/wacom_sys.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/hid/wacom_sys.c +6 -6
@@ -2425,16 +2425,16 @@ static int wacom_parse_and_register(stru error =wacom_register_inputs (wacom);if (error) - goto fail; + goto fail_hw_stop;if (wacom->wacom_wac.features.device_type &WACOM_DEVICETYPE_PAD ) { error =wacom_initialize_leds (wacom);if (error) - goto fail; + goto fail_hw_stop; error =wacom_initialize_remotes (wacom);if (error) - goto fail; + goto fail_hw_stop; }if (!wireless) {
@@ -2448,14 +2448,14 @@ static int wacom_parse_and_register(strucancel_delayed_work_sync (&wacom->init_work);_wacom_query_tablet_data (wacom); error = -ENODEV ; - goto fail_quirks; + goto fail_hw_stop; }if (features->device_type &WACOM_DEVICETYPE_WL_MONITOR ) { error =hid_hw_open (hdev);if (error) {hid_err (hdev,"hw open failed\n" ); - goto fail_quirks; + goto fail_hw_stop; } }
@@ -2464,7 +2464,7 @@ static int wacom_parse_and_register(strureturn 0 ; -fail_quirks: +fail_hw_stop:hid_hw_stop (hdev); fail:wacom_release_resources (wacom);
Greg Kroah-Hartman
maintainerPATCH 156/1067 HID: letsketch: fix UAF on inrange_timer at driver unbind
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manish Khadka <[email protected]>
commit 46c8beeccd8ab2c863827254a85ea877654a3534 upstream.
letsketch_driver does not provide a .remove callback, but letsketch_probe() arms a per-device timer:
timer_setup(&data->inrange_timer, letsketch_inrange_timeout, 0);
The timer is re-armed from letsketch_raw_event() with a 100 ms timeout on every pen-in-range report, and its callback dereferences data->input_tablet to deliver a synthetic BTN_TOOL_PEN release.
letsketch_data is allocated with devm_kzalloc(), and its input_dev fields are devm-allocated via letsketch_setup_input_tablet(). On device unbind (USB unplug or rmmod), the HID core runs its default teardown and devm cleanup frees both letsketch_data and the input devices. Because no .remove callback exists, nothing drains the timer first: if raw_event armed it within ~100 ms of the unbind, the pending timer fires on freed memory. This is a UAF read of data and of data->input_tablet, followed by input_report_key() / input_sync() into the freed input_dev.
The same problem can occur on the probe error path: if hid_hw_start() enabled I/O on an always-poll-quirk device and then failed, raw_event may have armed the timer before devm releases data.
Fix by adding a .remove callback that calls hid_hw_stop() first. hid_hw_stop() synchronously kills the URBs that deliver raw_event(), so once it returns no path can re-arm the timer. timer_shutdown_sync() then drains any in-flight callback and permanently disables further mod_timer() calls. Apply the same timer_shutdown_sync() in the probe error path so the timer is guaranteed not to outlive data.
--- drivers/hid/hid-letsketch.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/hid/hid-letsketch.c +33 -3
@@ -295,13 +295,42 @@ static int letsketch_probe(struct hid_de ret =letsketch_setup_input_tablet (data);if (ret) -return ret; + goto err_shutdown_timer; ret =letsketch_setup_input_tablet_pad (data);if (ret) -return ret; + goto err_shutdown_timer; -return hid_hw_start (hdev,HID_CONNECT_HIDRAW ); + ret =hid_hw_start (hdev,HID_CONNECT_HIDRAW ); +if (ret) + goto err_shutdown_timer; + +return 0 ; + +err_shutdown_timer: +/* +* Drain any pending callback and permanently disable the timer +* before devm releases data: if hid_hw_start() enabled I/O on an +* always-poll-quirk device and then failed, raw_event may have +* armed the timer already. +*/ +timer_shutdown_sync (&data->inrange_timer); +return ret; +} + +static void letsketch_remove (struct hid_device *hdev) +{ +struct letsketch_data *data =hid_get_drvdata (hdev); + +/* +* hid_hw_stop() synchronously kills the URBs that deliver +* raw_event(), so once it returns no path can re-arm +* inrange_timer. timer_shutdown_sync() then drains any +* in-flight callback and permanently disables further +* mod_timer() calls before devm releases data. +*/ +hid_hw_stop (hdev); +timer_shutdown_sync (&data->inrange_timer); }static const struct hid_device_id letsketch_devices[] = {
@@ -314,6 +343,7 @@ static struct hid_driver letsketch_drive .name = "letsketch", .id_table = letsketch_devices, .probe = letsketch_probe, + .remove = letsketch_remove, .raw_event = letsketch_raw_event, };module_hid_driver (letsketch_driver);
Greg Kroah-Hartman
maintainerPATCH 157/1067 HID: lg-g15: cancel pending work on remove to fix a use-after-free
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 7705b4140d188ce22656f6e541ae7ef834c7e11a upstream.
lg_g15_data is allocated with devm and holds a work item. The report handlers schedule that work straight from device input. lg_g15_event() and lg_g15_v2_event() do it on the backlight cycle key, and lg_g510_leds_event() does it too. The worker dereferences the lg_g15_data back through container_of.
The driver had no remove callback and never cancelled the work. So if a report scheduled the work and the keyboard was then unplugged, devres freed lg_g15_data while the work was still pending or running, and the worker touched freed memory. This is a use-after-free. It is reachable as a race on device unplug.
Add a remove callback that cancels the work before devres frees the state. g15->work is only initialized for the models that schedule it (G15, G15 v2, G510). The G13 and Z-10 leave it zeroed, so guard the cancel on g15->work.func to avoid cancelling a work that was never set up. The g15 NULL test mirrors the one already in lg_g15_raw_event().
--- drivers/hid/hid-lg-g15.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/hid/hid-lg-g15.c +16 -0
@@ -944,11 +944,27 @@ static const struct hid_device_id lg_g15 };MODULE_DEVICE_TABLE (hid, lg_g15_devices); +static void lg_g15_remove (struct hid_device *hdev) +{ +struct lg_g15_data *g15 =hid_get_drvdata (hdev); + +/* +* g15->work is only initialized for the models that schedule it +* (G15, G15 v2, G510). The G13 and Z-10 leave it zeroed, so only +* cancel it when it was set up. +*/ +if (g15 && g15->work.func) +cancel_work_sync (&g15->work); + +hid_hw_stop (hdev); +} +static struct hid_driver lg_g15_driver = { .name ="lg-g15" , .id_table = lg_g15_devices, .raw_event = lg_g15_raw_event, .probe = lg_g15_probe, + .remove = lg_g15_remove, };module_hid_driver (lg_g15_driver);
Greg Kroah-Hartman
maintainerPATCH 158/1067 HID: sensor-hub: Add sensor_hub_input_attr_read_values() for multi-byte reads
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
commit f784fcea450617055d2d12eec5b2f6e0e38bf878 upstream.
sensor_hub_input_attr_get_raw_value() is limited to returning a single 32-bit value, which is insufficient for sensors that report data larger than 32 bits, such as a quaternion with four s16 elements.
Add sensor_hub_input_attr_read_values() that accepts a caller-provided buffer and accumulates incoming data until the buffer is full. The two paths are distinguished in sensor_hub_raw_event() by pending.max_raw_size being non-zero, preserving backward compatibility.
--- drivers/hid/hid-sensor-hub.c | 77 +++++++++++++++++++++++++++++++++++++---- include/linux/hid-sensor-hub.h | 25 +++++++++++++ 2 files changed, 96 insertions(+), 6 deletions(-)
drivers/hid/hid-sensor-hub.c +71 -6
@@ -286,6 +286,54 @@ done_proc: }EXPORT_SYMBOL_GPL (sensor_hub_get_feature); +int sensor_hub_input_attr_read_values (struct hid_sensor_hub_device *hsdev, +u32 usage_id,u32 attr_usage_id, +u32 report_id, +enum sensor_hub_read_flags flag, +u32 buffer_size,u8 *buffer) +{ +struct sensor_hub_data *data =hid_get_drvdata (hsdev->hdev); +struct hid_report *report; +unsigned long flags; +long cycles; +int ret; + + report =sensor_hub_report (report_id, hsdev->hdev,HID_INPUT_REPORT ); +if (!report) +return -EINVAL ; + +mutex_lock (hsdev->mutex_ptr); +if (flag ==SENSOR_HUB_SYNC ) { +memset (&hsdev->pending,0 ,sizeof (hsdev->pending)); +init_completion (&hsdev->pending.ready); + hsdev->pending.usage_id = usage_id; + hsdev->pending.attr_usage_id = attr_usage_id; + hsdev->pending.max_raw_size = buffer_size; + hsdev->pending.raw_data = buffer; + +spin_lock_irqsave (&data->lock, flags); + hsdev->pending.status = true; +spin_unlock_irqrestore (&data->lock, flags); + } +mutex_lock (&data->mutex); +hid_hw_request (hsdev->hdev, report,HID_REQ_GET_REPORT ); +mutex_unlock (&data->mutex); + ret =0 ; +if (flag ==SENSOR_HUB_SYNC ) { + cycles =wait_for_completion_interruptible_timeout (&hsdev->pending.ready, +HZ *5 ); +if (cycles ==0 ) + ret = -ETIMEDOUT ; +else if (cycles <0 ) + ret = cycles; + + hsdev->pending.status = false; + } +mutex_unlock (hsdev->mutex_ptr); + +return ret; +} +EXPORT_SYMBOL_GPL (sensor_hub_input_attr_read_values); int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, u32 usage_id,
@@ -479,6 +527,8 @@ static int sensor_hub_raw_event(struct hstruct hid_collection *collection =NULL ;void *priv =NULL ;struct hid_sensor_hub_device *hsdev =NULL ; +u32 copy_size; +u32 avail;hid_dbg (hdev,"sensor_hub_raw_event report id:0x%x size:%d type:%d\n" , report->id, size, report->type);
@@ -518,12 +568,27 @@ static int sensor_hub_raw_event(struct h hsdev->pending.attr_usage_id == report->field[i]->logical)) {hid_dbg (hdev,"data was pending ...\n" ); - hsdev->pending.raw_data =kmemdup (ptr, sz,GFP_ATOMIC ); -if (hsdev->pending.raw_data) - hsdev->pending.raw_size = sz; -else - hsdev->pending.raw_size =0 ; -complete (&hsdev->pending.ready); +if (hsdev->pending.max_raw_size) { +if (hsdev->pending.index < hsdev->pending.max_raw_size) { + avail = hsdev->pending.max_raw_size - hsdev->pending.index; + copy_size =clamp (sz,0U , avail); + +memcpy (hsdev->pending.raw_data + hsdev->pending.index, + ptr, copy_size); + hsdev->pending.index += copy_size; +if (hsdev->pending.index >= hsdev->pending.max_raw_size) { + hsdev->pending.raw_size = hsdev->pending.index; +complete (&hsdev->pending.ready); + } + } + }else { + hsdev->pending.raw_data =kmemdup (ptr, sz,GFP_ATOMIC ); +if (hsdev->pending.raw_data) + hsdev->pending.raw_size = sz; +else + hsdev->pending.raw_size =0 ; +complete (&hsdev->pending.ready); + } }if (callback->capture_sample) {if (report->field[i]->logical)
include/linux/hid-sensor-hub.h +25 -0
@@ -43,6 +43,8 @@ struct hid_sensor_hub_attribute_info {* @attr_usage_id: Usage Id of a field, E.g. X-AXIS for a gyro. * @raw_size: Response size for a read request. * @raw_data: Place holder for received response. +* @index: Current write index into raw_data for multi-byte reads. +* @max_raw_size: Total buffer size for multi-byte reads; 0 for single-value reads. */ struct sensor_hub_pending {bool status;
@@ -51,6 +53,8 @@ struct sensor_hub_pending {u32 attr_usage_id;int raw_size;u8 *raw_data; +u32 index; +u32 max_raw_size; };/**
@@ -183,6 +187,27 @@ int sensor_hub_input_attr_get_raw_value( );/** +* sensor_hub_input_attr_read_values() - Synchronous multi-byte read request +* @hsdev: Hub device instance. +* @usage_id: Attribute usage id of parent physical device as per spec +* @attr_usage_id: Attribute usage id as per spec +* @report_id: Report id to look for +* @flag: Synchronous or asynchronous read +* @buffer_size: Size of the buffer in bytes +* @buffer: Buffer to store the read data +* +* Issues a synchronous or asynchronous read request for an input attribute, +* accumulating data into the provided buffer until it is full. +* Return: 0 on success, -ETIMEDOUT if the device did not respond, or a +* negative error code. +*/ +int sensor_hub_input_attr_read_values (struct hid_sensor_hub_device *hsdev, +u32 usage_id,u32 attr_usage_id, +u32 report_id, +enum sensor_hub_read_flags flag, +u32 buffer_size,u8 *buffer); + +/** * sensor_hub_set_feature() - Feature set request * @hsdev: Hub device instance. * @report_id: Report id to look for
Greg Kroah-Hartman
maintainerPATCH 159/1067 hfs/hfsplus: zero-initialize buffer in hfs_bnode_read
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit d67aadee19ffdf3cc8520c5a4f4d5b2916d30baf upstream.
hfs_bnode_read() can return early without writing to the output buffer when is_bnode_offset_valid() fails or when check_and_correct_requested_ length() corrects the length to zero. Callers such as hfs_bnode_read_ u16() and hfs_bnode_read_u8() pass stack-allocated buffers and use the result unconditionally, leading to KMSAN uninit-value reports.
Rather than initializing at each individual call site, zero the buffer at the start of hfs_bnode_read() before any validation checks. This ensures all callers in both hfs and hfsplus get a deterministic zero value regardless of which early-return path is taken.
--- fs/hfs/bnode.c | 2 ++ fs/hfsplus/bnode.c | 2 ++ 2 files changed, 4 insertions(+)
fs/hfs/bnode.c +2 -0
@@ -64,6 +64,8 @@ void hfs_bnode_read(struct hfs_bnode *noint bytes_read;int bytes_to_read; +memset (buf,0 , len); +if (!is_bnode_offset_valid (node, off))return ;
fs/hfsplus/bnode.c +2 -0
@@ -25,6 +25,8 @@ void hfs_bnode_read(struct hfs_bnode *nostruct page **pagep;int l; +memset (buf,0 , len); +if (!is_bnode_offset_valid (node, off))return ;
Greg Kroah-Hartman
maintainerPATCH 160/1067 nilfs2: reject CLEAN_SEGMENTS ioctl with out-of-range segment numbers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Deepanshu Kartikey <[email protected]>
commit 0e7a690fe435f8d5ea3feb7c1d8d73ba7e8b8aa9 upstream.
Syzbot reported a hung task in nilfs_transaction_begin() where multiple tasks performing chmod() on a nilfs2 mount blocked for over 143 seconds waiting to acquire ns_segctor_sem for read:
INFO: task syz.0.17:5918 blocked for more than 143 seconds. Call Trace: schedule+0x164/0x360 rwsem_down_read_slowpath+0x6d9/0x940 down_read+0x99/0x2e0 nilfs_transaction_begin+0x364/0x710 fs/nilfs2/segment.c:221 nilfs_setattr+0x124/0x2c0 fs/nilfs2/inode.c:921 notify_change+0xc1a/0xf40 chmod_common+0x273/0x4a0 do_fchmodat+0x12d/0x230
The writer holding ns_segctor_sem was a concurrent NILFS_IOCTL_CLEAN_SEGMENTS caller, stuck inside printk while emitting per-element warnings from nilfs_sufile_updatev():
__nilfs_msg+0x373/0x450 fs/nilfs2/super.c:78 nilfs_sufile_updatev+0x21c/0x6d0 fs/nilfs2/sufile.c:186 nilfs_sufile_freev fs/nilfs2/sufile.h:93 [inline] nilfs_free_segments fs/nilfs2/segment.c:1140 [inline] nilfs_segctor_collect_blocks fs/nilfs2/segment.c:1261 [inline] nilfs_segctor_do_construct+0x1f55/0x76c0 nilfs_clean_segments+0x3bd/0xa50 nilfs_ioctl_clean_segments fs/nilfs2/ioctl.c:922 [inline] nilfs_ioctl+0x261f/0x2780
The root cause is that user-supplied segment numbers are not validated before nilfs_clean_segments() begins doing work; the range check on each segnum is performed deep inside the call chain by nilfs_sufile_updatev(), which emits a nilfs_warn() per invalid entry while still holding the segctor lock and the sufile mi_sem. Under load (repeated invocations across multiple mounts saturating the global printk path), the cumulative printk latency keeps ns_segctor_sem held long enough to trip the hung_task watchdog, blocking concurrent operations such as chmod() that need ns_segctor_sem for read.
Fix by validating the contents of kbufs[4] in nilfs_clean_segments() immediately after acquiring ns_segctor_sem via nilfs_transaction_lock(). Holding ns_segctor_sem serializes the check against nilfs_ioctl_resize(), which can modify ns_nsegments, so the validation uses a consistent value. Out-of-range segment numbers are rejected with -EINVAL before any segment-cleaning work begins, so the bad entries never reach the per-element diagnostic path inside nilfs_sufile_updatev().
--- fs/nilfs2/segment.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
fs/nilfs2/segment.c +22 -0
@@ -2503,12 +2503,33 @@ int nilfs_clean_segments(struct super_blstruct nilfs_sc_info *sci = nilfs->ns_writer;struct nilfs_transaction_info ti;int err; +size_t i, nfreesegs = argv[4 ].v_nmembs; +__u64 *segnumv = kbufs[4 ];if (unlikely (!sci))return -EROFS ;nilfs_transaction_lock (sb, &ti,1 ); +/* +* Validate segment numbers under ns_segctor_sem (held for write +* by nilfs_transaction_lock above) so the check is serialized +* against nilfs_ioctl_resize(), which can modify ns_nsegments. +* Rejecting bad input here, before any segment-cleaning work +* begins, avoids the per-element diagnostic path inside +* nilfs_sufile_updatev() that would otherwise run under this +* same lock and stall concurrent readers. +*/ +for (i =0 ; i < nfreesegs; i++) { +if (segnumv[i] >= nilfs->ns_nsegments) { +nilfs_err (sb, +"Segment number %llu to be freed is out of range" , + (unsigned long long )segnumv[i]); + err = -EINVAL ; + goto bail_unlock; + } + } + err =nilfs_mdt_save_to_shadow_map (nilfs->ns_dat);if (unlikely (err)) goto out_unlock;
@@ -2549,6 +2570,7 @@ int nilfs_clean_segments(struct super_bl sci->sc_freesegs =NULL ; sci->sc_nfreesegs =0 ;nilfs_mdt_clear_shadow_map (nilfs->ns_dat); + bail_unlock:nilfs_transaction_unlock (sb);return err; }
Greg Kroah-Hartman
maintainerPATCH 161/1067 xfs: use null daddr for unset first bad log block
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yousef Alhouseen <[email protected]>
commit cc9af5e461ea5f6e37738f3f1e41c45a9b7f45d6 upstream.
xlog_do_recovery_pass() may return before setting first_bad. The caller must distinguish that case from an error at a valid log block, including block zero after the log wraps.
Initialize first_bad to XFS_BUF_DADDR_NULL and test it explicitly before treating the error as a torn write.
--- fs/xfs/xfs_log_recover.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/xfs/xfs_log_recover.c +3 -3
@@ -1028,7 +1028,7 @@ xlog_verify_head( {struct xlog_rec_header *tmp_rhead;char *tmp_buffer; -xfs_daddr_t first_bad; +xfs_daddr_t first_bad =XFS_BUF_DADDR_NULL ;xfs_daddr_t tmp_rhead_blk;int found;int error;
@@ -1057,7 +1057,8 @@ xlog_verify_head(*/ error =xlog_do_recovery_pass (log, *head_blk, tmp_rhead_blk,XLOG_RECOVER_CRCPASS , &first_bad); -if ((error == -EFSBADCRC || error == -EFSCORRUPTED ) && first_bad) { +if ((error == -EFSBADCRC || error == -EFSCORRUPTED ) && + first_bad !=XFS_BUF_DADDR_NULL ) {/* * We've hit a potential torn write. Reset the error and warn * about it.
@@ -3538,4 +3539,3 @@ xlog_recover_cancel(if (xlog_recovery_needed (log))xlog_recover_cancel_intents (log); } -
Greg Kroah-Hartman
maintainerPATCH 162/1067 xfs: fix unreachable BIGTIME check in dquot flush validation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Nepomnyashih <[email protected]>
commit 03866d130ed33ab68cc7faaf4bf2c4abef96d42e upstream.
The dqp->q_id == 0 check inside the XFS_DQTYPE_BIGTIME block is unreachable because root dquots return successfully earlier. Reject root dquots with XFS_DQTYPE_BIGTIME before that early return, preserving the intended validation and removing the unreachable condition.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- fs/xfs/xfs_dquot.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/xfs/xfs_dquot.c +8 -8
@@ -1174,6 +1174,14 @@ xfs_qm_dqflush_check( type != XFS_DQTYPE_PROJ)return __this_address; +/* bigtime flag should never be set on root dquots */ +if (dqp->q_type &XFS_DQTYPE_BIGTIME ) { +if (!xfs_has_bigtime (dqp->q_mount)) +return __this_address; +if (dqp->q_id ==0 ) +return __this_address; + } +if (dqp->q_id ==0 )return NULL ;
@@ -1189,14 +1197,6 @@ xfs_qm_dqflush_check( !dqp->q_rtb.timer)return __this_address; -/* bigtime flag should never be set on root dquots */ -if (dqp->q_type &XFS_DQTYPE_BIGTIME ) { -if (!xfs_has_bigtime (dqp->q_mount)) -return __this_address; -if (dqp->q_id ==0 ) -return __this_address; - } -return NULL ; }
Greg Kroah-Hartman
maintainerPATCH 163/1067 bpf: Reject fragmented frames in devmap
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Zhang <[email protected]>
commit aa496720618f1a6054f1c870bf10b4f6c99bf656 upstream.
Devmap broadcast redirects clone the packet for all but the last destination.
For native XDP, that clone path copies only the linear xdp_frame data, while fragmented frames keep skb_shared_info in tailroom outside the linear area. Cloning such a frame leaves XDP_FLAGS_HAS_FRAGS set but without valid frag metadata, and the later free path can interpret uninitialized tail data as skb_shared_info, leading to an out-of-bounds access during frame return.
Reject fragmented native XDP frames in dev_map_enqueue_clone().
Add the same restriction to the generic XDP clone path in dev_map_redirect_clone(). Generic XDP represents fragmented packets as nonlinear skbs, and rejecting them here keeps clone-based broadcast support aligned between native and generic XDP.
--- kernel/bpf/devmap.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/bpf/devmap.c +7 -0
@@ -552,6 +552,10 @@ static int dev_map_enqueue_clone(struct {struct xdp_frame *nxdpf; +/* Frags live outside the linear frame and cannot be cloned safely. */ +if (unlikely (xdp_frame_has_frags (xdpf))) +return -EOPNOTSUPP ; + nxdpf =xdpf_clone (xdpf);if (!nxdpf)return -ENOMEM ;
@@ -697,6 +701,9 @@ static int dev_map_redirect_clone(structstruct sk_buff *nskb;int err; +if (unlikely (skb_is_nonlinear (skb))) +return -EOPNOTSUPP ; + nskb =skb_clone (skb,GFP_ATOMIC );if (!nskb)return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 164/1067 bpf: Restore sysctl new-value from 1 to 0
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawei Feng <[email protected]>
commit 2566c3b24219c5b30e35205cba029ff34ff7c78b upstream.
Commit 4e63acdff864 ("bpf: Introduce bpf_sysctl_{get,set}_new_value helpers") changed the success return value to 0, but failed to update the corresponding check in __cgroup_bpf_run_filter_sysctl(). Since bpf_prog_run_array_cg() now returns 0 on success, the legacy ret == 1 condition is never satisfied. As a result, the modified value is ignored, and bpf_sysctl_set_new_value() fails to replace the write buffer.
Fix this by checking for a return value of 0 instead, so cgroup/sysctl programs can correctly replace the pending sysctl buffer.
This bug was discovered during a manual code review. Tested via a cgroup/sysctl BPF reproducer overriding writes to a target sysctl. Pre-fix, bpf_sysctl_set_new_value("foo") was silently ignored: the write returned 8192 and the value remained "600". Post-fix, the BPF replacement buffer properly propagates: the write returns 3 and the value updates to "foo".
--- kernel/bpf/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/cgroup.c +1 -1
@@ -1744,7 +1744,7 @@ int __cgroup_bpf_run_filter_sysctl(struckfree (ctx.cur_val); -if (ret ==1 && ctx.new_updated) { +if (!ret && ctx.new_updated) {kvfree (*buf); *buf = ctx.new_val; *pcount = ctx.new_len;
Greg Kroah-Hartman
maintainerPATCH 147/1067 firmware_loader: fix device reference leak in firmware_upload_register()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 896df22ee57648b0c505bd76ddbc6b2341834696 upstream.
firmware_upload_register()
-> fw_create_instance()
-> device_initialize()
After fw_create_instance() succeeds, the lifetime of the embedded struct device is expected to be managed through the device core reference counting, since fw_create_instance() has already called device_initialize().
In firmware_upload_register(), if alloc_lookup_fw_priv() fails after fw_create_instance() succeeds, the code reaches free_fw_sysfs and frees fw_sysfs directly instead of releasing the device reference with put_device(). This may leave the reference count of the embedded struct device unbalanced, resulting in a refcount leak.
The issue was identified by a static analysis tool I developed and confirmed by manual review. Fix this by using put_device(fw_dev) in the failure path and letting fw_dev_release() handle the final cleanup, instead of freeing the instance directly from the error path.
--- drivers/base/firmware_loader/sysfs_upload.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/base/firmware_loader/sysfs_upload.c +3 -5
@@ -340,7 +340,6 @@ firmware_upload_register(struct module * goto free_fw_upload_priv; } fw_upload->priv = fw_sysfs; - fw_sysfs->fw_upload_priv = fw_upload_priv; fw_dev = &fw_sysfs->dev; ret = alloc_lookup_fw_priv(name, &fw_cache, &fw_priv, NULL, 0, 0,
@@ -348,10 +347,12 @@ firmware_upload_register(struct module *if (ret !=0 ) {if (ret >0 ) ret = -EINVAL ; - goto free_fw_sysfs; +put_device (fw_dev); + goto free_fw_upload_priv; } fw_priv->is_paged_buf = true; fw_sysfs->fw_priv = fw_priv; + fw_sysfs->fw_upload_priv = fw_upload_priv; ret =device_add (fw_dev);if (ret) {
@@ -362,9 +363,6 @@ firmware_upload_register(struct module *return fw_upload; -free_fw_sysfs: -kfree (fw_sysfs); - free_fw_upload_priv:kfree (fw_upload_priv);
Greg Kroah-Hartman
maintainerPATCH 165/1067 net: usb: kalmia: bound RX frame length in kalmia_rx_fixup()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 47b6bcef6e679593d2e86e04ee72c46a4e2f7139 upstream.
kalmia_rx_fixup() computes usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH) as a u16, guarded only by a pre-loop check that skb->len is at least KALMIA_HEADER_LENGTH, which is 6. A device can deliver a short bulk-IN frame with skb->len in the 6 to 11 range, or leave a short trailing remainder on a later loop iteration. Either case underflows usb_packet_length to about 65530.
That bypasses the usb_packet_length < ether_packet_length truncation path. The device-supplied ether_packet_length, a le16 up to 65535 read from header_start[2], then drives a memcmp() and the following skb_trim() and skb_pull() past the end of the rx buffer. The rx buffer is hard_mtu * 10, which is 14000 bytes. That is an out of bounds read.
Require both the start and end framing headers to be present before subtracting them, on every loop iteration.
--- drivers/net/usb/kalmia.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/usb/kalmia.c +8 -0
@@ -276,6 +276,14 @@ kalmia_rx_fixup(struct usbnet *dev, stru"Received header: %6phC. Package length: %i\n" , header_start, skb->len - KALMIA_HEADER_LENGTH); +/* both framing headers must be present before we subtract +* them, otherwise usb_packet_length underflows and the +* device-supplied ether_packet_length drives an out of bounds +* access below +*/ +if (skb->len <2 *KALMIA_HEADER_LENGTH ) +return 0 ; +/* subtract start header and end header */ usb_packet_length = skb->len - (2 *KALMIA_HEADER_LENGTH ); ether_packet_length =get_unaligned_le16 (&header_start[2 ]);
Greg Kroah-Hartman
maintainerPATCH 166/1067 usb: cdc_acm: Add quirk for Uniden BC125AT scanner
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jared Baldridge <[email protected]>
commit 6eba58568f6cc3ff8515a00b05e258d8cfb72b72 upstream.
Uniden BC125AT radio scanner has a USB interface which fails to work with the cdc_acm driver:
usb 1-1: new full-speed USB device number 2 using uhci_hcd cdc_acm 1-1:1.0: Zero length descriptor references cdc_acm 1-1:1.0: probe with driver cdc_acm failed with error -22
usbcore: registered new interface driver cdc_acm
Adding the NO_UNION_NORMAL quirk for the device fixes the issue:
usb 1-1: new full-speed USB device number 2 using uhci_hcd cdc_acm 1-1:1.0: ttyACM0: USB ACM device
usbcore: registered new interface driver cdc_acm
lsusb -v of the device:
Bus 001 Device 002: ID 1965:0017 Uniden Corporation BC125AT Negotiated speed: Full Speed (12Mbps)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 2 Communications bDeviceSubClass 0 [unknown] bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x1965 Uniden Corporation idProduct 0x0017 BC125AT bcdDevice 0.01 iManufacturer 1 Uniden America Corp. iProduct 2 BC125AT iSerial 3 0001 bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0030
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 2 Communications
bInterfaceSubClass 2 Abstract (modem)
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x87 EP 7 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 10
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 10 CDC Data
bInterfaceSubClass 0 [unknown]
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Device Status: 0x0000
(Bus Powered)
--- drivers/usb/class/cdc-acm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/class/cdc-acm.c +3 -0
@@ -1786,6 +1786,9 @@ static const struct usb_device_id acm_id { USB_DEVICE(0x1901, 0x0006), /* GE Healthcare Patient Monitor UI Controller */ .driver_info =DISABLE_ECHO ,/* DISABLE ECHO in termios flag */ }, + { USB_DEVICE(0x1965, 0x0017), /* Uniden BC125AT */ + .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ + }, { USB_DEVICE(0x1965, 0x0018), /* Uniden UBC125XLT */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ },
Greg Kroah-Hartman
maintainerPATCH 167/1067 usb: cdnsp: fix stream context array leak in cdnsp_alloc_stream_info()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 3348f444a4ce43dd5c2d1aa41634cb6eff33aa64 upstream.
cdnsp_alloc_stream_info() allocates stream_info->stream_ctx_array with cdnsp_alloc_stream_ctx(). If a later stream ring allocation or stream mapping update fails, the error path frees the allocated stream rings and stream_rings array, but leaves stream_ctx_array allocated.
Free the stream context array before falling through to the stream_rings cleanup path.
--- drivers/usb/cdns3/cdnsp-mem.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/cdns3/cdnsp-mem.c +2 -0
@@ -632,6 +632,8 @@ cleanup_rings: } } +cdnsp_free_stream_ctx (pdev, pep); + cleanup_stream_rings:kfree (pep->stream_info.stream_rings);
Greg Kroah-Hartman
maintainerPATCH 168/1067 USB: core: add USB_QUIRK_NO_LPM for VIA Labs USB 2.0 hub
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rodrigo Lugathe da Conceição Alves <[email protected]>
commit bd728c3d9b1cc0bb0fda6a7055c5c8b55d7477b2 upstream.
The VIA Labs, Inc. USB 2.0 hub controller (2109:2817), found in a KVM switch, fails to enumerate high-power devices during cold boot and system restart.
Applying the kernel parameter
usbcore.quirks=2109:2817:k
resolves the issue.
Enumeration failure log:
usb 1-1.2.3: device descriptor read/64, error -32 usb 1-1.2.3: Device not responding to setup address. usb 1-1.2.3: device not accepting address 11, error -71 usb 1-1.2-port3: unable to enumerate USB device
Add USB_QUIRK_NO_LPM for this device.
--- drivers/usb/core/quirks.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/core/quirks.c +3 -0
@@ -574,6 +574,9 @@ static const struct usb_device_id usb_qu/* VLI disk */ { USB_DEVICE(0x2109, 0x0711), .driver_info = USB_QUIRK_NO_LPM }, + /* VIA Labs, Inc. USB2.0 Hub */ + { USB_DEVICE(0x2109, 0x2817), .driver_info = USB_QUIRK_NO_LPM }, + /* Raydium Touchscreen */ { USB_DEVICE(0x2386, 0x3114), .driver_info = USB_QUIRK_NO_LPM },
Greg Kroah-Hartman
maintainerPATCH 169/1067 usb: dwc3: meson-g12a: fix refcount leak in dwc3_meson_g12a_resume()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: WenTao Liang <[email protected]>
commit 692c354bef03b77b30e57e61934da502c8a12d45 upstream.
If dwc3_meson_g12a_resume() succeeds in calling reset_control_reset(), an internal triggered_count reference is acquired. If any later step fails (usb_init, phy_init, phy_power_on, regulator_enable, or usb_post_init), the function returns the error without rearming the reset control. This leaks the reference and leaves the reset control in a triggered state, causing future reset_control_reset() calls to incorrectly return early as if already reset.
Add an error path that calls reset_control_rearm() to balance the reference before returning the error.
--- drivers/usb/dwc3/dwc3-meson-g12a.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/usb/dwc3/dwc3-meson-g12a.c +9 -5
@@ -919,35 +919,39 @@ static int __maybe_unused dwc3_meson_g12 ret = priv->drvdata->usb_init (priv);if (ret) -return ret; + goto err_rearm;/* Init PHYs */ for (i =0 ; i <PHY_COUNT ; ++i) { ret =phy_init (priv->phys[i]);if (ret) -return ret; + goto err_rearm; }/* Set PHY Power */ for (i =0 ; i <PHY_COUNT ; ++i) { ret =phy_power_on (priv->phys[i]);if (ret) -return ret; + goto err_rearm; }if (priv->vbus && priv->otg_phy_mode ==PHY_MODE_USB_HOST ) { ret =regulator_enable (priv->vbus);if (ret) -return ret; + goto err_rearm; }if (priv->drvdata->usb_post_init) { ret = priv->drvdata->usb_post_init (priv);if (ret) -return ret; + goto err_rearm; }return 0 ; + +err_rearm: +reset_control_rearm (priv->reset); +return ret; }static const struct dev_pm_ops dwc3_meson_g12a_dev_pm_ops = {
Greg Kroah-Hartman
maintainerPATCH 170/1067 usb: gadget: composite: fix dead empty check in the USB_DT_OTG handler
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit f8f680609c2b3ab795ffcd6f21585b6dfc46d395 upstream.
The OTG branch of composite_setup() falls back to the first configuration when none is selected:
if (cdev->config) config = cdev->config; else config = list_first_entry(&cdev->configs, struct usb_configuration, list); if (!config) goto done; ... memcpy(req->buf, config->descriptors[0], value);
list_first_entry() never returns NULL. On an empty list it returns container_of() of the list head. So the "if (!config)" check is dead.
When cdev->configs is empty, config points at the head inside struct usb_composite_dev. config->descriptors[0] reads whatever sits at that offset. The memcpy copies up to w_length bytes of it into the response buffer.
cdev->configs can be empty in two cases. One is a teardown race on gadget unbind with a control transfer in flight. The other is a driver that sets is_otg before it adds a config. A reproducer that holds cdev->configs empty triggers a KASAN fault in this branch.
Use list_first_entry_or_null() so the existing check does its job.
--- drivers/usb/gadget/composite.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/gadget/composite.c +3 -2
@@ -1855,9 +1855,10 @@ composite_setup(struct usb_gadget *gadgeif (cdev->config) config = cdev->config;else - config =list_first_entry ( + config =list_first_entry_or_null ( &cdev->configs, - struct usb_configuration, list); + struct usb_configuration, + list);if (!config) goto done;
Greg Kroah-Hartman
maintainerPATCH 171/1067 usb: gadget: udc: Fix use-after-free in gadget_match_driver
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jimmy Hu <[email protected]>
commit 67e511d2989eb1c8c588b599ce2fcc6bb8e6f7ea upstream.
The udc structure acts as the management structure for the gadget, but their lifecycles are decoupled. A race condition exists where usb_del_gadget() frees the udc memory (e.g., via mode-switch work) while gadget_match_driver() concurrently accesses the freed udc memory (e.g., via configfs), causing a Use-After-Free (UAF) that triggers a NULL pointer dereference when the freed memory is zeroed:
[39430.908615][ T1171] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [39430.911397][ T1171] pc : __pi_strcmp+0x20/0x140 [39430.911441][ T1171] lr : gadget_match_driver+0x34/0x60 ... [39430.911890][ T1171] usb_gadget_register_driver_owner+0x50/0xf8 [39430.911910][ T1171] gadget_dev_desc_UDC_store+0xf4/0x140 [39430.931308][ T1171] configfs_write_iter+0xec/0x134
[39430.957058][ T1171] Workqueue: events_freezable __dwc3_set_mode [39430.957287][ T1171] dwc3_gadget_exit+0x34/0x8c [39430.957304][ T1171] __dwc3_set_mode+0xc0/0x664
Fix this by ensuring the udc structure remains allocated until the gadget is released. To achieve this, introduce a new usb_gadget_release() routine to the core. When the gadget is added, usb_add_gadget() stores the gadget's release routine in the udc structure and takes a reference to the udc. When the gadget is released, usb_gadget_release() drops the reference to the udc and then calls the gadget's release routine.
--- drivers/usb/gadget/udc/core.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/core.c +28 -1
@@ -31,8 +31,9 @@ static struct bus_type gadget_bus_type;/** * struct usb_udc - describes one usb device controller * @driver: the gadget driver pointer. For use by the class code -* @dev: the child device to the actual controller * @gadget: the gadget. For use by the class code +* @gadget_release: the gadget's release routine +* @dev: the child device to the actual controller * @list: for use by the udc class driver * @vbus: for udcs who care about vbus status, this value is real vbus status; * for udcs who do not care about vbus status, this value is always true
@@ -53,6 +54,7 @@ static struct bus_type gadget_bus_type;struct usb_udc {struct usb_gadget_driver *driver;struct usb_gadget *gadget; +void (*gadget_release)(struct device *dev);struct device dev;struct list_head list;bool vbus;
@@ -1351,6 +1353,17 @@ static void usb_udc_nop_release(struct ddev_vdbg (dev,"%s\n" , __func__); } +static void usb_gadget_release (struct device *dev) +{ +struct usb_gadget *gadget =dev_to_usb_gadget (dev); +struct usb_udc *udc = gadget->udc; +/* Cache the gadget's release routine to prevent UAF */ +void (*release)(struct device *dev) = udc->gadget_release; + +put_device (&udc->dev); +release (dev); +} +/** * usb_initialize_gadget - initialize a gadget and its embedded struct device * @parent: the parent device to this udc. Usually the controller driver's
@@ -1407,6 +1420,14 @@ int usb_add_gadget(struct usb_gadget *gamutex_init (&udc->connect_lock); udc->started = false; +/* +* Align decoupled lifecycles: take a UDC reference to ensure it +* remains allocated until the gadget is released, requiring an +* override of the gadget's release routine to drop it. +*/ + udc->gadget_release = gadget->dev.release; + gadget->dev.release = usb_gadget_release; +get_device (&udc->dev);mutex_lock (&udc_lock);list_add_tail (&udc->list, &udc_list);
@@ -1451,6 +1472,12 @@ int usb_add_gadget(struct usb_gadget *gamutex_lock (&udc_lock);list_del (&udc->list);mutex_unlock (&udc_lock); +/* +* Revert the override and drop the UDC reference to prevent +* leaking the UDC if the gadget was statically allocated. +*/ + gadget->dev.release = udc->gadget_release; +put_device (&udc->dev); err_put_udc:put_device (&udc->dev);
Greg Kroah-Hartman
maintainerPATCH 172/1067 USB: idmouse: fix use-after-free on disconnect race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit ff002c153f9722caece3983cc23dc4d9d4652cb4 upstream.
mutex_unlock() may access the mutex structure after releasing the lock and therefore cannot be used to manage lifetime of objects directly (unlike spinlocks and refcounts). [1][2]
Use a kref to release the driver data to avoid use-after-free in mutex_unlock() when release() races with disconnect().
[1] a51749ab34d9 ("locking/mutex: Document that mutex_unlock() is non-atomic")
[2] 2b9d9e0a9ba0 ("locking/mutex: Clarify that mutex_unlock(), and most other sleeping locks, can still use the lock object after it's unlocked")
--- drivers/usb/misc/idmouse.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
drivers/usb/misc/idmouse.c +22 -23
@@ -63,6 +63,7 @@ MODULE_DEVICE_TABLE(usb, idmouse_table);/* structure to hold all of our device specific stuff */ struct usb_idmouse { +struct kref kref;struct usb_device *udev;/* save off the usb device pointer */ struct usb_interface *interface;/* the interface for this device */
@@ -209,8 +210,10 @@ static int idmouse_resume(struct usb_intreturn 0 ; } -static inline void idmouse_delete (struct usb_idmouse *dev) +static inline void idmouse_delete (struct kref *kref) { + struct usb_idmouse *dev = container_of(kref, struct usb_idmouse, kref); +kfree (dev->bulk_in_buffer);kfree (dev); }
@@ -254,6 +257,8 @@ static int idmouse_open(struct inode *in/* increment our usage count for the driver */ ++dev->open; +kref_get (&dev->kref); +/* save our object in the file's private structure */ file->private_data = dev;
@@ -277,16 +282,11 @@ static int idmouse_release(struct inode/* lock our device */ mutex_lock (&dev->lock); - --dev->open; +mutex_unlock (&dev->lock); + +kref_put (&dev->kref, idmouse_delete); -if (!dev->present) { -/* the device was unplugged before the file was released */ -mutex_unlock (&dev->lock); -idmouse_delete (dev); - }else { -mutex_unlock (&dev->lock); - }return 0 ; }
@@ -334,6 +334,7 @@ static int idmouse_probe(struct usb_inteif (dev ==NULL )return -ENOMEM ; +kref_init (&dev->kref);mutex_init (&dev->lock); dev->udev = udev; dev->interface = interface;
@@ -342,8 +343,7 @@ static int idmouse_probe(struct usb_inte result =usb_find_bulk_in_endpoint (iface_desc, &endpoint);if (result) {dev_err (&interface->dev,"Unable to find bulk-in endpoint.\n" ); -idmouse_delete (dev); -return result; + goto err_put_kref; } dev->orig_bi_size =usb_endpoint_maxp (endpoint);
@@ -351,8 +351,8 @@ static int idmouse_probe(struct usb_inte dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; dev->bulk_in_buffer =kmalloc (IMGSIZE + dev->bulk_in_size,GFP_KERNEL );if (!dev->bulk_in_buffer) { -idmouse_delete (dev); -return -ENOMEM ; + result = -ENOMEM ; + goto err_put_kref; }/* allow device read, write and ioctl */
@@ -364,14 +364,18 @@ static int idmouse_probe(struct usb_inteif (result) {/* something prevented us from registering this device */ dev_err (&interface->dev,"Unable to allocate minor number.\n" ); -idmouse_delete (dev); -return result; + goto err_put_kref; }/* be noisy */ dev_info (&interface->dev,"%s now attached\n" ,DRIVER_DESC );return 0 ; + +err_put_kref: +kref_put (&dev->kref, idmouse_delete); + +return result; }static void idmouse_disconnect (struct usb_interface *interface)
@@ -387,14 +391,9 @@ static void idmouse_disconnect(struct us/* prevent device read, write and ioctl */ dev->present =0 ; -/* if the device is opened, idmouse_release will clean this up */ -if (!dev->open) { -mutex_unlock (&dev->lock); -idmouse_delete (dev); - }else { -/* unlock */ -mutex_unlock (&dev->lock); - } +mutex_unlock (&dev->lock); + +kref_put (&dev->kref, idmouse_delete);dev_info (&interface->dev,"disconnected\n" ); }
Greg Kroah-Hartman
maintainerPATCH 173/1067 USB: ldusb: fix use-after-free on disconnect race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 19bdfc7b3c179331eafa423d87e1336f43bbfeb8 upstream.
mutex_unlock() may access the mutex structure after releasing the lock and therefore cannot be used to manage lifetime of objects directly (unlike spinlocks and refcounts). [1][2]
Use a kref to release the driver data to avoid use-after-free in mutex_unlock() when release() races with disconnect().
[1] a51749ab34d9 ("locking/mutex: Document that mutex_unlock() is non-atomic")
[2] 2b9d9e0a9ba0 ("locking/mutex: Clarify that mutex_unlock(), and most other sleeping locks, can still use the lock object after it's unlocked")
--- drivers/usb/misc/ldusb.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/usb/misc/ldusb.c +18 -20
@@ -150,6 +150,7 @@ MODULE_PARM_DESC(min_interrupt_out_inter/* Structure to hold all of our device specific stuff */ struct ld_usb { +struct kref kref;struct mutex mutex;/* locks this structure */ struct usb_interface *intf;/* save off the usb interface pointer */ unsigned long disconnected:1 ;
@@ -201,8 +202,10 @@ static void ld_usb_abort_transfers(struc/* * ld_usb_delete */ -static void ld_usb_delete (struct ld_usb *dev) +static void ld_usb_delete (struct kref *kref) { + struct ld_usb *dev = container_of(kref, struct ld_usb, kref); +/* free data structures */ usb_free_urb (dev->interrupt_in_urb);usb_free_urb (dev->interrupt_out_urb);
@@ -355,6 +358,8 @@ static int ld_usb_open(struct inode *ino goto unlock_exit; } +kref_get (&dev->kref); +/* save device in the file's private structure */ file->private_data = dev;
@@ -381,17 +386,8 @@ static int ld_usb_release(struct inode *mutex_lock (&dev->mutex); -if (dev->open_count !=1 ) { - retval = -ENODEV ; +if (dev->disconnected) goto unlock_exit; - } -if (dev->disconnected) { -/* the device was unplugged before the file was released */ -mutex_unlock (&dev->mutex); -/* unlock here as ld_usb_delete frees dev */ -ld_usb_delete (dev); - goto exit; - }/* wait until write transfer is finished */ if (dev->interrupt_out_busy)
@@ -401,7 +397,7 @@ static int ld_usb_release(struct inode * unlock_exit:mutex_unlock (&dev->mutex); - +kref_put (&dev->kref, ld_usb_delete); exit:return retval; }
@@ -660,6 +656,8 @@ static int ld_usb_probe(struct usb_inter dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) goto exit; + +kref_init (&dev->kref);mutex_init (&dev->mutex);spin_lock_init (&dev->rbsl); dev->intf = intf;
@@ -741,7 +739,7 @@ exit:return retval; error: -ld_usb_delete (dev); +kref_put (&dev->kref, ld_usb_delete);return retval; }
@@ -769,18 +767,18 @@ static void ld_usb_disconnect(struct usbmutex_lock (&dev->mutex); -/* if the device is not opened, then we clean up right now */ -if (!dev->open_count) { -mutex_unlock (&dev->mutex); -ld_usb_delete (dev); - }else { - dev->disconnected =1 ; + dev->disconnected =1 ; + +if (dev->open_count) {/* wake up pollers */ wake_up_interruptible_all (&dev->read_wait);wake_up_interruptible_all (&dev->write_wait); -mutex_unlock (&dev->mutex); } +mutex_unlock (&dev->mutex); + +kref_put (&dev->kref, ld_usb_delete); +dev_info (&intf->dev,"LD USB Device #%d now disconnected\n" , (minor -USB_LD_MINOR_BASE )); }
Greg Kroah-Hartman
maintainerPATCH 174/1067 USB: iowarrior: fix use-after-free on disconnect
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit bc0e4f16c44e50daa0b1ea729934baa3b4815dee upstream.
Submitted write URBs are not stopped on close() and therefore need to be stopped unconditionally on disconnect() to avoid use-after-free in the completion handler.
--- drivers/usb/misc/iowarrior.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/misc/iowarrior.c +3 -1
@@ -920,13 +920,15 @@ static void iowarrior_disconnect(struct/* prevent device read, write and ioctl */ dev->present =0 ; +/* write urbs are not stopped on close() so kill unconditionally */ +usb_kill_anchored_urbs (&dev->submitted); +if (dev->opened) {/* There is a process that holds a filedescriptor to the device , so we only shutdown read-/write-ops going on. Deleting the device is postponed until close() was called. */ usb_kill_urb (dev->int_in_urb); -usb_kill_anchored_urbs (&dev->submitted);wake_up_interruptible (&dev->read_wait);wake_up_interruptible (&dev->write_wait);mutex_unlock (&dev->mutex);
Greg Kroah-Hartman
maintainerPATCH 148/1067 cpufreq: intel_pstate: Sync policy->cur during CPU offline
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fushuai Wang <[email protected]>
commit bcbdaa1086c25a8a5d48e04e1b82fdfb0682b681 upstream.
When a CPU goes offline with HWP disabled, intel_pstate_set_min_pstate() sets the MSR_IA32_PERF_CTL to minimum frequency to prevent SMT siblings from being restricted. However, the policy->cur value was not updated, leaving it at the previous value.
When the CPU comes back online, governor->limits() checks if target_freq equals policy->cur and skips the frequency adjustment if they match. Since policy->cur still holds the previous value, the governor does not call cpufreq_driver->target to update MSR_IA32_PERF_CTL.
Fix this by synchronizing policy->cur with the hardware state when setting minimum pstate during CPU offline.
--- drivers/cpufreq/intel_pstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -2
@@ -2631,10 +2631,12 @@ static int intel_cpufreq_cpu_offline(str* from getting to lower performance levels, so force the minimum * performance on CPU offline to prevent that from happening. */ -if (hwp_active) +if (hwp_active) {intel_pstate_hwp_offline (cpu); -else + }else {intel_pstate_set_min_pstate (cpu); + policy->cur = cpu->pstate.min_freq; + }intel_pstate_exit_perf_limits (policy);
Greg Kroah-Hartman
maintainerPATCH 175/1067 USB: quirks: add NO_LPM for the Samsung T5 EVO Portable SSD
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Erich E. Hoover <[email protected]>
commit fc591787785b9709a0bb65a7df3ba2537d611c47 upstream.
The Samsung T5 EVO Portable SSD (04e8:6200) exhibit two forms of link instability when USB Link Power Management is enabled:
1. The units fail to initialize properly on first detection, resulting in a lockup in the drive where it must be power cycled or the kernel will not recognize the presence of the device.
2. If used for sustained operations (small amounts of continuous data are transferred to the unit) then the unit will "hiccup" after roughly 8 hours of use and will disconnect and reconnect. This has a certain probability of triggering the first issue, but also causes mount points to become invalid since the device gets issued a new letter.
--- drivers/usb/core/quirks.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/core/quirks.c +3 -0
@@ -297,6 +297,9 @@ static const struct usb_device_id usb_qu/* CarrolTouch 4500U */ { USB_DEVICE(0x04e7, 0x0030), .driver_info = USB_QUIRK_RESET_RESUME }, + /* Samsung T5 EVO Portable SSD */ + { USB_DEVICE(0x04e8, 0x6200), .driver_info = USB_QUIRK_NO_LPM }, + /* Samsung Android phone modem - ID conflict with SPH-I500 */ { USB_DEVICE(0x04e8, 0x6601), .driver_info = USB_QUIRK_CONFIG_INTF_STRINGS },
Greg Kroah-Hartman
maintainerPATCH 176/1067 USB: legousbtower: fix use-after-free on disconnect race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 62fc8eb1b1481051f7bab4aa93d79809053dd09f upstream.
mutex_unlock() may access the mutex structure after releasing the lock and therefore cannot be used to manage lifetime of objects directly (unlike spinlocks and refcounts). [1][2]
Use a kref to release the driver data to avoid use-after-free in mutex_unlock() when release() races with disconnect().
[1] a51749ab34d9 ("locking/mutex: Document that mutex_unlock() is non-atomic")
[2] 2b9d9e0a9ba0 ("locking/mutex: Clarify that mutex_unlock(), and most other sleeping locks, can still use the lock object after it's unlocked")
--- drivers/usb/misc/legousbtower.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/usb/misc/legousbtower.c +19 -18
@@ -185,6 +185,7 @@ MODULE_DEVICE_TABLE(usb, tower_table);/* Structure to hold all of our device specific stuff */ struct lego_usb_tower { +struct kref kref;struct mutex lock;/* locks this structure */ struct usb_device *udev;/* save off the usb device pointer */ unsigned char minor;/* the starting minor number for this device */
@@ -220,7 +221,6 @@ struct lego_usb_tower {/* local function prototypes */ static ssize_t tower_read (struct file *file,char __user *buffer,size_t count,loff_t *ppos);static ssize_t tower_write (struct file *file,const char __user *buffer,size_t count,loff_t *ppos); -static inline void tower_delete (struct lego_usb_tower *dev);static int tower_open (struct inode *inode,struct file *file);static int tower_release (struct inode *inode,struct file *file);static __poll_t tower_poll (struct file *file,poll_table *wait);
@@ -286,8 +286,10 @@ static inline void lego_usb_tower_debug_/* * tower_delete */ -static inline void tower_delete (struct lego_usb_tower *dev) +static inline void tower_delete (struct kref *kref) { + struct lego_usb_tower *dev = container_of(kref, struct lego_usb_tower, kref); +/* free data structures */ usb_free_urb (dev->interrupt_in_urb);usb_free_urb (dev->interrupt_out_urb);
@@ -381,6 +383,8 @@ static int tower_open(struct inode *inod dev->open_count =1 ; +kref_get (&dev->kref); + unlock_exit:mutex_unlock (&dev->lock);
@@ -404,14 +408,8 @@ static int tower_release(struct inode *imutex_lock (&dev->lock); -if (dev->disconnected) { -/* the device was unplugged before the file was released */ - -/* unlock here as tower_delete frees dev */ -mutex_unlock (&dev->lock); -tower_delete (dev); - goto exit; - } +if (dev->disconnected) + goto out_unlock;/* wait until write transfer is finished */ if (dev->interrupt_out_busy) {
@@ -425,7 +423,9 @@ static int tower_release(struct inode *i dev->open_count =0 ; +out_unlock:mutex_unlock (&dev->lock); +kref_put (&dev->kref, tower_delete); exit:return retval; }
@@ -752,6 +752,7 @@ static int tower_probe(struct usb_interfif (!dev) goto exit; +kref_init (&dev->kref);mutex_init (&dev->lock); dev->udev =usb_get_dev (udev);spin_lock_init (&dev->read_buffer_lock);
@@ -828,7 +829,7 @@ exit:return retval; error: -tower_delete (dev); +kref_put (&dev->kref, tower_delete);return retval; }
@@ -856,18 +857,18 @@ static void tower_disconnect(struct usb_mutex_lock (&dev->lock); -/* if the device is not opened, then we clean up right now */ -if (!dev->open_count) { -mutex_unlock (&dev->lock); -tower_delete (dev); - }else { - dev->disconnected =1 ; + dev->disconnected =1 ; + +if (dev->open_count) {/* wake up pollers */ wake_up_interruptible_all (&dev->read_wait);wake_up_interruptible_all (&dev->write_wait); -mutex_unlock (&dev->lock); } +mutex_unlock (&dev->lock); + +kref_put (&dev->kref, tower_delete); +dev_info (&interface->dev,"LEGO USB Tower #%d now disconnected\n" , (minor -LEGO_USB_TOWER_MINOR_BASE )); }
Greg Kroah-Hartman
maintainerPATCH 177/1067 usb: sl811-hcd: disable controller wakeup on remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 4e8ba83ac4d311992e6a4c21de5dd705010df06e upstream.
sl811h_probe() enables the HCD controller device as a wakeup source after usb_add_hcd() succeeds, but sl811h_remove() removes the HCD and releases the driver resources without disabling that wakeup source.
Disable controller wakeup after usb_remove_hcd() and before usb_put_hcd() so the wakeup source object is detached while the controller device pointer is still available.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/usb/host/sl811-hcd.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/host/sl811-hcd.c +1 -0
@@ -1590,6 +1590,7 @@ sl811h_remove(struct platform_device *deremove_debug_file (sl811);usb_remove_hcd (hcd); +device_wakeup_disable (hcd->self.controller);/* some platforms may use IORESOURCE_IO */ res =platform_get_resource (dev,IORESOURCE_MEM ,1 );
Greg Kroah-Hartman
maintainerPATCH 178/1067 USB: storage: include US_FL_NO_SAME in quirks mask
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 2c00e09e3f9f06f8434f5ea2ee6179ce46692ee6 upstream.
usb_stor_adjust_quirks() parses the usb-storage.quirks module parameter into a new flag set and then applies it with the quirk mask to override built-in flags.
The mask is meant to cover the flags that can be overridden by the module parameter. The 'k' quirk character sets US_FL_NO_SAME, but US_FL_NO_SAME is not included in the mask.
As a result, the module parameter can set US_FL_NO_SAME, but it cannot clear a built-in US_FL_NO_SAME flag by providing an override entry that omits 'k'.
Add US_FL_NO_SAME to the mask so that the module parameter can override it in the same way as the other supported flags.
--- drivers/usb/storage/usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/storage/usb.c +1 -1
@@ -488,7 +488,7 @@ void usb_stor_adjust_quirks(struct usb_dUS_FL_INITIAL_READ10 |US_FL_WRITE_CACHE |US_FL_NO_ATA_1X |US_FL_NO_REPORT_OPCODES |US_FL_MAX_SECTORS_240 |US_FL_NO_REPORT_LUNS | - US_FL_ALWAYS_SYNC); + US_FL_ALWAYS_SYNC | US_FL_NO_SAME); p = quirks;while (*p) {
Greg Kroah-Hartman
maintainerPATCH 179/1067 USB: misc: uss720: unregister parport on probe failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit b4ecbdc4f8830f5586c4a5cfc384c00f20f8f8b3 upstream.
uss720_probe() registers a parport before reading the 1284 register used to detect unsupported Belkin F5U002 adapters. If get_1284_register() fails, the error path drops the driver private data and the USB device reference, but leaves the parport device registered.
Leaving the port registered is more than a private allocation leak:parport_register_port() has already reserved a parport number and registered the parport bus device, while pp->private_data still points at the private data that the common error path is about to release.
Undo the pre-announce registration in the get_1284_register() failure branch before jumping to the common private-data cleanup path. Clear priv->pp first, matching the disconnect path and avoiding a stale pointer in the private data.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/usb/misc/uss720.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/misc/uss720.c +4 -1
@@ -732,8 +732,11 @@ static int uss720_probe(struct usb_inter* here. */ ret =get_1284_register (pp,0 , ®,GFP_KERNEL );dev_dbg (&intf->dev,"reg: %7ph\n" , priv->reg); -if (ret <0 ) +if (ret <0 ) { + priv->pp =NULL ; +parport_del_port (pp); goto probe_abort; + } ret =usb_find_last_int_in_endpoint (interface, &epd);if (!ret) {
Greg Kroah-Hartman
maintainerPATCH 180/1067 usb: mtu3: unmap request DMA on queue failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 0bddda5a11665c210339de76d27ebbd1a2e0b43c upstream.
mtu3_gadget_queue() maps the request before checking whether the QMU GPD ring can accept another transfer. the request is returned with -EAGAIN before it is linked on the endpoint request list if mtu3_prepare_transfer() fails.
Normal completion and dequeue paths unmap requests from mtu3_req_complete(), but this error path never reaches that helper, so the DMA mapping is left active. Unmap the request before returning from the failed queue path.
--- drivers/usb/mtu3/mtu3_gadget.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/mtu3/mtu3_gadget.c +1 -0
@@ -305,6 +305,7 @@ static int mtu3_gadget_queue(struct usb_if (mtu3_prepare_transfer (mep)) { ret = -EAGAIN ; +usb_gadget_unmap_request (&mtu->g, req, mep->is_in); goto error; }
Greg Kroah-Hartman
maintainerPATCH 181/1067 USB: serial: keyspan_pda: fix information leak
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 6bfc8d01ac4068eced509f8fc74d0cd205e4dcec upstream.
The write() callback is supposed to return the number of characters accepted or a negative errno. Since the addition of write fifo support the keyspan_pda implementation will however return the number characters submitted to the device if the write urb is not already in use. If this number is larger than the number of characters passed to write(), the line discipline continues writing data from beyond the tty write buffer.
Fix the information leak by making sure that keyspan_pda_write_start() returns zero on success as intended.
--- drivers/usb/serial/keyspan_pda.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/serial/keyspan_pda.c +1 -1
@@ -514,7 +514,7 @@ static int keyspan_pda_write_start(strucif (count == room)schedule_work (&priv->unthrottle_work); -return count; +return 0 ; }static void keyspan_pda_write_bulk_callback (struct urb *urb)
Greg Kroah-Hartman
maintainerPATCH 182/1067 USB: serial: option: add Telit Cinterion FE990D50 compositions
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabio Porcedda <[email protected]>
commit b33ab1dd80f5c1742f49eb6ec7b337c5ffcf3d32 upstream.
Add support for Telit Cinterion FE990D50 compositions:
0x990: RNDIS + tty (AT/NMEA) + tty (AT) + tty (AT) + tty (AT) +
tty (diag) + ADPL + adb
T: Bus=01 Lev=01 Prnt=01 Port=06 Cnt=03 Dev#= 3 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=1bc7 ProdID=0990 Rev=06.06 S: Manufacturer=Telit Cinterion S: Product=FE990 S: SerialNumber=90b6a3ed C: #Ifs=10 Cfg#= 1 Atr=e0 MxPwr=500mA I: If#= 0 Alt= 0 #EPs= 1 Cls=ef(misc ) Sub=04 Prot=01 Driver=rndis_host E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl=32ms I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=rndis_host E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=60 Driver=option E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=84(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=86(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=88(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 5 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=89(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8a(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 6 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option E: Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8b(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 7 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=80 Driver=(none) E: Ad=8c(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 8 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=70 Driver=(none) E: Ad=8d(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 9 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=01 Driver=(none) E: Ad=07(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8e(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
0x991: rmnet + tty (AT/NMEA) + tty (AT) + tty (AT) + tty (AT) +
tty (diag) + ADPL + adb
T: Bus=01 Lev=01 Prnt=01 Port=06 Cnt=03 Dev#= 9 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=1bc7 ProdID=0991 Rev=06.06 S: Manufacturer=Telit Cinterion S: Product=FE990 S: SerialNumber=90b6a3ed C: #Ifs= 9 Cfg#= 1 Atr=e0 MxPwr=500mA I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=50 Driver=(none) E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl=32ms I: If#= 1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=60 Driver=option E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=84(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=86(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=88(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=89(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8a(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 5 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option E: Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8b(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 6 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=80 Driver=(none) E: Ad=8c(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 7 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=70 Driver=(none) E: Ad=8d(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 8 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=01 Driver=(none) E: Ad=07(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8e(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
0x992: MBIM + tty (AT/NMEA) + tty (AT) + tty (AT) + tty (AT) +
tty (diag) + ADPL + adb
T: Bus=01 Lev=01 Prnt=01 Port=06 Cnt=03 Dev#= 12 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=1bc7 ProdID=0992 Rev=06.06 S: Manufacturer=Telit Cinterion S: Product=FE990 S: SerialNumber=90b6a3ed C: #Ifs=10 Cfg#= 1 Atr=e0 MxPwr=500mA I: If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim E: Ad=82(I) Atr=03(Int.) MxPS= 64 Ivl=32ms I: If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=60 Driver=option E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=84(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=86(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=88(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 5 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=89(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8a(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 6 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option E: Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8b(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 7 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=80 Driver=(none) E: Ad=8c(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 8 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=70 Driver=(none) E: Ad=8d(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 9 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=01 Driver=(none) E: Ad=07(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8e(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
0x993: ECM + tty (AT/NMEA) + tty (AT) + tty (AT) + tty (AT) +
tty (diag) + ADPL + adb
T: Bus=01 Lev=01 Prnt=01 Port=06 Cnt=03 Dev#= 15 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=1bc7 ProdID=0993 Rev=06.06 S: Manufacturer=Telit Cinterion S: Product=FE990 S: SerialNumber=90b6a3ed C: #Ifs=10 Cfg#= 1 Atr=e0 MxPwr=500mA I: If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=06 Prot=00 Driver=cdc_ether E: Ad=82(I) Atr=03(Int.) MxPS= 16 Ivl=32ms I: If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_ether E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=60 Driver=option E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=84(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=86(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=88(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 5 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=89(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8a(I) Atr=03(Int.) MxPS= 10 Ivl=32ms I: If#= 6 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option E: Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8b(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 7 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=80 Driver=(none) E: Ad=8c(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 8 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=70 Driver=(none) E: Ad=8d(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms I: If#= 9 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=01 Driver=(none) E: Ad=07(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=8e(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
--- drivers/usb/serial/option.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/usb/serial/option.c +16 -0
@@ -1326,6 +1326,22 @@ static const struct usb_device_id option { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_CC864_SINGLE) }, { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_DE910_DUAL) }, { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UE910_V2) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0990, 0xff, 0xff, 0x30), /* Telit FE990D50 (RNDIS) */ + .driver_info = NCTRL(6) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0990, 0xff, 0xff, 0x40) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0990, 0xff, 0xff, 0x60) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0991, 0xff, 0xff, 0x30), /* Telit FE990D50 (rmnet) */ + .driver_info = NCTRL(5) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0991, 0xff, 0xff, 0x40) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0991, 0xff, 0xff, 0x60) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0992, 0xff, 0xff, 0x30), /* Telit FE990D50 (MBIM) */ + .driver_info = NCTRL(6) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0992, 0xff, 0xff, 0x40) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0992, 0xff, 0xff, 0x60) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0993, 0xff, 0xff, 0x30), /* Telit FE990D50 (ECM) */ + .driver_info = NCTRL(6) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0993, 0xff, 0xff, 0x40) }, + { USB_DEVICE_AND_INTERFACE_INFO(TELIT_VENDOR_ID, 0x0993, 0xff, 0xff, 0x60) }, { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1031, 0xff), /* Telit LE910C1-EUX */ .driver_info = NCTRL(0) | RSVD(3) }, { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1033, 0xff), /* Telit LE910C1-EUX (ECM) */
Greg Kroah-Hartman
maintainerPATCH 183/1067 USB: serial: digi_acceleport: fix broken rx after throttle
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 83a3dfc018943b05b6daf3a6f891833e1aabfa1f upstream.
If the port is closed while throttled, the read urb is never resubmitted and the port will not receive any further data until the device is reconnected (or the driver is rebound).
Clear the throttle flags and submit the urb if needed when opening the port.
--- drivers/usb/serial/digi_acceleport.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/usb/serial/digi_acceleport.c +16 -0
@@ -1072,6 +1072,7 @@ static int digi_open(struct tty_struct *unsigned char buf[32 ];struct digi_port *priv =usb_get_serial_port_data (port);struct ktermios not_termios; +int throttled;/* be sure the device is started up */ if (digi_startup_device (port->serial) !=0 )
@@ -1099,6 +1100,21 @@ static int digi_open(struct tty_struct * not_termios.c_iflag = ~tty->termios.c_iflag;digi_set_termios (tty, port, ¬_termios); } + +spin_lock_irq (&priv->dp_port_lock); + throttled = priv->dp_throttle_restart; + priv->dp_throttled =0 ; + priv->dp_throttle_restart =0 ; +spin_unlock_irq (&priv->dp_port_lock); + +if (throttled) { + ret =usb_submit_urb (port->read_urb,GFP_KERNEL ); +if (ret) { +dev_err (&port->dev,"failed to submit read urb: %d\n" , ret); +return ret; + } + } +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 184/1067 USB: serial: digi_acceleport: fix hard lockup on disconnect
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 5c1ea24b53bf3bfb859f0a05573997487975da23 upstream.
If submitting the OOB write urb fails persistently (e.g if the device is being disconnected) the driver would loop indefinitely with interrupts disabled.
Check for urb submission errors when sending OOB commands to avoid hanging if, for example, open(), set_termios() or close() races with a physical disconnect.
This is issue was flagged by Sashiko when reviewing an unrelated change to the driver.
--- drivers/usb/serial/digi_acceleport.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/usb/serial/digi_acceleport.c +7 -5
@@ -396,12 +396,14 @@ static int digi_write_oob_command(struct len &= ~3 ;memcpy (oob_port->write_urb->transfer_buffer, buf, len); oob_port->write_urb->transfer_buffer_length = len; + ret =usb_submit_urb (oob_port->write_urb,GFP_ATOMIC ); -if (ret ==0 ) { - oob_priv->dp_write_urb_in_use =1 ; - count -= len; - buf += len; - } +if (ret) +break ; + + oob_priv->dp_write_urb_in_use =1 ; + count -= len; + buf += len; }spin_unlock_irqrestore (&oob_priv->dp_port_lock, flags);if (ret)
Greg Kroah-Hartman
maintainerPATCH 149/1067 sched/rt: Have RT_PUSH_IPI be default off for non PREEMPT_RT
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit dd29c017aed628076e915fe4cdfb5392fd4c5cab upstream.
RT migration is done aggressively. When a CPU schedules out a high priority RT task for a lower priority task, it will look to see if there's any RT tasks that are waiting to run on another CPU that is of higher priority than the task this CPU is about to run. If it finds one, it will pull that task over to the CPU and allow it to run there instead.
Normally, this pulling is done by looking at the RT overloaded mask (rto) which contains all the CPUs in the scheduler domain with RT tasks that are waiting to run due to a higher priority RT task currently running on their CPU. The CPU that is about to schedule a lower priority task will grab the rq lock of the overloaded CPU and move the RT task from that CPU's runqueue to the local one and schedule the higher priority RT task.
This caused issues when a lot of CPUs would schedule a lower priority task at the same time. They would all try to grab the same runqueue lock of the CPU with the overloaded RT tasks. Only the first CPU that got in will get that task. All the others would wait until they got the runqueue lock and see there's nothing to pull and do nothing. On systems with lots of CPUs, this caused a large latency (up to 500us) which is beyond what PREEMPT_RT is to allow.
The solution to that was to create an RT_PUSH_IPI logic. When any CPU wanted to pull a task, instead of grabbing the runqueue lock of the overloaded CPU, it would start by sending an IPI to the overloaded CPU, and that IPI handler would have the CPU with the waiting RT task do a push instead. Then that handler would send an IPI to the next CPU with overloaded RT tasks, and so on. Note, after the first CPU starts this process, if another CPU wanted to do a pull, it would see that the process has already begun and would only increment a counter to have the IPIs continue again.
The RT_PUSH_IPI solved the latency problem with PREEMPT_RT but could cause a new issue with non PREEMPT_RT. Namely, softirqs run in a threaded context on PREEMPT_RT but they can run in an interrupt context in non-RT.
If an IPI lands on a CPU that has just woken up multiple RT tasks and the current CPU is running a non RT or a low priority RT task, instead of doing a push, it would simply do a schedule on that CPU. But if a softirq was also executing on this CPU, the schedule would need to wait until the softirq finished. Until then, the CPU would still be considered overloaded as there are RT tasks still waiting to run on it.
A live lock occurred on a workload that was doing heavy networking traffic on a large machine where the softirqs would run 500us out of 750us. And it would also be waking up RT tasks, causing the RT pull logic to be constantly executed.
When a softirq triggered on a CPU with RT tasks queued but not running yet, and the other CPUs would see this CPU as being overloaded, they would send an IPI over to it. The CPU would notice that the waiting RT tasks are of higher priority than the currently running task and simply schedule that CPU instead. But because the softirq was executing, before it could schedule, it would receive another IPI to do the same. The amount of IPIs would slow down the currently running softirq so much that before it could return back to task context, it would execute another softirq never allowing the CPU to schedule. This live locked that CPU.
As RT_PUSH_IPI was created to help PREEMPT_RT, make it default off if PREEMPT_RT is not enabled.
--- kernel/sched/features.h | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/sched/features.h +8 -0
@@ -79,8 +79,16 @@ SCHED_FEAT(WARN_DOUBLE_CLOCK, false)* rq lock and possibly create a large contention, sending an * IPI to that CPU and let that CPU push the RT task to where * it should go may be a better scenario. +* +* This is best for PREEMPT_RT, but for non-RT it can cause issues +* when preemption is disabled for long periods of time. Have +* it only default enabled for PREEMPT_RT. */ +# ifdef CONFIG_PREEMPT_RT SCHED_FEAT(RT_PUSH_IPI, true) +# else +SCHED_FEAT(RT_PUSH_IPI, false) +# endif #endif SCHED_FEAT (RT_RUNTIME_SHARE , false)
Greg Kroah-Hartman
maintainerPATCH 185/1067 USB: serial: digi_acceleport: fix write buffer corruption
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 24ca1fea8f2753bf33e1d458ec1ae5d9b7796a65 upstream.
The digi_write_inb_command() is supposed to wait for the write urb to become available or return an error, but instead it updates the transfer buffer and tries to resubmit the urb on timeout.
To make things worse, for commands like break control where no timeout is used, the driver would corrupt the urb immediately due to a broken jiffies comparison (on 32-bit machines this takes five minutes of uptime to trigger due to INITIAL_JIFFIES).
Fix this by adding the missing return on timeout and waiting indefinitely when no timeout has been specified as intended.
This issue was (sort of) flagged by Sashiko when reviewing an unrelated change to the driver.
--- drivers/usb/serial/digi_acceleport.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/usb/serial/digi_acceleport.c +10 -5
@@ -433,20 +433,22 @@ static int digi_write_inb_command(structint len;struct digi_port *priv =usb_get_serial_port_data (port);unsigned char *data = port->write_urb->transfer_buffer; +unsigned long expire;unsigned long flags;dev_dbg (&port->dev,"digi_write_inb_command: TOP: port=%d, count=%d\n" , priv->dp_port_num, count);if (timeout) - timeout += jiffies; -else - timeout =ULONG_MAX ; + expire = jiffies + timeout;spin_lock_irqsave (&priv->dp_port_lock, flags);while (count >0 && ret ==0 ) { -while (priv->dp_write_urb_in_use && -time_before (jiffies, timeout)) { +while (priv->dp_write_urb_in_use) { +if (timeout &&time_after (jiffies, expire)) { + ret = -ETIMEDOUT ; +break ; + }cond_wait_interruptible_timeout_irqrestore ( &priv->write_wait,DIGI_RETRY_TIMEOUT , &priv->dp_port_lock, flags);
@@ -455,6 +457,9 @@ static int digi_write_inb_command(structspin_lock_irqsave (&priv->dp_port_lock, flags); } +if (ret) +break ; +/* len must be a multiple of 4 and small enough to */ /* guarantee the write will send buffered data first, */ /* so commands are in order with data and not split */
Greg Kroah-Hartman
maintainerPATCH 186/1067 USB: ulpi: fix memory leak on registration failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 8af6812795869a66e9b26044f455b13deecdb69c upstream.
The allocated device name is never freed on early ULPI device registration failures.
Fix this by initialising the device structure earlier and releasing the initial reference whenever registration fails.
--- drivers/usb/common/ulpi.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/usb/common/ulpi.c +10 -13
@@ -281,28 +281,24 @@ static int ulpi_register(struct device * ulpi->dev.parent = dev;/* needed early for ops */ ulpi->dev.bus = &ulpi_bus; ulpi->dev.type = &ulpi_dev_type; + +device_initialize (&ulpi->dev); +dev_set_name (&ulpi->dev,"%s.ulpi" ,dev_name (dev));ACPI_COMPANION_SET (&ulpi->dev,ACPI_COMPANION (dev)); ret =ulpi_of_register (ulpi); -if (ret) { -kfree (ulpi); +if (ret)return ret; - } ret =ulpi_read_id (ulpi); -if (ret) { -of_node_put (ulpi->dev.of_node); -kfree (ulpi); +if (ret)return ret; - } - ret =device_register (&ulpi->dev); -if (ret) { -put_device (&ulpi->dev); + ret =device_add (&ulpi->dev); +if (ret)return ret; - } root =debugfs_create_dir (dev_name (&ulpi->dev), ulpi_root);debugfs_create_file ("regs" ,0444 , root, ulpi, &ulpi_regs_fops);
@@ -334,9 +330,10 @@ struct ulpi *ulpi_register_interface(str ulpi->ops = ops; ret =ulpi_register (dev, ulpi); -if (ret) +if (ret) { +put_device (&ulpi->dev);return ERR_PTR (ret); - + }return ulpi; }
Greg Kroah-Hartman
maintainerPATCH 187/1067 USB: usb-storage: ene_ub6250: restore media-ready check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 5fc3f333c001f1e308bbcdeecdec0d054d24338b upstream.
Commit 1892bf90677a ("USB: usb-storage: Fix use of bitfields for hardware data in ene_ub6250.c") converted the media status fields from bitfields to bit masks.
The original ene_transport() test called ene_init() only when neither media type was ready:
!(sd_ready || ms_ready)
The converted test became:
!sd_ready || ms_ready
This is not equivalent. Restore the original semantics by testing that both ready bits are clear before calling ene_init().
--- drivers/usb/storage/ene_ub6250.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/storage/ene_ub6250.c +2 -1
@@ -2306,7 +2306,8 @@ static int ene_transport(struct scsi_cmn/*US_DEBUG(usb_stor_show_command(us, srb)); */ scsi_set_resid (srb,0 ); -if (unlikely (!(info->SD_Status & SD_Ready) || (info->MS_Status & MS_Ready))) +if (unlikely (!(info->SD_Status & SD_Ready) && + !(info->MS_Status & MS_Ready))) result =ene_init (us);if (result ==USB_STOR_XFER_GOOD ) { result =USB_STOR_TRANSPORT_ERROR ;
Greg Kroah-Hartman
maintainerPATCH 188/1067 usbip: tools: support SuperSpeedPlus devices
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
commit 195e667c8719480c320cd48ac0fbf1cb81d6ffe0 upstream.
USB devices running at SuperSpeedPlus report "10000" or "20000" in their sysfs speed attribute. usbip currently maps only "5000" to USB_SPEED_SUPER, so a SuperSpeedPlus device is imported as USB_SPEED_UNKNOWN.
The attach request is then rejected by vhci_hcd:
vhci_hcd: Failed attach request for unsupported USB speed: UNKNOWN
Map the SuperSpeedPlus sysfs speed values to USB_SPEED_SUPER_PLUS, use the SuperSpeed VHCI hub for SuperSpeedPlus devices, and recognize the gadget current_speed string used by the kernel.
--- tools/usb/usbip/libsrc/usbip_common.c | 2 ++ tools/usb/usbip/libsrc/usbip_device_driver.c | 4 ++++ tools/usb/usbip/libsrc/vhci_driver.c | 1 + 3 files changed, 7 insertions(+)
tools/usb/usbip/libsrc/usbip_common.c +2 -0
@@ -29,6 +29,8 @@ static const struct speed_string speed_s { USB_SPEED_HIGH, "480", "High Speed(480Mbps)" }, { USB_SPEED_WIRELESS, "53.3-480", "Wireless"}, { USB_SPEED_SUPER, "5000", "Super Speed(5000Mbps)" }, + { USB_SPEED_SUPER_PLUS, "10000", "Super Speed Plus(10000Mbps)" }, + { USB_SPEED_SUPER_PLUS, "20000", "Super Speed Plus(20000Mbps)" }, { 0, NULL, NULL } };
tools/usb/usbip/libsrc/usbip_device_driver.c +4 -0
@@ -57,6 +57,10 @@ static struct { .speed = USB_SPEED_SUPER, .name = "super-speed", }, + { + .speed = USB_SPEED_SUPER_PLUS, + .name = "super-speed-plus", + }, }; static
tools/usb/usbip/libsrc/vhci_driver.c +1 -0
@@ -338,6 +338,7 @@ int usbip_vhci_get_free_port(uint32_t spswitch (speed) {case USB_SPEED_SUPER : +case USB_SPEED_SUPER_PLUS :if (vhci_driver->idev[i].hub !=HUB_SPEED_SUPER )continue ;break ;
Greg Kroah-Hartman
maintainerPATCH 189/1067 usbip: vudc: fix NULL deref in vep_dequeue()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sam Day <[email protected]>
commit c5371e0b91b24159a3ebaa61e70b0980bcf03c0a upstream.
vep_alloc_request() wasn't initializing vrequest->udc, so cancellations on the FunctionFS AIO path were arriving in vep_dequeue without a valid UDC reference.
Since vrequest->udc is never actually properly used anywhere, we opt to remove it, and update vep_dequeue to obtain a reference to the udc with ep_to_vudc(), consistent with the other vep_ ops.
AFAICT this bug has existed for ~10 years. Seems that nobody has really stressed the FunctionFS AIO path on usbip's vudc.
I tested this fix in a QEMU aarch64 guest driving FunctionFS endpoints via AIO. Before the fix, running usbip attach from the host would cause the guest to oops with the following backtrace:
Call trace: vep_dequeue+0x1c/0xe4 (P) usb_ep_dequeue+0x14/0x20 ffs_aio_cancel+0x24/0x34 __arm64_sys_io_cancel+0xb0/0x124 do_el0_svc+0x68/0x100 el0_svc+0x18/0x5c el0t_64_sync_handler+0x98/0xdc el0t_64_sync+0x154/0x158
--- drivers/usb/usbip/vudc.h | 1 - drivers/usb/usbip/vudc_dev.c | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/usb/usbip/vudc.h +0 -1
@@ -38,7 +38,6 @@ struct vep {struct vrequest {struct usb_request req; -struct vudc *udc;struct list_head req_entry;/* Request queue */ };
drivers/usb/usbip/vudc_dev.c +1 -3
@@ -333,7 +333,6 @@ static int vep_queue(struct usb_ep *_ep,static int vep_dequeue (struct usb_ep *_ep,struct usb_request *_req) {struct vep *ep; -struct vrequest *req;struct vudc *udc;struct vrequest *lst;unsigned long flags;
@@ -343,8 +342,7 @@ static int vep_dequeue(struct usb_ep *_ereturn ret; ep =to_vep (_ep); - req =to_vrequest (_req); - udc = req->udc; + udc =ep_to_vudc (ep);if (!udc->driver)return -ESHUTDOWN ;
Greg Kroah-Hartman
maintainerPATCH 190/1067 usb: typec: anx7411: use devm_pm_runtime_enable()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 0ef7cc27da8b9e315a4a5a665c68c44206f5e559 upstream.
anx7411_i2c_probe() enables runtime PM before returning successfully, but anx7411_i2c_remove() tears down the Type-C partner state, workqueue, dummy I2C device, mux, switch and port without disabling runtime PM.
Use devm_pm_runtime_enable() so runtime PM is disabled automatically on driver detach. Since devres action registration can fail, route that failure through the existing probe unwind path.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/usb/typec/anx7411.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/typec/anx7411.c +3 -1
@@ -1543,7 +1543,9 @@ static int anx7411_i2c_probe(struct i2c_if (anx7411_typec_check_connection (plat))dev_err (dev,"check status\n" ); -pm_runtime_enable (dev); + ret =devm_pm_runtime_enable (dev); +if (ret) + goto free_wq;return 0 ;
Greg Kroah-Hartman
maintainerPATCH 150/1067 cpufreq: Fix hotplug-suspend race during reboot
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianxiang Chen <[email protected]>
commit a9029dd55696c651ee46912afa2a166fa456bb3e upstream.
During system reboot, cpufreq_suspend() is called via the kernel_restart() -> device_shutdown() path. Unlike the normal system suspend path, the reboot path does not call freeze_processes(), so userspace processes and kernel threads remain active.
This allows CPU hotplug operations to run concurrently with cpufreq_suspend(). The original code has no synchronization with CPU hotplug, leading to a race condition where governor_data can be freed by the hotplug path while cpufreq_suspend() is still accessing it, resulting in a null pointer dereference:
Unable to handle kernel NULL pointer dereference Call Trace: do_kernel_fault+0x28/0x3c cpufreq_suspend+0xdc/0x160 device_shutdown+0x18/0x200 kernel_restart+0x40/0x80 arm64_sys_reboot+0x1b0/0x200
Fix this by adding cpus_read_lock()/cpus_read_unlock() to cpufreq_suspend() to block CPU hotplug operations while suspend is in progress.
--- drivers/cpufreq/cpufreq.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/cpufreq/cpufreq.c +2 -0
@@ -1918,6 +1918,7 @@ void cpufreq_suspend(void)if (!cpufreq_driver)return ; +cpus_read_lock ();if (!has_target () && !cpufreq_driver->suspend) goto suspend;
@@ -1937,6 +1938,7 @@ void cpufreq_suspend(void) suspend: cpufreq_suspended = true; +cpus_read_unlock (); }/**
Greg Kroah-Hartman
maintainerPATCH 151/1067 cpufreq: pcc: fix use-after-free and double free in _OSC evaluation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
commit 266d3dd8b757b48a576e90f018b51f7b7563cc32 upstream.
pcc_cpufreq_do_osc() calls acpi_evaluate_object() twice for the two-phase _OSC negotiation. Between the two calls it freed output.pointer but left output.length unchanged. Since acpi_evaluate_object() treats a non-zero length with a non-NULL pointer as an existing buffer to write into, the second call wrote into freed memory (use-after-free). The subsequent kfree(output.pointer) at out_free then freed the same pointer a second time (double free).
Reset output.pointer to NULL and output.length to ACPI_ALLOCATE_BUFFER after freeing the first result, so ACPICA allocates a fresh buffer for each phase independently.
--- drivers/cpufreq/pcc-cpufreq.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/cpufreq/pcc-cpufreq.c +2 -0
@@ -351,6 +351,8 @@ static int __init pcc_cpufreq_do_osc(acp }kfree (output.pointer); + output.pointer =NULL ; + output.length =ACPI_ALLOCATE_BUFFER ; capabilities[0 ] =0x0 ; capabilities[1 ] =0x1 ;
Greg Kroah-Hartman
maintainerPATCH 152/1067 posix-cpu-timers: Fix pid refcount leak in do_cpu_nanosleep() error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: WenTao Liang <[email protected]>
commit 87bd2ad568e15b90d5f7d4bcd70342d05dad649c upstream.
In do_cpu_nanosleep(), posix_cpu_timer_create() takes a pid reference via get_pid() and stores it in timer.it.cpu.pid. If the subsequent posix_cpu_timer_set() call fails, the function returns immediately without calling posix_cpu_timer_del() to release the pid reference, causing a leak.
Fix it by calling posix_cpu_timer_del() before the unlock-and-return on the error path, consistent with the other exit paths in the same function.
--- kernel/time/posix-cpu-timers.c | 1 + 1 file changed, 1 insertion(+)
kernel/time/posix-cpu-timers.c +1 -0
@@ -1536,6 +1536,7 @@ static int do_cpu_nanosleep(const clockispin_lock_irq (&timer.it_lock); error =posix_cpu_timer_set (&timer, flags, &it,NULL );if (error) { +posix_cpu_timer_del (&timer);spin_unlock_irq (&timer.it_lock);return error; }
Greg Kroah-Hartman
maintainerPATCH 153/1067 clocksource/drivers/timer-tegra186: Fix support for multiple watchdog instances
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kartik Rajput <[email protected]>
commit ca57bf46e7a94f8c53d05c376df9fcfdcb482100 upstream.
Tegra SoCs support multiple watchdogs; currently only one (WDT0) is used. When multiple watchdogs are registered, tegra186_wdt_enable() overwrites the TKEIE(x) register, discarding any existing watchdog interrupt enable bits. As a result, enabling one watchdog inadvertently disables interrupts for the others.
Fix this by preserving the existing TKEIE(x) value and updating it using a read-modify-write sequence.
--- drivers/clocksource/timer-tegra186.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clocksource/timer-tegra186.c +2 -1
@@ -145,7 +145,8 @@ static void tegra186_wdt_enable(struct tu32 value;/* unmask hardware IRQ, this may have been lost across powergate */ - value =TKEIE_WDT_MASK (wdt->index,1 ); + value =readl (tegra->regs +TKEIE (wdt->tmr->hwirq)); + value |=TKEIE_WDT_MASK (wdt->index,1 );writel (value, tegra->regs +TKEIE (wdt->tmr->hwirq));/* clear interrupt */
Greg Kroah-Hartman
maintainerPATCH 154/1067 X.509: Fix validation of ASN.1 certificate header
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
commit 3b626ba431c4501512ad07549310685e07fe4706 upstream.
x509_load_certificate_list() seeks to enforce that a certificate starts with 0x30 0x82 (ASN.1 SEQUENCE tag followed by a length of more than 256 and less than 65535 bytes).
But it only enforces that *either* of those two byte values are present, instead of checking for the *conjunction* of the two values. Fix it.
--- crypto/asymmetric_keys/x509_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/asymmetric_keys/x509_loader.c +1 -1
@@ -20,7 +20,7 @@ int x509_load_certificate_list(const u8*/ if (end - p <4 ) goto dodgy_cert; -if (p[0 ] !=0x30 && +if (p[0 ] !=0x30 || p[1 ] !=0x82 ) goto dodgy_cert; plen = (p[2 ] <<8 ) | p[3 ];
Greg Kroah-Hartman
maintainerPATCH 145/1067 smb: client: harden POSIX SID length parsing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit 7ad2bcf2441430bb2e918fb3ef9a90d775a6e422 upstream.
posix_info_sid_size() reads sid[1] to obtain the subauthority count, but its existing boundary check still accepts buffers with only one remaining byte. Require two bytes before reading sid[1] so all client paths that reuse the helper reject truncated POSIX SIDs safely.
--- fs/smb/client/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2pdu.c +1 -1
@@ -4857,7 +4857,7 @@ int posix_info_sid_size(const void *beg,size_t subauth;int total; -if (beg +1 > end) +if (beg +2 > end)return -1 ; subauth = *(u8 *)(beg+1 );
Greg Kroah-Hartman
maintainerPATCH 192/1067 usb: typec: tcpm: Validate SVID index in svdm_consume_modes()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Badhri Jagan Sridharan <[email protected]>
commit 7b681dd5fbf60b24a13c14661e5b7735759fb491 upstream.
In svdm_consume_modes(), the SVID value is read from pmdata->svids using pmdata->svid_index as an array index without bounds validation:
paltmode->svid = pmdata->svids[pmdata->svid_index];
If pmdata->svid_index is driven beyond SVID_DISCOVERY_MAX (16), it results in an out-of-bounds read of the pmdata->svids array. Because pd_mode_data is embedded inside struct tcpm_port, indexing past svids reads into adjacent fields. In particular:
- At index 16, it reads the altmodes count.
- At index 18 and beyond, it reads into altmode_desc[], which contains partner-supplied SVDM Discovery Modes VDOs.
By injecting a chosen SVID into altmode_desc[0].vdo and driving svid_index to 20, the partner can force paltmode->svid to be loaded with an arbitrary, partner- chosen SVID, which is then registered via typec_partner_register_altmode().
Fix this by validating that pmdata->svid_index is non-negative and strictly less than pmdata->nsvids before accessing the pmdata->svids array inside svdm_consume_modes().
--- drivers/usb/typec/tcpm/tcpm.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +5 -0
@@ -1546,6 +1546,11 @@ static void svdm_consume_modes(struct tcreturn ; } +if (pmdata->svid_index <0 || pmdata->svid_index >= pmdata->nsvids) { +tcpm_log (port,"Invalid SVID index %d" , pmdata->svid_index); +return ; + } +for (i =1 ; i < cnt; i++) { paltmode = &pmdata->altmode_desc[pmdata->altmodes];memset (paltmode,0 ,sizeof (*paltmode));
Greg Kroah-Hartman
maintainerPATCH 201/1067 udf: validate VAT header length against the VAT inode size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit d8202786b3d75125c84ebc4de6d946f92fde0ee8 upstream.
udf_load_vat() takes the virtual partition's start offset straight from the on-disk VAT 2.0 header without checking it against the VAT inode size:
map->s_type_specific.s_virtual.s_start_offset = le16_to_cpu(vat20->lengthHeader); map->s_type_specific.s_virtual.s_num_entries = (sbi->s_vat_inode->i_size - map->s_type_specific.s_virtual.s_start_offset) >> 2;
lengthHeader is a fully attacker-controlled 16-bit value. If it exceeds the VAT inode size, the s_num_entries subtraction underflows to a huge count, which defeats the "block > s_num_entries" bound in udf_get_pblock_virt15(); and on the ICB-inline path that function reads
((__le32 *)(iinfo->i_data + s_start_offset))[block]
so a large s_start_offset indexes past the inode's in-ICB data. Mounting a crafted UDF image with a virtual (VAT) partition then triggers an out-of-bounds read.
Reject a VAT whose header length does not leave room for at least one entry within the VAT inode.
--- fs/udf/super.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/udf/super.c +8 -0
@@ -1233,6 +1233,14 @@ static int udf_load_vat(struct super_blo map->s_type_specific.s_virtual.s_start_offset =le16_to_cpu (vat20->lengthHeader); +if (map->s_type_specific.s_virtual.s_start_offset + > sbi->s_vat_inode->i_size) { +udf_err (sb,"Corrupted VAT header length %u (VAT inode size %lld)\n" , + map->s_type_specific.s_virtual.s_start_offset, + sbi->s_vat_inode->i_size); +brelse (bh); +return -EFSCORRUPTED ; + } map->s_type_specific.s_virtual.s_num_entries = (sbi->s_vat_inode->i_size - map->s_type_specific.s_virtual.
Greg Kroah-Hartman
maintainerPATCH 202/1067 udf: validate sparing table length as an entry count, not a byte count
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 3ec997bd5508e9b25210b5bbec89031629cdb093 upstream.
udf_load_sparable_map() accepts a sparing table when
sizeof(*st) + le16_to_cpu(st->reallocationTableLen) > sb->s_blocksize
is false, i.e. it treats reallocationTableLen as a number of BYTES that must fit in the block. But the table is walked as an array of 8-byte sparingEntry elements:
for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) {
struct sparingEntry *entry = &st->mapEntry[i];
... entry->origLocation ...
}in udf_get_pblock_spar15() and udf_relocate_blocks(). A reallocationTableLen of N therefore passes the check whenever sizeof(*st) + N <= blocksize, yet the consumers index sizeof(*st) + N * sizeof(struct sparingEntry) bytes -- up to ~8x the block. On a crafted UDF image this is an out-of-bounds read in udf_get_pblock_spar15(); udf_relocate_blocks() additionally feeds the same length to udf_update_tag(), whose crc_itu_t() reads far past the block, and its memmove() through st->mapEntry[] is an out-of-bounds write.
Validate reallocationTableLen as the entry count it is, with struct_size().
--- fs/udf/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/udf/super.c +2 -1
@@ -1396,7 +1396,8 @@ static int udf_load_sparable_map(structif (ident !=0 ||strncmp (st->sparingIdent.ident,UDF_ID_SPARING ,strlen (UDF_ID_SPARING )) || -sizeof (*st) +le16_to_cpu (st->reallocationTableLen) > +struct_size (st, mapEntry, +le16_to_cpu (st->reallocationTableLen)) > sb->s_blocksize) {brelse (bh);continue ;
Greg Kroah-Hartman
maintainerPATCH 203/1067 dm-ioctl: report an error if a device has no table
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 457e32348d606a77f9b20e25e989734189834c07 upstream.
When we send a message to a device that has no table, the return code was not set. The code would return "2", which is not considered a valid return value.
--- drivers/md/dm-ioctl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/md/dm-ioctl.c +4 -1
@@ -1742,8 +1742,11 @@ static int target_message(struct file *f goto out_argv; table =dm_get_live_table (md, &srcu_idx); -if (!table) +if (!table) { +DMERR ("The device has no table." ); + r = -EINVAL ; goto out_table; + }if (dm_deleting_md (md)) { r = -ENXIO ;
Greg Kroah-Hartman
maintainerPATCH 204/1067 nvme-multipath: set BIO_REMAPPED on bios remapped to per-path namespace disks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Achkinazi, Igor <[email protected]>
commit 88bac2c1a72b8f4f71e9845699aa872df04e5850 upstream.
When nvme_ns_head_submit_bio() remaps a bio from the multipath head to a per-path namespace, bio_set_dev() clears BIO_REMAPPED. The remapped bio is then resubmitted through submit_bio_noacct() which calls bio_check_eod() because BIO_REMAPPED is not set.
This races with nvme_ns_remove() which zeroes the per-path capacity before synchronize_srcu():
CPU 0 (IO submission)
---------------------
srcu_read_lock()
nvme_find_path() -> ns
[NVME_NS_READY is set]
CPU 1 (namespace removal)
-------------------------
clear_bit(NVME_NS_READY)
set_capacity(ns->disk, 0)
synchronize_srcu() <- blocks
CPU 0 (IO submission)
---------------------
bio_set_dev(bio, ns->disk->part0)
[clears BIO_REMAPPED]
submit_bio_noacct(bio)
-> bio_check_eod() sees capacity=0
-> bio fails with IO errorThe SRCU read lock prevents synchronize_srcu() from completing, but does not prevent set_capacity(0) from executing. The bio fails the EOD check before it reaches the NVMe driver, so nvme_failover_req() never gets a chance to redirect it to another path of multipath. IO errors are reported to the application despite another path being available.
On older kernels (before commit 0b64682e78f7 "block: skip unnecessary checks for split bio"), the same race was also reachable through split remainders resubmitted via submit_bio_noacct().
Fix this by setting BIO_REMAPPED after bio_set_dev() in nvme_ns_head_submit_bio(). This skips bio_check_eod() on the per-path device; the EOD check already passed on the multipath head.
NVMe per-path namespace devices are always whole disks (bd_partno=0), so the blk_partition_remap() skip also gated by BIO_REMAPPED is a no-op. The flag does not persist across failover and cannot go stale if the namespace geometry changes between attempts: nvme_failover_req() calls bio_set_dev() to redirect the bio back to the multipath head, which clears BIO_REMAPPED. When nvme_requeue_work() resubmits through submit_bio_noacct(), bio_check_eod() runs normally against the current capacity.
Same approach as commit 3a905c37c351 ("block: skip bio_check_eod for partition-remapped bios").
--- drivers/nvme/host/multipath.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/nvme/host/multipath.c +6 -0
@@ -359,6 +359,12 @@ static void nvme_ns_head_submit_bio(stru ns =nvme_find_path (head);if (likely (ns)) {bio_set_dev (bio, ns->disk->part0); +/* +* Use BIO_REMAPPED to skip bio_check_eod() when this bio +* enters submit_bio_noacct() for the per-path device. The EOD +* check already passed on the multipath head. +*/ +bio_set_flag (bio,BIO_REMAPPED ); bio->bi_opf |=REQ_NVME_MPATH ;trace_block_bio_remap (bio,disk_devt (ns->head->disk), bio->bi_iter.bi_sector);
Greg Kroah-Hartman
maintainerPATCH 205/1067 btrfs: do not trim a device which is not writeable
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 1b1937eb08f51319bf71575484cde2b8c517aedc upstream.
[BUG]
There is a bug report that btrfs/242 can randomly fail with the following NULL pointer dereference:
run fstests btrfs/242 at 2026-06-01 10:25:08
BTRFS: device fsid d4d7f234-487c-4787-88e4-47a8b68c9874 devid 1 transid 9 /dev/sdc (8:32) scanned by mount (122609) BTRFS info (device sdc): first mount of filesystem d4d7f234-487c-4787-88e4-47a8b68c9874
BTRFS info (device sdc): using crc32c checksum algorithm
BTRFS warning (device sdc): devid 2 uuid fbe72d72-3272-482d-80fb-ab88ed398192 is missing
BTRFS warning (device sdc): devid 2 uuid fbe72d72-3272-482d-80fb-ab88ed398192 is missing
BTRFS info (device sdc): allowing degraded mounts
BTRFS info (device sdc): turning on async discard
BTRFS info (device sdc): enabling free space tree
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018 user pgtable: 4k pages, 48-bit VAs, pgdp=000000013fd6b000 CPU: 4 UID: 0 PID: 122625 Comm: fstrim Not tainted 7.0.10-2-default #1 PREEMPT(full) openSUSE Tumbleweed e9a5f6b24978fba3bf015a992f865837fdfff3dd Hardware name: QEMU KVM Virtual Machine, BIOS edk2-20250812-19.fc42 08/12/2025 pstate: 01400005 (nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) pc : btrfs_trim_fs+0x34c/0xa00 [btrfs] lr : btrfs_trim_fs+0x1f0/0xa00 [btrfs] Call trace: btrfs_trim_fs+0x34c/0xa00 [btrfs f02c1d570ceea621c69d302ba75dd61868083840] (P) btrfs_ioctl_fitrim+0xe8/0x178 [btrfs f02c1d570ceea621c69d302ba75dd61868083840] btrfs_ioctl+0xdd4/0x2bd8 [btrfs f02c1d570ceea621c69d302ba75dd61868083840] __arm64_sys_ioctl+0xac/0x108 invoke_syscall.constprop.0+0x5c/0xd0 el0_svc_common.constprop.0+0x40/0xf0 do_el0_svc+0x24/0x40 el0_svc+0x40/0x1d0 el0t_64_sync_handler+0xa0/0xe8 el0t_64_sync+0x1b0/0x1b8 Code: 17ffff83 f94017e0 f9002be0 f9402ea0 (f9400c00) ---[ end trace 0000000000000000 ]---
Also the reporter is very kind to test the following ASSERT() added to btrfs_trim_free_extents_throttle():
ASSERT(device->bdev, "devid=%llu path=%s dev_state=0x%lx\n", device->devid, btrfs_dev_name(device), device->dev_state);
And it shows the following output:
assertion failed: device->bdev, in extent-tree.c:6630 (devid=2 path=/dev/sdd dev_state=0x82)
Which means the device->bdev is NULL, and the dev_state is BTRFS_DEV_STATE_IN_FS_METADATA | BTRFS_DEV_STATE_ITEM_FOUND, without BTRFS_DEV_STATE_WRITEABLE flag set.
[CAUSE]
The pc points to the following call chain:
btrfs_trim_fs()
|- btrfs_trim_free_extents()
|- btrfs_trim_free_extents_throttle()
|- bdev_max_discard_sectors(device->bdev)So the NULL pointer dereference is caused by device->bdev being NULL.
This looks impossible by a quick glance, as just before calling btrfs_trim_free_extents_throttle(), we have skipped any device that has BTRFS_DEV_STATE_MISSING flag set.
However in this particular case, there is a window where the missing device is later re-scanned, causing btrfs to remove the BTRFS_DEV_STATE_MISSING flag:
btrfs_control_ioctl()
|- btrfs_scan_one_device()
|- device_list_add()
|- rcu_assign_pointer(device->name, name);
| This updates the missing device's path to the new good path.
|
|- clear_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)
This removes the BTRFS_DEV_STATE_MISSING flag.This allows the missing device to re-appear and clear the BTRFS_DEV_STATE_MISSING flag. However the device still does not have the BTRFS_DEV_STATE_WRITEABLE flag set, nor is its bdev pointer updated.
The bdev pointer remains NULL, triggering the crash later.
[FIX]
This is a big de-synchronization between BTRFS_DEV_STATE_MISSING and device->bdev pointer, and shows a gap in btrfs's re-appearing-device handling.
The proper handling of re-appearing device will need quite some extra work, which is out of the context of this small fix.
Thankfully the regular bbio submission path has already handled it well by checking if the device->bdev is NULL before submitting.
So here we just fix the crash by checking if the device is writeable and has a bdev pointer before calling bdev_max_discard_sectors().
--- fs/btrfs/extent-tree.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/btrfs/extent-tree.c +8 -4
@@ -6117,12 +6117,16 @@ static int btrfs_trim_free_extents(struc *trimmed =0 ; -/* Discard not supported = nothing to do. */ -if (!bdev_max_discard_sectors (device->bdev)) +/* +* The caller only filters out MISSING devices, but a device that was +* missing at mount and later rescanned has MISSING cleared while bdev +* is still NULL and WRITEABLE is still unset. Skip those here. +*/ +if (!test_bit (BTRFS_DEV_STATE_WRITEABLE , &device->dev_state) || !device->bdev)return 0 ; -/* Not writable = nothing to do. */ -if (!test_bit (BTRFS_DEV_STATE_WRITEABLE , &device->dev_state)) +/* Discard not supported = nothing to do. */ +if (!bdev_max_discard_sectors (device->bdev))return 0 ;/* No free space = nothing to do. */
Greg Kroah-Hartman
maintainerPATCH 206/1067 partitions: aix: bound the pp_count scan to the ppe array
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 2dc0bfd2fe355fb930de63c2f2eb8ced8570c579 upstream.
aix_partition() reads the physical volume descriptor into a fixed-size struct pvd and then scans its physical-partition-extent array:
int numpps = be16_to_cpu(pvd->pp_count);
...
for (i = 0; i < numpps; i += 1) {
struct ppe *p = pvd->ppe + i;
...
lp_ix = be16_to_cpu(p->lp_ix);pvd points at a single kmalloc()'d struct pvd whose ppe[] member holds a fixed ARRAY_SIZE(pvd->ppe) (1016) entries, but the loop runs up to the on-disk pp_count. pp_count is an unvalidated __be16 read straight from the descriptor, so a crafted AIX image with pp_count larger than 1016 drives the loop to read pvd->ppe[i] past the end of the allocation (up to 65535 entries, ~2 MB out of bounds).
The partition scan runs without mounting anything, when a block device with a crafted AIX/IBM partition table appears (an attacker-supplied image attached with losetup -P, or a device auto-scanned by udev), via msdos_partition() -> aix_partition().
Clamp the scan to the number of entries the ppe[] array can hold.
--- block/partitions/aix.c | 9 +++++++++ 1 file changed, 9 insertions(+)
block/partitions/aix.c +9 -0
@@ -228,6 +228,15 @@ int aix_partition(struct parsed_partitioint next_lp_ix =1 ;int lp_ix; +/* +* pvd was read into a fixed-size struct pvd whose ppe[] array +* holds ARRAY_SIZE(pvd->ppe) entries. pp_count is an +* unvalidated on-disk __be16, so clamp the scan to the array +* size to avoid walking past the allocation. +*/ +if (numpps >ARRAY_SIZE (pvd->ppe)) + numpps =ARRAY_SIZE (pvd->ppe); +for (i =0 ; i < numpps; i +=1 ) {struct ppe *p = pvd->ppe + i;unsigned int lv_ix;
Greg Kroah-Hartman
maintainerPATCH 207/1067 isofs: bound Rock Ridge symlink components to the SL record
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 5fa1d6a5ec2356d2107dead614437c66fa7138b1 upstream.
get_symlink_chunk() and the SL handling in parse_rock_ridge_inode_internal() walk the variable-length components of a Rock Ridge "SL" (symbolic link) record. Each component is a two-byte header (flags, len) followed by len bytes of text, so it occupies slp->len + 2 bytes. Both loops read slp->len and advance to the next component, and get_symlink_chunk() additionally does memcpy(rpnt, slp->text, slp->len), but neither checks that the component lies within the SL record before dereferencing it.
A crafted SL record whose component declares a len that runs past the record (rr->len) therefore triggers an out-of-bounds read of up to 255 bytes. When the record sits at the tail of its backing buffer - for example a small kmalloc()ed continuation block reached through a CE record - the read crosses the allocation; get_symlink_chunk() then copies the out-of-bounds bytes into the symlink body returned to user space by readlink(), disclosing adjacent kernel memory.
ISO 9660 images are routinely mounted from untrusted removable media - desktop environments auto-mount them (e.g. via udisks2) without CAP_SYS_ADMIN - so the record contents are attacker-controlled.
Reject any component that does not fit in the remaining record bytes before using it. In get_symlink_chunk() return NULL, like the existing output-buffer (plimit) checks, so a malformed record makes readlink() fail with -EIO rather than silently returning a truncated target; in parse_rock_ridge_inode_internal() stop the inode-size walk.
--- fs/isofs/rock.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/isofs/rock.c +11 -0
@@ -464,6 +464,9 @@ repeat: inode->i_size = symlink_len;while (slen >1 ) { rootflag =0 ; +/* keep the component within the SL record */ +if (slp->len +2 > slen) + goto eio;switch (slp->flags & ~1 ) {case 0 : inode->i_size +=
@@ -619,6 +622,14 @@ static char *get_symlink_chunk(char *rpn slp = &rr->u.SL.link;while (slen >1 ) { rootflag =0 ; +/* +* A component is slp->len + 2 bytes (a two-byte header plus +* len bytes of text). If it does not fit in the bytes left in +* the SL record the record is malformed: fail like the plimit +* checks below so readlink() returns -EIO, not a truncated path. +*/ +if (slp->len +2 > slen) +return NULL ;switch (slp->flags & ~1 ) {case 0 :if (slp->len > plimit - rpnt)
Greg Kroah-Hartman
maintainerPATCH 208/1067 crypto: caam - use print_hex_dump_devel to guard key hex dumps
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit 3f57657b6ea23f933371f2c2846322f441773cee upstream.
Use print_hex_dump_devel() for dumping sensitive key material in *_setkey() and gen_split_key() to avoid leaking secrets at runtime when CONFIG_DYNAMIC_DEBUG is enabled.
--- drivers/crypto/caam/caamalg.c | 12 ++++++------ drivers/crypto/caam/caamalg_qi.c | 12 ++++++------ drivers/crypto/caam/caamhash.c | 4 ++-- drivers/crypto/caam/key_gen.c | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-)
drivers/crypto/caam/caamalg.c +6 -6
@@ -588,7 +588,7 @@ static int aead_setkey(struct crypto_aeadev_dbg (jrdev,"keylen %d enckeylen %d authkeylen %d\n" , keys.authkeylen + keys.enckeylen, keys.enckeylen, keys.authkeylen); - print_hex_dump_debug("key in @"__stringify(__LINE__)": ", + print_hex_dump_devel("key in @"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );/*
@@ -624,7 +624,7 @@ static int aead_setkey(struct crypto_aeadma_sync_single_for_device (jrdev, ctx->key_dma, ctx->adata.keylen_pad + keys.enckeylen, ctx->dir); - print_hex_dump_debug("ctx.key@"__stringify(__LINE__)": ", + print_hex_dump_devel("ctx.key@"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , ctx->key, ctx->adata.keylen_pad + keys.enckeylen,1 );
@@ -665,7 +665,7 @@ static int gcm_setkey(struct crypto_aeadif (err)return err; - print_hex_dump_debug("key in @"__stringify(__LINE__)": ", + print_hex_dump_devel("key in @"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -686,7 +686,7 @@ static int rfc4106_setkey(struct crypto_if (err)return err; - print_hex_dump_debug("key in @"__stringify(__LINE__)": ", + print_hex_dump_devel("key in @"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -712,7 +712,7 @@ static int rfc4543_setkey(struct crypto_if (err)return err; - print_hex_dump_debug("key in @"__stringify(__LINE__)": ", + print_hex_dump_devel("key in @"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -739,7 +739,7 @@ static int skcipher_setkey(struct cryptou32 *desc;const bool is_rfc3686 = alg->caam.rfc3686; - print_hex_dump_debug("key in @"__stringify(__LINE__)": ", + print_hex_dump_devel("key in @"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 ); ctx->cdata.keylen = keylen;
drivers/crypto/caam/caamalg_qi.c +6 -6
@@ -207,7 +207,7 @@ static int aead_setkey(struct crypto_aeadev_dbg (jrdev,"keylen %d enckeylen %d authkeylen %d\n" , keys.authkeylen + keys.enckeylen, keys.enckeylen, keys.authkeylen); - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );/*
@@ -243,7 +243,7 @@ static int aead_setkey(struct crypto_aea ctx->adata.keylen_pad + keys.enckeylen, ctx->dir); - print_hex_dump_debug("ctx.key@" __stringify(__LINE__)": ", + print_hex_dump_devel("ctx.key@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , ctx->key, ctx->adata.keylen_pad + keys.enckeylen,1 );
@@ -366,7 +366,7 @@ static int gcm_setkey(struct crypto_aeadif (ret)return ret; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -470,7 +470,7 @@ static int rfc4106_setkey(struct crypto_if (ret)return ret; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -576,7 +576,7 @@ static int rfc4543_setkey(struct crypto_if (ret)return ret; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -626,7 +626,7 @@ static int skcipher_setkey(struct cryptoconst bool is_rfc3686 = alg->caam.rfc3686;int ret =0 ; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 ); ctx->cdata.keylen = keylen;
drivers/crypto/caam/caamhash.c +2 -2
@@ -495,7 +495,7 @@ static int axcbc_setkey(struct crypto_ah DMA_TO_DEVICE); ctx->adata.keylen = keylen; - print_hex_dump_debug("axcbc ctx.key@" __stringify(__LINE__)" : ", + print_hex_dump_devel("axcbc ctx.key@" __stringify(__LINE__)" : ",DUMP_PREFIX_ADDRESS ,16 ,4 , ctx->key, keylen,1 );return axcbc_set_sh_desc (ahash);
@@ -515,7 +515,7 @@ static int acmac_setkey(struct crypto_ah ctx->adata.key_virt = key; ctx->adata.keylen = keylen; - print_hex_dump_debug("acmac ctx.key@" __stringify(__LINE__)" : ", + print_hex_dump_devel("acmac ctx.key@" __stringify(__LINE__)" : ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );return acmac_set_sh_desc (ahash);
drivers/crypto/caam/key_gen.c +2 -2
@@ -58,7 +58,7 @@ int gen_split_key(struct device *jrdev,dev_dbg (jrdev,"split keylen %d split keylen padded %d\n" , adata->keylen, adata->keylen_pad); - print_hex_dump_debug("ctx.key@" __stringify(__LINE__)": ", + print_hex_dump_devel("ctx.key@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key_in, keylen,1 );if (local_max > max_keylen)
@@ -113,7 +113,7 @@ int gen_split_key(struct device *jrdev,wait_for_completion (&result.completion); ret = result.err; - print_hex_dump_debug("ctx.key@"__stringify(__LINE__)": ", + print_hex_dump_devel("ctx.key@"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key_out, adata->keylen_pad,1 ); }
Greg Kroah-Hartman
maintainerPATCH 209/1067 crypto: caam - use print_hex_dump_devel to guard key hex dumps again
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit 8005dc808bcce7d6cc2ae015a3cde1683bee602d upstream.
Use print_hex_dump_devel() for dumping sensitive key material in *_setkey() to avoid leaking secrets at runtime when CONFIG_DYNAMIC_DEBUG is enabled.
--- drivers/crypto/caam/caamalg_qi2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/crypto/caam/caamalg_qi2.c +6 -6
@@ -297,7 +297,7 @@ static int aead_setkey(struct crypto_aeadev_dbg (dev,"keylen %d enckeylen %d authkeylen %d\n" , keys.authkeylen + keys.enckeylen, keys.enckeylen, keys.authkeylen); - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 ); ctx->adata.keylen = keys.authkeylen;
@@ -311,7 +311,7 @@ static int aead_setkey(struct crypto_aeamemcpy (ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);dma_sync_single_for_device (dev, ctx->key_dma, ctx->adata.keylen_pad + keys.enckeylen, ctx->dir); - print_hex_dump_debug("ctx.key@" __stringify(__LINE__)": ", + print_hex_dump_devel("ctx.key@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , ctx->key, ctx->adata.keylen_pad + keys.enckeylen,1 );
@@ -728,7 +728,7 @@ static int gcm_setkey(struct crypto_aead ret =aes_check_keylen (keylen);if (ret)return ret; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -824,7 +824,7 @@ static int rfc4106_setkey(struct crypto_if (ret)return ret; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -923,7 +923,7 @@ static int rfc4543_setkey(struct crypto_if (ret)return ret; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 );memcpy (ctx->key, key, keylen);
@@ -951,7 +951,7 @@ static int skcipher_setkey(struct cryptou32 *desc;const bool is_rfc3686 = alg->caam.rfc3686; - print_hex_dump_debug("key in @" __stringify(__LINE__)": ", + print_hex_dump_devel("key in @" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, keylen,1 ); ctx->cdata.keylen = keylen;
Greg Kroah-Hartman
maintainerPATCH 210/1067 crypto: ecc - Fix carry overflow in vli multiplication
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anastasia Tishchenko <[email protected]>
commit 27b536a2ec8e2f85a0380c2d13c9ecbc7aaab406 upstream.
The carry flag calculation fails when r01.m_high is saturated (0xFFFFFFFFFFFFFFFF) and addition of lower bits overflows.
The condition (r01.m_high < product.m_high) doesn't handle the case where r01.m_high == product.m_high and an additional carry exists from lower-bit overflow.
When commit 3c4b23901a0c ("crypto: ecdh - Add ECDH software support") introduced crypto/ecc.c, it split the muladd() function in the micro-ecc library into separate mul_64_64() and add_128_128() helpers. It seems the check got lost in translation.
Add proper handling for this boundary by accounting for the carry from the lower addition.
--- crypto/ecc.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
crypto/ecc.c +20 -11
@@ -378,14 +378,26 @@ static uint128_t mul_64_64(u64 left, u64return result; } -static uint128_t add_128_128 (uint128_t a,uint128_t b) +/* Calculate addition with overflow checking. Returns true on wrap-around, +* false otherwise. +*/ +static bool check_add_128_128_overflow (uint128_t *result,uint128_t a, +uint128_t b) { -uint128_t result; +bool carry; - result.m_low = a.m_low + b.m_low; - result.m_high = a.m_high + b.m_high + (result.m_low < a.m_low); + result->m_low = a.m_low + b.m_low; + carry = (result->m_low < a.m_low); -return result; + result->m_high = a.m_high + b.m_high + carry; + +/* Using constant-time bitwise arithmetic to prevent timing +* side-channels. +*/ + carry = (result->m_high < a.m_high) | + ((result->m_high == a.m_high) & carry); + +return carry; } static void vli_mult(u64 *result, const u64 *left, const u64 *right,
@@ -410,9 +422,7 @@ static void vli_mult(u64 *result, constuint128_t product; product =mul_64_64 (left[i], right[k - i]); - - r01 =add_128_128 (r01, product); - r2 += (r01.m_high < product.m_high); + r2 +=check_add_128_128_overflow (&r01, r01, product); } result[k] = r01.m_low;
@@ -435,7 +445,7 @@ static void vli_umult(u64 *result, constuint128_t product; product =mul_64_64 (left[k], right); - r01 =add_128_128 (r01, product); +check_add_128_128_overflow (&r01, r01, product);/* no carry */ result[k] = r01.m_low; r01.m_low = r01.m_high;
@@ -472,8 +482,7 @@ static void vli_square(u64 *result, cons product.m_low <<=1 ; } - r01 =add_128_128 (r01, product); - r2 += (r01.m_high < product.m_high); + r2 +=check_add_128_128_overflow (&r01, r01, product); } result[k] = r01.m_low;
Greg Kroah-Hartman
maintainerPATCH 193/1067 usb: typec: ucsi: Invert DisplayPort role assignment
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrei Kuchynski <[email protected]>
commit d092d7edf8faefa3e27b9fc7f0e7904b06c833a2 upstream.
The existing implementation assigned these flags backwards, configuring the partner's DisplayPort role to match the port's role instead of complementing it.
This prevents proper configuration during DP altmode activation, often causing pin_assignment to remain 0 in dp_altmode_configure() and resulting in VDM negotiation failures:
[ 583.328246] typec port1.1: VDM 0xff01a150 failed
Additionally, the fix ensures that the pin_assignment sysfs attribute displays the correct values.
--- drivers/usb/typec/ucsi/displayport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/displayport.c +2 -2
@@ -166,12 +166,12 @@ static int ucsi_displayport_status_updat* that Multi-function is preferred. */ if (DP_CAP_CAPABILITY (cap) &DP_CAP_UFP_D ) { - dp->data.status |=DP_STATUS_CON_UFP_D ; + dp->data.status |=DP_STATUS_CON_DFP_D ;if (DP_CAP_UFP_D_PIN_ASSIGN (cap) &BIT (DP_PIN_ASSIGN_D )) dp->data.status |=DP_STATUS_PREFER_MULTI_FUNC ; }else { - dp->data.status |=DP_STATUS_CON_DFP_D ; + dp->data.status |=DP_STATUS_CON_UFP_D ;if (DP_CAP_DFP_D_PIN_ASSIGN (cap) &BIT (DP_PIN_ASSIGN_D )) dp->data.status |=DP_STATUS_PREFER_MULTI_FUNC ;
Greg Kroah-Hartman
maintainerPATCH 211/1067 crypto: pcrypt - restore callback for non-parallel fallback
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruijie Li <[email protected]>
commit ed459fe319376e876de433d12b6c6772e612ca36 upstream.
pcrypt installs pcrypt_aead_done() on the child AEAD request before trying to submit it through padata. If padata_do_parallel() returns -EBUSY, pcrypt falls back to calling the child AEAD directly.
That fallback must not keep the padata completion callback. Otherwise an asynchronous completion runs pcrypt_aead_done() even though the request was never enrolled in padata.
Restore the original request callback and callback data before calling the child AEAD directly. This keeps the fallback path aligned with a direct AEAD request while leaving the parallel path unchanged.
--- crypto/pcrypt.c | 4 ++++ 1 file changed, 4 insertions(+)
crypto/pcrypt.c +4 -0
@@ -122,6 +122,8 @@ static int pcrypt_aead_encrypt(struct aereturn -EINPROGRESS ;if (err == -EBUSY ) {/* try non-parallel mode */ +aead_request_set_callback (creq, flags, req->base.complete, + req->base.data);return crypto_aead_encrypt (creq); }
@@ -173,6 +175,8 @@ static int pcrypt_aead_decrypt(struct aereturn -EINPROGRESS ;if (err == -EBUSY ) {/* try non-parallel mode */ +aead_request_set_callback (creq, flags, req->base.complete, + req->base.data);return crypto_aead_decrypt (creq); }
Greg Kroah-Hartman
maintainerPATCH 212/1067 crypto: drbg - Fix returning success on failure in CTR_DRBG
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 39a31ad9e2a5ed7e9c9c6f711dca96c8c8f5f26b upstream.
drbg_ctr_generate() sometimes returns success when it fails, leaving the output buffer uninitialized. Fix it.
--- crypto/drbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/drbg.c +1 -1
@@ -603,7 +603,7 @@ static int drbg_ctr_generate(struct drbgif (addtl && !list_empty (addtl)) { ret =drbg_ctr_update (drbg, addtl,2 );if (ret) -return 0 ; +return ret; }/* 10.2.1.5.2 step 4.1 */
Greg Kroah-Hartman
maintainerPATCH 213/1067 crypto: drbg - Fix drbg_max_addtl() on 64-bit kernels
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 6f49f00c981bbb9ef602966f19bfdbef46b681d2 upstream.
On 64-bit kernels, drbg_max_addtl() returns 2**35 bytes. That's too large, for two reasons:
1. SP800-90A says the maximum limit is 2**35 *bits*, not 2**35 bytes. So the implemented limit has confused bits and bytes.
2. When drbg_kcapi_hash() calls crypto_shash_update() on the additional information string, the length is implicitly cast to 'unsigned int'. That truncates the additional information string to U32_MAX bytes.
Fix the maximum additional information string length to always be U32_MAX - 1, causing an error to be returned for any longer lengths.
--- include/crypto/drbg.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
include/crypto/drbg.h +7 -11
@@ -171,19 +171,15 @@ static inline size_t drbg_max_request_byreturn (1 <<16 ); } +/* +* SP800-90A allows implementations to support additional info / personalization +* strings of up to 2**35 bits. Implementations can have a smaller maximum. We +* use 2**35 - 16 bits == U32_MAX - 1 bytes so that the max + 1 always fits in a +* size_t, allowing drbg_healthcheck_sanity() to verify its enforcement. +*/ static inline size_t drbg_max_addtl (struct drbg_state *drbg) { -/* SP800-90A requires 2**35 bytes additional info str / pers str */ -#if (__BITS_PER_LONG ==32 ) -/* -* SP800-90A allows smaller maximum numbers to be returned -- we -* return SIZE_MAX - 1 to allow the verification of the enforcement -* of this value in drbg_healthcheck_sanity. -*/ -return (SIZE_MAX -1 ); -#else -return (1UL <<35 ); -#endif +return U32_MAX -1 ; }static inline size_t drbg_max_requests (struct drbg_state *drbg)
Greg Kroah-Hartman
maintainerPATCH 214/1067 crypto: drbg - Fix the fips_enabled priority boost
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit a8a1f93080efc83a9ff8452954429ae379e9e614 upstream.
When fips_enabled=1, it seems to have been intended for one of the algorithms defined in crypto/drbg.c to be the highest priority "stdrng" algorithm, so that it is what is used by "stdrng" users.
However, the code only boosts the priority to 400, which is less than the priority 500 used in drivers/crypto/caam/caamprng.c. Thus, the CAAM RNG could be used instead.
Fix this by boosting the priority by 2000 instead of 200.
--- crypto/drbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/drbg.c +1 -1
@@ -2095,7 +2095,7 @@ static inline void __init drbg_fill_arra* it is selected. */ if (fips_enabled) - alg->base.cra_priority +=200 ; + alg->base.cra_priority +=2000 ; alg->base.cra_ctxsize =sizeof (struct drbg_state ); alg->base.cra_module =THIS_MODULE ;
Greg Kroah-Hartman
maintainerPATCH 215/1067 crypto: talitos - use dma_sync_single_for_cpu() before reading descriptor header
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Louvel <[email protected]>
commit e17ff3d6ff907dc8406261e8fd3e1fc8a908f0f6 upstream.
In order to know if a descriptor has been processed by the device, the driver polls the FIFO to see if DESC_HDR_DONE is set on a descriptor header to confirm completion.
The current code does not make sure that the CPU gets up to date data before reading the descriptor.
Fix this by calling dma_sync_single_for_cpu() before reading memory written by the device.
--- drivers/crypto/talitos.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
drivers/crypto/talitos.c +20 -8
@@ -321,19 +321,31 @@ static int talitos_submit(struct devicereturn -EINPROGRESS ; } -static __be32 get_request_hdr (struct talitos_request *request,bool is_sec1) +static __be32 get_request_hdr (struct device *dev, +struct talitos_request *request,bool is_sec1) {struct talitos_edesc *edesc; -if (!is_sec1) +if (!is_sec1) { +dma_sync_single_for_cpu (dev, request->dma_desc, +TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); +return request->desc->hdr; + } -if (!request->desc->next_desc) +if (!request->desc->next_desc) { +dma_sync_single_for_cpu (dev, request->dma_desc, +TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL );return request->desc->hdr1; - - edesc = container_of(request->desc, struct talitos_edesc, desc); - -return ((struct talitos_desc *)(edesc->buf + edesc->dma_len))->hdr1; + }else { +dma_sync_single_for_cpu (dev, +be32_to_cpu (request->desc->next_desc), +TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); + edesc = container_of(request->desc, struct talitos_edesc, desc); + +return ((struct talitos_desc *)(edesc->buf + edesc->dma_len)) + ->hdr1; + } }/*
@@ -357,7 +369,7 @@ static void flush_channel(struct device/* descriptors with their done bits set don't get the error */ rmb (); - hdr =get_request_hdr (request, is_sec1); + hdr =get_request_hdr (dev, request, is_sec1);if ((hdr &DESC_HDR_DONE ) ==DESC_HDR_DONE ) status =0 ;
Greg Kroah-Hartman
maintainerPATCH 216/1067 crypto: talitos - add chaining of arbitrary number of descriptor for the SEC1
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Louvel <[email protected]>
commit f126384ed55279c3b676f89d5ab547b8de8df782 upstream.
The SEC1 hardware can process a chain of descriptors without host intervention. Only the hash implementation currently use this feature, but with a chain of at most 2 descriptors added in commit 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on SEC1").
Add supports for chaining an arbitrary number of descriptors in a chain.
Adapt the ahash implementation to make it compatible.
--- drivers/crypto/talitos.c | 180 +++++++++++++++++++++++++++++++---------------- drivers/crypto/talitos.h | 2 2 files changed, 124 insertions(+), 58 deletions(-)
drivers/crypto/talitos.c +122 -58
@@ -272,7 +272,10 @@ static int talitos_submit(struct device void *context, int error), void *context) { + struct talitos_edesc *edesc = container_of(desc, struct talitos_edesc, desc);struct talitos_private *priv =dev_get_drvdata (dev); +dma_addr_t dma_desc, prev_dma_desc; +struct talitos_edesc *prev_edesc =NULL ;struct talitos_request *request;unsigned long flags;int head;
@@ -291,10 +294,31 @@ static int talitos_submit(struct device/* map descriptor and save caller data */ if (is_sec1) { - desc->hdr1 = desc->hdr; - request->dma_desc =dma_map_single (dev, &desc->hdr1, +while (edesc) { + edesc->desc.hdr1 = edesc->desc.hdr; + + dma_desc =dma_map_single (dev, &edesc->desc.hdr1, +TALITOS_DESC_SIZE , +DMA_BIDIRECTIONAL ); + +if (!prev_edesc) { + request->dma_desc = dma_desc; + goto next; + } + +/* Chain in any previous descriptors. */ + + prev_edesc->desc.next_desc =cpu_to_be32 (dma_desc); + +dma_sync_single_for_device (dev, prev_dma_desc,TALITOS_DESC_SIZE , -DMA_BIDIRECTIONAL ); +DMA_TO_DEVICE ); + +next: + prev_edesc = edesc; + prev_dma_desc = dma_desc; + edesc = edesc->next_desc; + } }else { request->dma_desc = dma_map_single(dev, desc, TALITOS_DESC_SIZE,
@@ -325,6 +349,7 @@ static __be32 get_request_hdr(struct dev struct talitos_request *request, bool is_sec1) {struct talitos_edesc *edesc; +dma_addr_t dma_desc;if (!is_sec1) { dma_sync_single_for_cpu(dev, request->dma_desc,
@@ -333,19 +358,17 @@ static __be32 get_request_hdr(struct devreturn request->desc->hdr; } -if (!request->desc->next_desc) { -dma_sync_single_for_cpu (dev, request->dma_desc, -TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); -return request->desc->hdr1; - }else { -dma_sync_single_for_cpu (dev, -be32_to_cpu (request->desc->next_desc), -TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); - edesc = container_of(request->desc, struct talitos_edesc, desc); - -return ((struct talitos_desc *)(edesc->buf + edesc->dma_len)) - ->hdr1; + edesc = container_of(request->desc, struct talitos_edesc, desc); + dma_desc = request->dma_desc; +while (edesc->next_desc) { + dma_desc =be32_to_cpu (edesc->desc.next_desc); + edesc = edesc->next_desc; } + +dma_sync_single_for_cpu (dev, dma_desc,TALITOS_DESC_SIZE , +DMA_BIDIRECTIONAL ); + +return edesc->desc.hdr1; }/*
@@ -355,6 +378,7 @@ static void flush_channel(struct device {struct talitos_private *priv =dev_get_drvdata (dev);struct talitos_request *request, saved_req; +struct talitos_edesc *edesc;unsigned long flags;int tail, status;bool is_sec1 =has_ftr_sec1 (priv);
@@ -379,9 +403,22 @@ static void flush_channel(struct deviceelse status = error; -dma_unmap_single (dev, request->dma_desc, -TALITOS_DESC_SIZE , -DMA_BIDIRECTIONAL ); +if (is_sec1) { +dma_unmap_single (dev, request->dma_desc, +TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); + edesc =container_of (request->desc, + struct talitos_edesc, desc); +while (edesc->next_desc) { +dma_unmap_single ( + dev,be32_to_cpu (edesc->desc.next_desc), +TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); + edesc = edesc->next_desc; + } + }else { +dma_unmap_single (dev, request->dma_desc, +TALITOS_DESC_SIZE , +DMA_BIDIRECTIONAL ); + }/* copy entries so we can call callback outside lock */ saved_req.desc = request->desc;
@@ -476,8 +513,12 @@ DEF_TALITOS2_DONE(ch1_3, TALITOS2_ISR_CHstatic __be32 current_desc_hdr (struct device *dev,int ch) {struct talitos_private *priv =dev_get_drvdata (dev); +bool is_sec1 =has_ftr_sec1 (priv); +struct talitos_request *request; +struct talitos_edesc *edesc;int tail, iter;dma_addr_t cur_desc; +__be32 hdr =0 ; cur_desc = ((u64 )in_be32 (priv->chan[ch].reg +TALITOS_CDPR )) <<32 ; cur_desc |=in_be32 (priv->chan[ch].reg +TALITOS_CDPR_LO );
@@ -488,27 +529,35 @@ static __be32 current_desc_hdr(struct de } tail = priv->chan[ch].tail; - iter = tail; -while (priv->chan[ch].fifo[iter].dma_desc != cur_desc && - priv->chan[ch].fifo[iter].desc->next_desc !=cpu_to_be32 (cur_desc)) { - iter = (iter +1 ) & (priv->fifo_len -1 ); -if (iter == tail) { -dev_err (dev,"couldn't locate current descriptor\n" ); -return 0 ; +do { + request = &priv->chan[ch].fifo[iter]; + +if (request->dma_desc == cur_desc) { + hdr = request->desc->hdr; + }else if (is_sec1) { + edesc =container_of (request->desc, + struct talitos_edesc, desc); +while (edesc->next_desc) { +if (edesc->desc.next_desc == +cpu_to_be32 (cur_desc)) { + hdr = edesc->next_desc->desc.hdr1; +break ; + } + edesc = edesc->next_desc; + } } - } -if (priv->chan[ch].fifo[iter].desc->next_desc ==cpu_to_be32 (cur_desc)) { -struct talitos_edesc *edesc; +if (hdr) +break ; - edesc =container_of (priv->chan[ch].fifo[iter].desc, - struct talitos_edesc, desc); -return ((struct talitos_desc *) - (edesc->buf + edesc->dma_len))->hdr; - } + iter = (iter +1 ) & (priv->fifo_len -1 ); + }while (iter != tail); + +if (!hdr) +dev_err (dev,"couldn't locate current descriptor\n" ); -return priv->chan[ch].fifo[iter].desc->hdr; +return hdr; }/*
@@ -1399,10 +1448,6 @@ static struct talitos_edesc *talitos_ede dma_len =0 ; } alloc_len += icv_stashing ? authsize :0 ; - -/* if its a ahash, add space for a second desc next to the first one */ -if (is_sec1 && !dst) - alloc_len +=sizeof (struct talitos_desc ); alloc_len += ivsize; edesc =kmalloc (alloc_len,GFP_DMA | flags);
@@ -1418,6 +1463,7 @@ static struct talitos_edesc *talitos_ede edesc->dst_nents = dst_nents; edesc->iv_dma = iv_dma; edesc->dma_len = dma_len; + edesc->next_desc =NULL ;if (dma_len) edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0], edesc->dma_len,
@@ -1718,8 +1764,10 @@ static void common_nonsnoop_hash_unmap(sstruct talitos_private *priv =dev_get_drvdata (dev);bool is_sec1 =has_ftr_sec1 (priv);struct talitos_desc *desc = &edesc->desc; -struct talitos_desc *desc2 = (struct talitos_desc *) - (edesc->buf + edesc->dma_len); +struct talitos_desc *desc2; + +if (desc->next_desc) + desc2 = &edesc->next_desc->desc;unmap_single_talitos_ptr (dev, &desc->ptr[5 ],DMA_FROM_DEVICE ); if (desc->next_desc &&
@@ -1747,10 +1795,17 @@ static void common_nonsnoop_hash_unmap(sif (edesc->dma_len)dma_unmap_single (dev, edesc->dma_link_tbl, edesc->dma_len,DMA_BIDIRECTIONAL ); +} -if (desc->next_desc) -dma_unmap_single (dev,be32_to_cpu (desc->next_desc), -TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); +static void free_edesc_list_from (struct talitos_edesc *edesc) +{ +struct talitos_edesc *next; + +while (edesc) { + next = edesc->next_desc; +kfree (edesc); + edesc = next; + } } static void ahash_done(struct device *dev,
@@ -1769,7 +1824,7 @@ static void ahash_done(struct device *de }common_nonsnoop_hash_unmap (dev, edesc, areq); -kfree (edesc); +free_edesc_list_from (edesc); areq->base.complete (&areq->base, err); }
@@ -1872,14 +1927,23 @@ static int common_nonsnoop_hash(struct ttalitos_handle_buggy_hash (ctx, edesc, &desc->ptr[3 ]);if (is_sec1 && req_ctx->nbuf && length) { -struct talitos_desc *desc2 = (struct talitos_desc *) - (edesc->buf + edesc->dma_len); -dma_addr_t next_desc; +struct talitos_edesc *edesc2; +struct talitos_desc *desc2; + + edesc2 =kzalloc (sizeof (*edesc2), + areq->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ? +GFP_KERNEL : +GFP_ATOMIC ); +if (!edesc2) { + ret = -ENOMEM ; + goto err; + } + edesc->next_desc = edesc2; + + desc2 = &edesc2->desc; -memset (desc2,0 ,sizeof (*desc2)); desc2->hdr = desc->hdr; desc2->hdr &= ~DESC_HDR_MODE0_MDEU_INIT ; - desc2->hdr1 = desc2->hdr; desc->hdr &= ~DESC_HDR_MODE0_MDEU_PAD ; desc->hdr |=DESC_HDR_MODE0_MDEU_CONT ; desc->hdr &= ~DESC_HDR_DONE_NOTIFY ;
@@ -1903,21 +1967,21 @@ static int common_nonsnoop_hash(struct t req_ctx->hw_context_size, req_ctx->hw_context, DMA_FROM_DEVICE); - - next_desc =dma_map_single (dev, &desc2->hdr1,TALITOS_DESC_SIZE , -DMA_BIDIRECTIONAL ); - desc->next_desc =cpu_to_be32 (next_desc); }if (sync_needed)dma_sync_single_for_device (dev, edesc->dma_link_tbl, edesc->dma_len,DMA_BIDIRECTIONAL ); - ret =talitos_submit (dev, ctx->ch, desc, callback, areq); -if (ret != -EINPROGRESS ) { -common_nonsnoop_hash_unmap (dev, edesc, areq); -kfree (edesc); - } + ret =talitos_submit (dev, ctx->ch, desc, callback, + areq); +if (ret != -EINPROGRESS ) + goto err; + +return -EINPROGRESS ; +err: +common_nonsnoop_hash_unmap (dev, edesc, areq); +kfree (edesc);return ret; }
drivers/crypto/talitos.h +2 -0
@@ -49,6 +49,7 @@ struct talitos_desc {* @iv_dma: dma address of iv for checking continuity and link table * @dma_len: length of dma mapped link_tbl space * @dma_link_tbl: bus physical address of link_tbl/buf +* @next_desc: next descriptor * @desc: h/w descriptor * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (SEC2) * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1)
@@ -63,6 +64,7 @@ struct talitos_edesc {dma_addr_t iv_dma;int dma_len;dma_addr_t dma_link_tbl; +struct talitos_edesc *next_desc;struct talitos_desc desc;union {struct talitos_ptr link_tbl[0 ];
Greg Kroah-Hartman
maintainerPATCH 217/1067 crypto: talitos - move dma unmapping code in flush_channel() into a standalone dma_unmap_request() function
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Louvel <[email protected]>
commit 4d9b0b7415b9e79a3d54d18b5ff230974ea78740 upstream.
Previously added code to flush_channel() in order to unmap an entire descriptor.
Move that code into a standalone function to improve readability.
--- drivers/crypto/talitos.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-)
drivers/crypto/talitos.c +22 -17
@@ -371,6 +371,27 @@ static __be32 get_request_hdr(struct devreturn edesc->desc.hdr1; } +static void dma_unmap_request (struct device *dev, +struct talitos_request *request,bool is_sec1) +{ +struct talitos_edesc *edesc; + +if (is_sec1) { +dma_unmap_single (dev, request->dma_desc,TALITOS_DESC_SIZE , +DMA_BIDIRECTIONAL ); + edesc = container_of(request->desc, struct talitos_edesc, desc); +while (edesc->next_desc) { +dma_unmap_single (dev, +be32_to_cpu (edesc->desc.next_desc), +TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); + edesc = edesc->next_desc; + } + }else { +dma_unmap_single (dev, request->dma_desc,TALITOS_DESC_SIZE , +DMA_BIDIRECTIONAL ); + } +} +/* * process what was done, notify callback of error if not */
@@ -378,7 +399,6 @@ static void flush_channel(struct device {struct talitos_private *priv =dev_get_drvdata (dev);struct talitos_request *request, saved_req; -struct talitos_edesc *edesc;unsigned long flags;int tail, status;bool is_sec1 =has_ftr_sec1 (priv);
@@ -403,22 +423,7 @@ static void flush_channel(struct deviceelse status = error; -if (is_sec1) { -dma_unmap_single (dev, request->dma_desc, -TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); - edesc =container_of (request->desc, - struct talitos_edesc, desc); -while (edesc->next_desc) { -dma_unmap_single ( - dev,be32_to_cpu (edesc->desc.next_desc), -TALITOS_DESC_SIZE ,DMA_BIDIRECTIONAL ); - edesc = edesc->next_desc; - } - }else { -dma_unmap_single (dev, request->dma_desc, -TALITOS_DESC_SIZE , -DMA_BIDIRECTIONAL ); - } +dma_unmap_request (dev, request, is_sec1);/* copy entries so we can call callback outside lock */ saved_req.desc = request->desc;
Greg Kroah-Hartman
maintainerPATCH 218/1067 crypto: talitos - move dma mapping code in talitos_submit() into a standalone dma_map_request() function
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Louvel <[email protected]>
commit 5c0aa8cad7745505297103f05dda3fa06e8ac670 upstream.
Previously added code to talitos_submit() in order to map an entire descriptor chain.
Move that code into a standalone function to improve readability.
--- drivers/crypto/talitos.c | 75 +++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 34 deletions(-)
drivers/crypto/talitos.c +41 -34
@@ -254,6 +254,46 @@ static int init_device(struct device *dereturn 0 ; } +static void dma_map_request (struct device *dev,struct talitos_request *request, +struct talitos_desc *desc,bool is_sec1) +{ +struct talitos_edesc *edesc = + container_of(desc, struct talitos_edesc, desc); +dma_addr_t dma_desc, prev_dma_desc; +struct talitos_edesc *prev_edesc =NULL ; + +if (is_sec1) { +while (edesc) { + edesc->desc.hdr1 = edesc->desc.hdr; + + dma_desc =dma_map_single (dev, &edesc->desc.hdr1, +TALITOS_DESC_SIZE , +DMA_BIDIRECTIONAL ); + +if (!prev_edesc) { + request->dma_desc = dma_desc; + goto next; + } + +/* Chain in any previous descriptors. */ + + prev_edesc->desc.next_desc =cpu_to_be32 (dma_desc); + +dma_sync_single_for_device (dev, prev_dma_desc, +TALITOS_DESC_SIZE , +DMA_TO_DEVICE ); + +next: + prev_edesc = edesc; + prev_dma_desc = dma_desc; + edesc = edesc->next_desc; + } + }else { + request->dma_desc =dma_map_single (dev, desc,TALITOS_DESC_SIZE , +DMA_BIDIRECTIONAL ); + } +} +/** * talitos_submit - submits a descriptor to the device for processing * @dev: the SEC device to be used
@@ -272,10 +312,7 @@ static int talitos_submit(struct device void *context, int error), void *context) { - struct talitos_edesc *edesc = container_of(desc, struct talitos_edesc, desc); struct talitos_private *priv = dev_get_drvdata(dev); -dma_addr_t dma_desc, prev_dma_desc; -struct talitos_edesc *prev_edesc =NULL ;struct talitos_request *request;unsigned long flags;int head;
@@ -293,37 +330,7 @@ static int talitos_submit(struct device request = &priv->chan[ch].fifo[head];/* map descriptor and save caller data */ -if (is_sec1) { -while (edesc) { - edesc->desc.hdr1 = edesc->desc.hdr; - - dma_desc =dma_map_single (dev, &edesc->desc.hdr1, -TALITOS_DESC_SIZE , -DMA_BIDIRECTIONAL ); - -if (!prev_edesc) { - request->dma_desc = dma_desc; - goto next; - } - -/* Chain in any previous descriptors. */ - - prev_edesc->desc.next_desc =cpu_to_be32 (dma_desc); - -dma_sync_single_for_device (dev, prev_dma_desc, -TALITOS_DESC_SIZE , -DMA_TO_DEVICE ); - -next: - prev_edesc = edesc; - prev_dma_desc = dma_desc; - edesc = edesc->next_desc; - } - }else { - request->dma_desc =dma_map_single (dev, desc, -TALITOS_DESC_SIZE , -DMA_BIDIRECTIONAL ); - } +dma_map_request (dev, request, desc, is_sec1); request->callback = callback; request->context = context;
Greg Kroah-Hartman
maintainerPATCH 219/1067 crypto: talitos - move code in current_desc_hdr() into a standalone function
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Louvel <[email protected]>
commit f8713d9e6091755dd30f7f1cfa25f8440cddf81b upstream.
Previously added code in current_desc_hdr() in order to add support for searching an offending descriptor inside a descriptor chain.
Move that code into a standalone function to improve readability.
--- drivers/crypto/talitos.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/crypto/talitos.c +19 -16
@@ -519,6 +519,24 @@ DEF_TALITOS2_DONE(ch0, TALITOS2_ISR_CH_0 DEF_TALITOS2_DONE(ch0_2, TALITOS2_ISR_CH_0_2_DONE) DEF_TALITOS2_DONE(ch1_3, TALITOS2_ISR_CH_1_3_DONE) +static __be32 search_desc_hdr_in_request (struct talitos_request *request, +dma_addr_t cur_desc,bool is_sec1) +{ +struct talitos_edesc *edesc; + +if (request->dma_desc == cur_desc) { +return request->desc->hdr; + }else if (is_sec1) { + edesc = container_of(request->desc, struct talitos_edesc, desc); +while (edesc->next_desc) { +if (edesc->desc.next_desc ==cpu_to_be32 (cur_desc)) +return edesc->next_desc->desc.hdr1; + edesc = edesc->next_desc; + } + } +return 0 ; +} +/* * locate current (offending) descriptor */
@@ -527,7 +545,6 @@ static __be32 current_desc_hdr(struct destruct talitos_private *priv =dev_get_drvdata (dev);bool is_sec1 =has_ftr_sec1 (priv);struct talitos_request *request; -struct talitos_edesc *edesc;int tail, iter;dma_addr_t cur_desc;__be32 hdr =0 ;
@@ -545,21 +562,7 @@ static __be32 current_desc_hdr(struct de do { request = &priv->chan[ch].fifo[iter]; - if (request->dma_desc == cur_desc) { - hdr = request->desc->hdr; - } else if (is_sec1) { - edesc = container_of(request->desc, - struct talitos_edesc, desc); - while (edesc->next_desc) { - if (edesc->desc.next_desc == - cpu_to_be32(cur_desc)) { - hdr = edesc->next_desc->desc.hdr1; - break; - } - edesc = edesc->next_desc; - } - } - + hdr = search_desc_hdr_in_request(request, cur_desc, is_sec1); if (hdr) break;
Greg Kroah-Hartman
maintainerPATCH 220/1067 spi: fsl-lpspi: replace dmaengine_terminate_all() with dmaengine_terminate_sync()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carlos Song <[email protected]>
commit e703ce47691b967fe9b4057fb1d062273211afa9 upstream.
dmaengine_terminate_all() has been deprecated, so replace it with dmaengine_terminate_sync().
--- drivers/spi/spi-fsl-lpspi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/spi/spi-fsl-lpspi.c +9 -9
@@ -577,7 +577,7 @@ static int fsl_lpspi_dma_transfer(struct tx->sgl, tx->nents,DMA_MEM_TO_DEV , DMA_PREP_INTERRUPT | DMA_CTRL_ACK);if (!desc_tx) { -dmaengine_terminate_all (controller->dma_tx); +dmaengine_terminate_sync (controller->dma_tx);return -EINVAL ; }
@@ -598,8 +598,8 @@ static int fsl_lpspi_dma_transfer(struct transfer_timeout);if (!timeout) {dev_err (fsl_lpspi->dev,"I/O Error in DMA TX\n" ); -dmaengine_terminate_all (controller->dma_tx); -dmaengine_terminate_all (controller->dma_rx); +dmaengine_terminate_sync (controller->dma_tx); +dmaengine_terminate_sync (controller->dma_rx);fsl_lpspi_reset (fsl_lpspi);return -ETIMEDOUT ; }
@@ -608,8 +608,8 @@ static int fsl_lpspi_dma_transfer(struct transfer_timeout);if (!timeout) {dev_err (fsl_lpspi->dev,"I/O Error in DMA RX\n" ); -dmaengine_terminate_all (controller->dma_tx); -dmaengine_terminate_all (controller->dma_rx); +dmaengine_terminate_sync (controller->dma_tx); +dmaengine_terminate_sync (controller->dma_rx);fsl_lpspi_reset (fsl_lpspi);return -ETIMEDOUT ; }
@@ -618,8 +618,8 @@ static int fsl_lpspi_dma_transfer(struct fsl_lpspi->slave_aborted) {dev_dbg (fsl_lpspi->dev,"I/O Error in DMA TX interrupted\n" ); -dmaengine_terminate_all (controller->dma_tx); -dmaengine_terminate_all (controller->dma_rx); +dmaengine_terminate_sync (controller->dma_tx); +dmaengine_terminate_sync (controller->dma_rx);fsl_lpspi_reset (fsl_lpspi);return -EINTR ; }
@@ -628,8 +628,8 @@ static int fsl_lpspi_dma_transfer(struct fsl_lpspi->slave_aborted) {dev_dbg (fsl_lpspi->dev,"I/O Error in DMA RX interrupted\n" ); -dmaengine_terminate_all (controller->dma_tx); -dmaengine_terminate_all (controller->dma_rx); +dmaengine_terminate_sync (controller->dma_tx); +dmaengine_terminate_sync (controller->dma_rx);fsl_lpspi_reset (fsl_lpspi);return -EINTR ; }
Greg Kroah-Hartman
maintainerPATCH 194/1067 usb: typec: ucsi: Pass full DP config payload in SET_NEW_CAM for DP alt mode
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Madhu M <[email protected]>
commit 735a461d060d4eeb2f9732aba1295bc32a3982e2 upstream.
In the UCSI Specification Revision 3.1 RC1, bits 32-63 of the SET_NEW_CAM command hold the 32-bit Alternate Mode Specific (AMSpecific) field.
For DisplayPort Alternate Mode, this field must contain the full 32-bit DisplayPort configuration VDO payload that the OPM wants the connector to operate in, rather than just the pin assignment value. This AMSpecific value follows the DisplayPort Configurations defined in the DisplayPort Alt Mode on USB Type-C Specification v2.1a, Table 5-13: SOP DisplayPort Configurations.
--- drivers/usb/typec/ucsi/displayport.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/typec/ucsi/displayport.c +1 -2
@@ -185,13 +185,12 @@ static int ucsi_displayport_status_updatstatic int ucsi_displayport_configure (struct ucsi_dp *dp) { -u32 pins =DP_CONF_GET_PIN_ASSIGN (dp->data.conf);u64 command;if (!dp->override)return 0 ; - command =UCSI_CMD_SET_NEW_CAM (dp->con->num,1 , dp->offset, pins); + command =UCSI_CMD_SET_NEW_CAM (dp->con->num,1 , dp->offset, dp->data.conf);return ucsi_send_command (dp->con->ucsi, command,NULL ,0 ); }
Greg Kroah-Hartman
maintainerPATCH 221/1067 spi: fsl-lpspi: terminate the RX channel on TX prepare failure path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carlos Song <[email protected]>
commit 01980b5da56e573d62798d0ff6c86bcaa2b22cbe upstream.
When dmaengine_prep_slave_sg() fails for the TX channel, the error path terminates the TX DMA channel but leaves the RX channel running. Since the RX channel was already submitted and issued prior to preparing the TX descriptor, returning -EINVAL causes the SPI core to unmap the DMA buffers while the RX DMA engine continues writing to them, leading to potential memory corruption or use-after-free.
Terminate the RX channel before returning on the TX prepare failure path.
--- drivers/spi/spi-fsl-lpspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-fsl-lpspi.c +1 -1
@@ -577,7 +577,7 @@ static int fsl_lpspi_dma_transfer(struct tx->sgl, tx->nents,DMA_MEM_TO_DEV , DMA_PREP_INTERRUPT | DMA_CTRL_ACK);if (!desc_tx) { -dmaengine_terminate_sync (controller->dma_tx); +dmaengine_terminate_sync (controller->dma_rx);return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 222/1067 EDAC/i10nm: Dont fail probing if ADXL is missing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasily Khoruzhick <[email protected]>
commit e360a6d65bb46c527a5909430a31d640cdd5036e upstream.
ADXL is not present in Coreboot- or Slimbootloader-based BIOSes and as result, the driver fails to probe there.
Since commit 2738c69a8813 ("EDAC/i10nm: Add driver decoder for Ice Lake and Tremont CPUs"), i10nm_edac supports driver decoder. Switch to driver decoding when ADXL is not present.
--- drivers/edac/i10nm_base.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/edac/i10nm_base.c +11 -3
@@ -76,6 +76,7 @@ static struct res_config *res_cfg;static int retry_rd_err_log;static int decoding_via_mca;static bool mem_cfg_2lm; +static bool no_adxl;static u32 offsets_scrub_icx[] = {0x22c60 ,0x22c54 ,0x22c5c ,0x22c58 ,0x22c28 ,0x20ed8 };static u32 offsets_scrub_spr[] = {0x22c60 ,0x22c54 ,0x22f08 ,0x22c58 ,0x22c28 ,0x20ed8 };
@@ -826,8 +827,14 @@ static int __init i10nm_init(void) } rc =skx_adxl_get (); -if (rc) - goto fail; +if (rc) { +/* Decoding errors via MCA banks for 2LM isn't supported yet */ +if (rc != -ENODEV || mem_cfg_2lm) + goto fail; +i10nm_printk (KERN_INFO ,"ADXL not found, falling back to MCA-based decoding.\n" ); + no_adxl = true; + decoding_via_mca = true; + }opstate_init ();mce_register_decode_chain (&i10nm_mce_dec);
@@ -861,7 +868,8 @@ static void __exit i10nm_exit(void)teardown_i10nm_debug ();mce_unregister_decode_chain (&i10nm_mce_dec); -skx_adxl_put (); +if (!no_adxl) +skx_adxl_put ();skx_remove (); }
Greg Kroah-Hartman
maintainerPATCH 223/1067 watchdog: apple: Add "apple,t8103-wdt" compatible
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Janne Grunau <[email protected]>
commit 14ca4868886f2188401fe06cd7bf01a330b3fb99 upstream.
After discussion with the devicetree maintainers we agreed to not extend lists with the generic compatible "apple,wdt" anymore [1]. Use "apple,t8103-wdt" as base compatible as it is the SoC the driver and bindings were written for.
[1]: https://lore.kernel.org/asahi/[email protected]/
--- drivers/watchdog/apple_wdt.c | 1 + 1 file changed, 1 insertion(+)
drivers/watchdog/apple_wdt.c +1 -0
@@ -207,6 +207,7 @@ static int apple_wdt_probe(struct platfo }static const struct of_device_id apple_wdt_of_match[] = { + { .compatible ="apple,t8103-wdt" }, { .compatible ="apple,wdt" }, {}, };
Greg Kroah-Hartman
maintainerPATCH 224/1067 tracing: Prevent out-of-bounds read in glob matching
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huihui Huang <[email protected]>
commit 0a6070839b1ef276d5b05bedfb787743e140fb17 upstream.
String event fields are not necessarily NUL-terminated, so the filter predicate functions (filter_pred_string(), filter_pred_strloc() and filter_pred_strrelloc()) pass the field length to the regex match callbacks, and the length-aware matchers honour it.
regex_match_glob() was the exception: it ignored the length and called glob_match(), which scans the string until it hits a NUL byte. Some string fields are not NUL-terminated. One example is the dynamic char array of the xfs_* namespace tracepoints, which is copied without a trailing NUL. For such a field, glob matching reads past the end of the event field, causing a KASAN slab-out-of-bounds read in glob_match(), reached via regex_match_glob() and filter_match_preds() from the xfs_lookup tracepoint.
Add a length-bounded glob_match_len() and use it from regex_match_glob() so glob matching always stops at the field boundary. The matching loop is factored into a shared helper so glob_match() keeps its behaviour.
--- include/linux/glob.h | 1 + kernel/trace/trace_events_filter.c | 6 ++---- lib/glob.c | 31 +++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-)
include/linux/glob.h +1 -0
@@ -6,5 +6,6 @@#include <linux/compiler.h> /* For __pure */ bool __pure glob_match (char const *pat,char const *str); +bool __pure glob_match_len (char const *pat,char const *str,size_t len);#endif /* _LINUX_GLOB_H */
kernel/trace/trace_events_filter.c +2 -4
@@ -923,11 +923,9 @@ static int regex_match_end(char *str, streturn 0 ; } -static int regex_match_glob (char *str,struct regex *r,int len__maybe_unused ) +static int regex_match_glob (char *str,struct regex *r,int len) { -if (glob_match (r->pattern, str)) -return 1 ; -return 0 ; +return glob_match_len (r->pattern, str, len) ?1 :0 ; }/**
lib/glob.c +29 -2
@@ -9,6 +9,9 @@MODULE_DESCRIPTION ("glob(7) matching" );MODULE_LICENSE ("Dual MIT/GPL" ); +static bool __pure glob_match_str (char const *pat,char const *str, +char const *str_end); +/** * glob_match - Shell-style pattern matching, like !fnmatch(pat, str, 0) * @pat: Shell-style pattern to match, e.g. "*.[ch]".
@@ -39,6 +42,29 @@ MODULE_LICENSE("Dual MIT/GPL");*/ bool __pure glob_match (char const *pat,char const *str) { +return glob_match_str (pat, str,NULL ); +} +EXPORT_SYMBOL (glob_match); + +/** +* glob_match_len - glob match against a length-bounded string +* @pat: Shell-style pattern to match. +* @str: String to match. Need not be NUL-terminated. +* @len: Number of bytes of @str that may be read. +* +* Like glob_match(), but @str is only read up to @len bytes, so it can be +* used on buffers that are not NUL-terminated (e.g. trace event fields). +* A NUL byte within @len still terminates the string. +*/ +bool __pure glob_match_len (char const *pat,char const *str,size_t len) +{ +return glob_match_str (pat, str, str + len); +} +EXPORT_SYMBOL (glob_match_len); + +static bool __pure glob_match_str (char const *pat,char const *str, +char const *str_end) +{/* * Backtrack to previous * on mismatch and retry starting one * character later in the string. Because * matches all characters
@@ -53,9 +79,11 @@ bool __pure glob_match(char const *pat,* on mismatch, or true after matching the trailing nul bytes. */ for (;;) { -unsigned char c = *str++; +unsigned char c = (str_end && str >= str_end) ?'\0' : *str;unsigned char d = *pat++; + str++; +switch (d) {case '?' :/* Wildcard: anything but nul */ if (c =='\0' )
@@ -120,4 +148,3 @@ backtrack: } } } -EXPORT_SYMBOL (glob_match);
Greg Kroah-Hartman
maintainerPATCH 225/1067 NFSv4: include MAY_WRITE in open permission mask for O_TRUNC
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Coddington <[email protected]>
commit 5140f099ecd8a2f2808b7f7b720ee1bad8468974 upstream.
POSIX requires write permission to truncate a file, so an open() that specifies O_TRUNC must be authorized for write access regardless of the O_ACCMODE access mode.
nfs_open_permission_mask() builds the access mask passed to nfs_may_open(), which is the local authorization gate for OPENs the client serves itself from a cached write delegation via the can_open_delegated() path in nfs4_try_open_cached(). The mask is derived from O_ACCMODE alone, so an open(O_RDONLY | O_TRUNC) against a file the caller cannot write requests only MAY_READ and passes the local check. The OPEN is then satisfied locally and the truncation is issued to the server as a SETATTR(size=0) over the delegation stateid, which the server accepts under standard write-delegation semantics. POSIX requires that this open fail with EACCES.
Include MAY_WRITE in the mask whenever O_TRUNC is set so the local check matches the access the server would have enforced.
--- fs/nfs/dir.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nfs/dir.c +2 -0
@@ -3237,6 +3237,8 @@ static int nfs_open_permission_mask(int mask |=MAY_READ ;if ((openflags &O_ACCMODE ) !=O_RDONLY ) mask |=MAY_WRITE ; +if (openflags &O_TRUNC ) + mask |=MAY_WRITE ; }return mask;
Greg Kroah-Hartman
maintainerPATCH 226/1067 module: decompress: check return value of module_extend_max_pages()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrii Kuchmenko <[email protected]>
commit 786d2d84416a9a1c1a47b71a68d679d886284be2 upstream.
module_extend_max_pages() calls kvrealloc() internally and returns -ENOMEM on allocation failure. The return value is never checked.
If the initial allocation fails, info->pages remains NULL and info->max_pages remains 0. Subsequent calls to module_get_next_page() will attempt to dynamically grow the array by calling module_extend_max_pages(info, 0) since info->used_pages is 0. This results in kvrealloc(NULL, 0) returning ZERO_SIZE_PTR, which is treated as a success, leading to a dereference of ZERO_SIZE_PTR and a kernel oops.
Fix: add the missing error check after module_extend_max_pages() and return immediately on failure. This matches the pattern used by every other kvrealloc() caller in the module loading path.
--- kernel/module/decompress.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/module/decompress.c +2 -0
@@ -215,6 +215,8 @@ int module_decompress(struct load_info **/ n_pages =DIV_ROUND_UP (size,PAGE_SIZE ) *2 ; error =module_extend_max_pages (info, n_pages); +if (error) +return error; data_size =MODULE_DECOMPRESS_FN (info, buf, size);if (data_size <0 ) {
Greg Kroah-Hartman
maintainerPATCH 227/1067 exfat: bound uniname advance in exfat_find_dir_entry()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 3a1230e7b043c62737b05a3e9275ca83a43ad20a upstream.
In exfat_find_dir_entry(), each TYPE_EXTEND (file name) entry advances the output pointer by a fixed amount while the loop guard only tracks the accumulated name length:
if (++order == 2) uniname = p_uniname->name; else uniname += EXFAT_FILE_NAME_LEN; len = exfat_extract_uni_name(ep, entry_uniname); name_len += len; unichar = *(uniname+len); *(uniname+len) = 0x0;
uniname grows by EXFAT_FILE_NAME_LEN (15) per name entry, but name_len grows only by the actual extracted length, which is shorter when a name fragment contains an early NUL. The only guard isname_len >= MAX_NAME_LENGTH, so a crafted directory with many short name fragments lets uniname run far past the p_uniname->name[MAX_NAME_LENGTH + 3] buffer while name_len stays small, causing an out-of-bounds read and write at *(uniname+len).
The sibling extractor exfat_get_uniname_from_ext_entry() already stops on a short fragment (the lockstep len != EXFAT_FILE_NAME_LEN guard added in commit d42334578eba ("exfat: check if filename entries exceeds max filename length")); exfat_find_dir_entry() never got the equivalent. Track the per-entry write offset as a count and reject a fragment once the offset, or the offset plus the extracted length, would exceed MAX_NAME_LENGTH, before forming the output pointer.
--- fs/exfat/dir.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
fs/exfat/dir.c +8 -5
@@ -1042,6 +1042,7 @@ rewind:if (entry_type ==TYPE_EXTEND ) {unsigned short entry_uniname[16 ], unichar; +unsigned int offset;if (step !=DIRENT_STEP_NAME || name_len >=MAX_NAME_LENGTH ) {
@@ -1050,13 +1051,15 @@ rewind:continue ; } -if (++order ==2 ) - uniname = p_uniname->name; -else - uniname +=EXFAT_FILE_NAME_LEN ; - + offset = (++order -2 ) *EXFAT_FILE_NAME_LEN ; len =exfat_extract_uni_name (ep, entry_uniname);brelse (bh); +if (offset >MAX_NAME_LENGTH || + len >MAX_NAME_LENGTH - offset) { + step =DIRENT_STEP_FILE ; +continue ; + } + uniname = p_uniname->name + offset; name_len += len; unichar = *(uniname+len);
Greg Kroah-Hartman
maintainerPATCH 228/1067 NTB: epf: Fix request_irq() unwind in ntb_epf_init_isr()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit fcba26efe5efc7441f5505f4ccc69791214b40be upstream.
ntb_epf_init_isr() requests multiple MSI/MSI-X vectors in a loop. If request_irq() fails part-way through, it jumps straight to pci_free_irq_vectors() without freeing already requested IRQs.
Fix the error path by freeing any successfully requested IRQs before releasing the vectors.
--- drivers/ntb/hw/epf/ntb_hw_epf.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/ntb/hw/epf/ntb_hw_epf.c +4 -6
@@ -357,7 +357,7 @@ static int ntb_epf_init_isr(struct ntb_e 0, "ntb_epf", ndev);if (ret) {dev_err (dev,"Failed to request irq\n" ); - goto err_request_irq; + goto err_free_irq; } }
@@ -367,16 +367,14 @@ static int ntb_epf_init_isr(struct ntb_e argument | irq);if (ret) {dev_err (dev,"Failed to configure doorbell\n" ); - goto err_configure_db; + goto err_free_irq; }return 0 ; -err_configure_db: -for (i =0 ; i < ndev->db_count +1 ; i++) +err_free_irq: +while (i--)free_irq (pci_irq_vector (pdev, i), ndev); - -err_request_irq:pci_free_irq_vectors (pdev);return ret;
Greg Kroah-Hartman
maintainerPATCH 229/1067 KVM: VMX: Refresh GUEST_PENDING_DBG_EXCEPTIONS.BS on all injected #DBs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit c5bad4fa2d5dfd8c25140051a9807eba387a19b8 upstream.
Move KVM's stuffing of GUEST_PENDING_DBG_EXCEPTIONS.BS when RFLAGS.TF=1 and MOV/POP SS or STI blocking is active into the exception injection code so that KVM fixes up the VMCS for all injected #DBs, not only those that are reflected back into the guest after #DB interception. E.g. if KVM queues a #DB in the emulator, or more importantly if userspace does save/restore exactly on the #DB+shadow boundary, then KVM needs to massage the VMCS to avoid the VM-Entry consistency check.
Opportunistically update the wording of the comment to describe the behavior as a workaround of flawed CPU behavior/architecture, to make it clear that the *only* thing KVM is doing is fudging around a consistency check. Per the SDM:
There are no pending debug exceptions after VM entry if any of the following are true:
* The VM entry is vectoring with one of the following interruption
types: external interrupt, non-maskable interrupt (NMI), hardware exception, or privileged software exception.
I.e. forcing GUEST_PENDING_DBG_EXCEPTIONS.BS does *not* impact guest- visible behavior.
--- arch/x86/kvm/vmx/vmx.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
arch/x86/kvm/vmx/vmx.c +18 -17
@@ -1734,6 +1734,24 @@ static void vmx_inject_exception(structu32 intr_info = ex->vector |INTR_INFO_VALID_MASK ;struct vcpu_vmx *vmx =to_vmx (vcpu); +/* +* When injecting a #DB, single-stepping is enabled in RFLAGS, and STI +* or MOV-SS blocking is active, set vmcs.PENDING_DBG_EXCEPTIONS.BS to +* prevent a false positive from VM-Entry consistency check. VM-Entry +* asserts that a single-step #DB _must_ be pending in this scenario, +* as the previous instruction cannot have toggled RFLAGS.TF 0=>1 +* (because STI and POP/MOV don't modify RFLAGS), therefore the one +* instruction delay when activating single-step breakpoints must have +* already expired. However, the CPU isn't smart enough to peek at +* vmcs.VM_ENTRY_INTR_INFO_FIELD and so doesn't realize that yes, there +* is indeed a #DB pending/imminent. +*/ +if (ex->vector ==DB_VECTOR && + (vmx_get_rflags (vcpu) &X86_EFLAGS_TF ) && +vmx_get_interrupt_shadow (vcpu)) +vmcs_writel (GUEST_PENDING_DBG_EXCEPTIONS , +vmcs_readl (GUEST_PENDING_DBG_EXCEPTIONS ) |DR6_BS ); +kvm_deliver_exception_payload (vcpu, ex);if (ex->has_error_code) {
@@ -5206,26 +5224,9 @@ static int handle_exception_nmi(struct k* avoid single-step #DB and MTF updates, as ICEBP is * higher priority. Note, skipping ICEBP still clears * STI and MOVSS blocking. -* -* For all other #DBs, set vmcs.PENDING_DBG_EXCEPTIONS.BS -* if single-step is enabled in RFLAGS and STI or MOVSS -* blocking is active, as the CPU doesn't set the bit -* on VM-Exit due to #DB interception. VM-Entry has a -* consistency check that a single-step #DB is pending -* in this scenario as the previous instruction cannot -* have toggled RFLAGS.TF 0=>1 (because STI and POP/MOV -* don't modify RFLAGS), therefore the one instruction -* delay when activating single-step breakpoints must -* have already expired. Note, the CPU sets/clears BS -* as appropriate for all other VM-Exits types. */ if (is_icebp (intr_info))WARN_ON (!skip_emulated_instruction (vcpu)); -else if ((vmx_get_rflags (vcpu) &X86_EFLAGS_TF ) && - (vmcs_read32 (GUEST_INTERRUPTIBILITY_INFO ) & - (GUEST_INTR_STATE_STI |GUEST_INTR_STATE_MOV_SS ))) -vmcs_writel (GUEST_PENDING_DBG_EXCEPTIONS , -vmcs_readl (GUEST_PENDING_DBG_EXCEPTIONS ) |DR6_BS );kvm_queue_exception_p (vcpu,DB_VECTOR , dr6);return 1 ;
Greg Kroah-Hartman
maintainerPATCH 230/1067 KVM: VMX: Grab vmcs12 on CR8 interception update iff vCPU is in guest mode
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit 7ef78d71ca713d8c00f7c34ddcf276c808143f77 upstream.
When updating CR8 intercepts, get vmcs12 if and only if the vCPU is in guest mode so that a future change can have update CR8 intercepts during vCPU creation, without running afoul of get_vmcs12()'s lockdep assertion.
------------[ cut here ]------------ debug_locks && !(lock_is_held(&(&vcpu->mutex)->dep_map) || !refcount_read(&vcpu->kvm->users_count)) WARNING: arch/x86/kvm/vmx/nested.h:61 at get_vmcs12 arch/x86/kvm/vmx/nested.h:60 [inline], CPU#0: syz.2.19/5879 WARNING: arch/x86/kvm/vmx/nested.h:61 at vmx_update_cr8_intercept+0x3de/0x4e0 arch/x86/kvm/vmx/vmx.c:6879, CPU#0: syz.2.19/5879 Modules linked in: CPU: 0 UID: 0 PID: 5879 Comm: syz.2.19 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 RIP: 0010:get_vmcs12 arch/x86/kvm/vmx/nested.h:60 [inline] RIP: 0010:vmx_update_cr8_intercept+0x3de/0x4e0 arch/x86/kvm/vmx/vmx.c:6879 Call Trace: <TASK> apic_update_ppr arch/x86/kvm/lapic.c:984 [inline] kvm_lapic_reset+0x1c24/0x2980 arch/x86/kvm/lapic.c:3023 kvm_vcpu_reset+0x44c/0x1bf0 arch/x86/kvm/x86.c:12986 kvm_arch_vcpu_create+0x746/0x8b0 arch/x86/kvm/x86.c:12847 kvm_vm_ioctl_create_vcpu+0x428/0x930 virt/kvm/kvm_main.c:4201 kvm_vm_ioctl+0x893/0xd50 virt/kvm/kvm_main.c:5159 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
No functional change intended.
Message-ID: <[email protected]>
--- arch/x86/kvm/vmx/vmx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/vmx/vmx.c +1 -2
@@ -6620,11 +6620,10 @@ static noinstr void vmx_l1d_flush(structstatic void vmx_update_cr8_intercept (struct kvm_vcpu *vcpu,int tpr,int irr) { -struct vmcs12 *vmcs12 =get_vmcs12 (vcpu);int tpr_threshold;if (is_guest_mode (vcpu) && -nested_cpu_has (vmcs12,CPU_BASED_TPR_SHADOW )) +nested_cpu_has (get_vmcs12 (vcpu),CPU_BASED_TPR_SHADOW ))return ; tpr_threshold = (irr ==-1 || tpr < irr) ?0 : irr;
Greg Kroah-Hartman
maintainerPATCH 195/1067 usb: typec: ucsi: ccg: Fix use-after-free of ucsi on remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 1f0bdc2884b67de337215079bba166df0cdf4ac5 upstream.
The threaded IRQ handler ccg_irq_handler() calls ucsi_notify_common(), which on a connector-change event calls ucsi_connector_change() and schedules connector work. In ucsi_ccg_remove(), ucsi_destroy() frees uc->ucsi (kfree) before free_irq() is called, so a handler invocation already in flight may access the freed object after ucsi_destroy().
CPU 0 (remove) | CPU 1 (threaded IRQ)
ucsi_destroy(uc->ucsi) | ccg_irq_handler()
kfree(ucsi) // FREE | ucsi_notify_common(uc->ucsi) // USEMove free_irq() before ucsi_destroy() in the remove path. It is kept after ucsi_unregister(): ucsi_unregister() cancels connector work whose handler issues GET_CONNECTOR_STATUS through ucsi_send_command_common(), which waits for a completion that is signalled from the IRQ handler, so the IRQ must stay active until that work has been cancelled.
The probe error path already orders free_irq() before ucsi_destroy().
This bug was found by static analysis.
--- drivers/usb/typec/ucsi/ucsi_ccg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/ucsi/ucsi_ccg.c +1 -1
@@ -1435,8 +1435,8 @@ static void ucsi_ccg_remove(struct i2c_ccancel_work_sync (&uc->work);pm_runtime_disable (uc->dev);ucsi_unregister (uc->ucsi); -ucsi_destroy (uc->ucsi);free_irq (uc->irq, uc); +ucsi_destroy (uc->ucsi); }static const struct i2c_device_id ucsi_ccg_device_id[] = {
Greg Kroah-Hartman
maintainerPATCH 231/1067 udmabuf: fix DMA direction mismatch in release_udmabuf()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Gavrilov <[email protected]>
commit fb7b1a0ab25a6077d26cb3829e31743972d4f31d upstream.
begin_cpu_udmabuf() maps the sg_table with the caller-provided direction (e.g., DMA_TO_DEVICE for a write-only sync), and caches it in ubuf->sg for reuse. However, release_udmabuf() always unmaps this sg_table with a hardcoded DMA_BIDIRECTIONAL, regardless of the direction that was originally used for the mapping.
With CONFIG_DMA_API_DEBUG=y this produces:
DMA-API: misc udmabuf: device driver frees DMA memory with different direction [device address=0x000000044a123000] [size=4096 bytes] [mapped with DMA_TO_DEVICE] [unmapped with DMA_BIDIRECTIONAL]
The issue was found during video playback when GStreamer performed a write-only DMA_BUF_IOCTL_SYNC on a udmabuf. It can be reproduced with CONFIG_DMA_API_DEBUG=y by creating a udmabuf from a memfd, performing a write-only sync (DMA_BUF_SYNC_WRITE without DMA_BUF_SYNC_READ), and closing the file descriptor.
Fix this by storing the DMA direction used when the sg_table is first created in begin_cpu_udmabuf(), and passing that same direction to put_sg_table() in release_udmabuf().
--- drivers/dma-buf/udmabuf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/dma-buf/udmabuf.c +4 -1
@@ -25,6 +25,7 @@ struct udmabuf {pgoff_t pagecount;struct page **pages;struct sg_table *sg; +enum dma_data_direction sg_dir;struct miscdevice *device; };
@@ -111,7 +112,7 @@ static void release_udmabuf(struct dma_bpgoff_t pg;if (ubuf->sg) -put_sg_table (dev, ubuf->sg,DMA_BIDIRECTIONAL ); +put_sg_table (dev, ubuf->sg, ubuf->sg_dir);for (pg =0 ; pg < ubuf->pagecount; pg++)put_page (ubuf->pages[pg]);
@@ -131,6 +132,8 @@ static int begin_cpu_udmabuf(struct dma_if (IS_ERR (ubuf->sg)) { ret =PTR_ERR (ubuf->sg); ubuf->sg =NULL ; + }else { + ubuf->sg_dir = direction; } }else {dma_sync_sgtable_for_cpu (dev, ubuf->sg, direction);
Greg Kroah-Hartman
maintainerPATCH 232/1067 i2c: core: fix adapter deregistration race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit b1a58ed9eab146b36f41a55db8f5d7ce9fdedf3f upstream.
Adapters can be looked up by their id using i2c_get_adapter() which takes a reference to the embedded struct device.
Remove the adapter from the IDR before tearing it down during deregistration (and on registration failure) to make sure its resources are not accessed after having been freed (e.g. the device name).
--- drivers/i2c/i2c-core-base.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +7 -2
@@ -1568,7 +1568,7 @@ static int i2c_register_adapter(struct i res =device_add (&adap->dev);if (res) {pr_err ("adapter '%s': can't register device (%d)\n" , adap->name, res); - goto err_remove_debugfs; + goto err_replace_id; } res =i2c_setup_smbus_alert (adap);
@@ -1612,7 +1612,10 @@ static int i2c_register_adapter(struct i out_reg:i2c_deregister_clients (adap);device_del (&adap->dev); -err_remove_debugfs: +err_replace_id: +mutex_lock (&core_lock); +idr_replace (&i2c_adapter_idr,NULL , adap->nr); +mutex_unlock (&core_lock);debugfs_remove_recursive (adap->debugfs);init_completion (&adap->dev_released);put_device (&adap->dev);
@@ -1802,6 +1805,8 @@ void i2c_del_adapter(struct i2c_adapter/* First make sure that this adapter was ever added */ mutex_lock (&core_lock); found =idr_find (&i2c_adapter_idr, adap->nr); +if (found == adap) +idr_replace (&i2c_adapter_idr,NULL , adap->nr);mutex_unlock (&core_lock);if (found != adap) {pr_debug ("attempting to delete unregistered adapter [%s]\n" , adap->name);
Greg Kroah-Hartman
maintainerPATCH 233/1067 i2c: stm32f7: truncate clock period instead of rounding it
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guillermo Rodríguez <[email protected]>
commit 111bb7f9f4a90b32e495d70a607c67b137f3074a upstream.
stm32f7_i2c_compute_timing() derives the I2C clock source period (i2cclk) with DIV_ROUND_CLOSEST, which may round it up. When the period is overestimated, all timings computed from it (SCLDEL, SDADEL, SCLL, SCLH) come out shorter on the wire than calculated, and the resulting bus rate can exceed the requested speed, violating the I2C specification minimums for tLOW and tHIGH.
For example, with a 104.45 MHz clock source (e.g. PCLK1, the reset-default I2C clock source on STM32MP1), i2cclk is rounded from 9.574 ns up to 10 ns. Requesting a 400 kHz fast mode bus with 72/27 ns rise/fall times and no analog/digital filters then produces an actual bus rate of 415.6 kHz with tLOW = 1254 ns, violating both the 400 kHz maximum rate and the 1300 ns tLOW minimum of the specification.
Truncate the period instead, so that it can only be underestimated. The error then falls on the safe side: the programmed timings come out slightly longer than computed and the bus runs marginally below the target rate (375.3 kHz in the example above) while meeting the specification.
i2cbus is left rounded-to-closest: it is only used as the target of the clk_error comparison and is never multiplied into the programmed timings, so nearest rounding remains accurate there.
--- drivers/i2c/busses/i2c-stm32f7.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-stm32f7.c +7 -2
@@ -449,8 +449,13 @@ static int stm32f7_i2c_compute_timing(st {struct stm32f7_i2c_spec *specs;u32 p_prev =STM32F7_PRESC_MAX ; -u32 i2cclk =DIV_ROUND_CLOSEST (NSEC_PER_SEC , - setup->clock_src); +/* +* Truncate instead of rounding to closest: if the clock period is +* overestimated, the computed SCL timings will come out shorter on +* the wire, which can push the bus above the target rate and below +* the spec's tLOW/tHIGH minimums. +*/ +u32 i2cclk =NSEC_PER_SEC / setup->clock_src;u32 i2cbus =DIV_ROUND_CLOSEST (NSEC_PER_SEC , setup->speed_freq);u32 clk_error_prev = i2cbus;
Greg Kroah-Hartman
maintainerPATCH 234/1067 Input: synaptics-rmi4 - unregister function handlers on physical driver registration failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 6251f7d3472c0409e30f8d6a24f10d33d12e3f9a upstream.
If rmi_register_physical_driver() fails, the current error path unregisters only the RMI bus. The function handlers registered earlier remain registered with the driver core.
Add a separate error path to unregister the function handlers before unregistering the bus in this failure case.
--- drivers/input/rmi4/rmi_bus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/input/rmi4/rmi_bus.c +3 -1
@@ -448,11 +448,13 @@ static int __init rmi_bus_init(void)if (error) {pr_err ("%s: error registering the RMI physical driver: %d\n" , __func__, error); - goto err_unregister_bus; + goto err_unregister_function_handlers; }return 0 ; +err_unregister_function_handlers: +rmi_unregister_function_handlers (); err_unregister_bus:bus_unregister (&rmi_bus_type);return error;
Greg Kroah-Hartman
maintainerPATCH 235/1067 Input: synaptics-rmi4 - bound the F3A keymap to the GPIO count
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 57c10915f2c16c90e0d46ad00876bf39ece40fc2 upstream.
rmi_f3a_initialize() takes the GPIO count from the device query register (f3a->gpio_count = buf & RMI_F3A_GPIO_COUNT, range 0..127). rmi_f3a_map_gpios() then allocates gpio_key_map with min(gpio_count, TRACKSTICK_RANGE_END) == at most 6 entries, but rmi_f3a_attention() iterates the full gpio_count and dereferences gpio_key_map[i], and input->keycodemax is set to the full gpio_count while input->keycode points at the 6-entry allocation.
A device that reports gpio_count > 6 therefore causes an out-of-bounds read of gpio_key_map[] on every attention interrupt, and out-of-bounds accesses through the input core's default keymap ioctls: EVIOCGKEYCODE reads past the buffer (leaking adjacent slab memory to user space) and EVIOCSKEYCODE writes a caller-controlled value past it, for any process able to open the evdev node, since input_default_getkeycode() and input_default_setkeycode() only bound the index against keycodemax.
Size the keymap for the full gpio_count. The mapping loop is unchanged:
it still assigns only the first min(gpio_count, TRACKSTICK_RANGE_END) entries; the remaining slots stay KEY_RESERVED (devm_kcalloc zero-fills) and are skipped when reporting.
--- drivers/input/rmi4/rmi_f3a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/rmi4/rmi_f3a.c +1 -1
@@ -132,7 +132,7 @@ static int rmi_f3a_map_gpios(struct rmi_int button_count =min_t (u8, f3a->gpio_count,TRACKSTICK_RANGE_END ); f3a->gpio_key_map =devm_kcalloc (&fn->dev, - button_count, + f3a->gpio_count,sizeof (f3a->gpio_key_map[0 ]),GFP_KERNEL );if (!f3a->gpio_key_map) {
Greg Kroah-Hartman
maintainerPATCH 236/1067 Input: synaptics-rmi4 - bound the F30 keymap to the GPIO/LED count
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit d577e46785d45484b2ab7e7309c49b18764bf56c upstream.
rmi_f30_map_gpios() allocates gpioled_key_map with min(gpioled_count, TRACKSTICK_RANGE_END) == at most 6 entries, but rmi_f30_attention() iterates the full f30->gpioled_count (device query register, range 0..31) and dereferences gpioled_key_map[i], and input->keycodemax is set to the full gpioled_count while input->keycode points at the 6-entry allocation.
A device that reports gpioled_count > 6 with GPIO support enabled therefore causes an out-of-bounds read on the attention interrupt and out-of-bounds read/write through the EVIOCGKEYCODE/EVIOCSKEYCODE ioctls, which bound the index only against keycodemax. This is the same defect as the F3A handler, which was copied from F30.
Size the keymap for the full gpioled_count; the mapping loop still assigns only the first min(gpioled_count, TRACKSTICK_RANGE_END) entries.
--- drivers/input/rmi4/rmi_f30.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/rmi4/rmi_f30.c +1 -1
@@ -233,7 +233,7 @@ static int rmi_f30_map_gpios(struct rmi_int button_count =min_t (u8, f30->gpioled_count,TRACKSTICK_RANGE_END ); f30->gpioled_key_map =devm_kcalloc (&fn->dev, - button_count, + f30->gpioled_count,sizeof (f30->gpioled_key_map[0 ]),GFP_KERNEL );if (!f30->gpioled_key_map) {
Greg Kroah-Hartman
maintainerPATCH 237/1067 Input: elan_i2c - prevent division by zero and arithmetic underflow
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ranjan Kumar <[email protected]>
commit df2b818fa009c10ff6ba875a1663ff001cda9558 upstream.
The Elan I2C touchpad driver queries the device for its physical dimensions and trace counts to calculate the device resolution and width. However, if the device firmware or device tree provides invalid zero values for x_traces or y_traces, it results in a fatal division-by-zero exception leading to a kernel panic during device probe.
Add checks to ensure these parameters are non-zero before performing the division. If invalid trace values are detected, fall back to a safe default of 1.
Additionally, prevent an arithmetic underflow in the touch reporting logic. Previously, if the calculated or fallback width was smaller than ETP_FWIDTH_REDUCE (90), the subtraction would underflow, resulting in a massive unsigned integer being reported to userspace. Clamp the adjusted width to a minimum of 0 to safely handle small physical dimensions and fallback scenarios.
Completing the probe with safe fallback values ensures the sysfs nodes are created, keeping the firmware update path intact so a recovery firmware can be flashed to the device.
--- drivers/input/mouse/elan_i2c_core.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)
drivers/input/mouse/elan_i2c_core.c +30 -6
@@ -425,8 +425,17 @@ static int elan_query_device_parameters(if (error)return error; } - data->width_x = data->max_x / x_traces; - data->width_y = data->max_y / y_traces; + +if (!x_traces || !y_traces) { +dev_warn (&client->dev, +"invalid trace numbers: x=%u, y=%u\n" , + x_traces, y_traces); + data->width_x =1 ; + data->width_y =1 ; + }else { + data->width_x = data->max_x / x_traces; + data->width_y = data->max_y / y_traces; + } if (device_property_read_u32(&client->dev, "touchscreen-x-mm", &x_mm) ||
@@ -440,8 +449,16 @@ static int elan_query_device_parameters( data->x_res =elan_convert_resolution (hw_x_res, data->pattern); data->y_res =elan_convert_resolution (hw_y_res, data->pattern); }else { - data->x_res = (data->max_x +1 ) / x_mm; - data->y_res = (data->max_y +1 ) / y_mm; +if (unlikely (x_mm ==0 || y_mm ==0 )) { +dev_warn (&client->dev, +"invalid physical dimensions: x_mm=%u, y_mm=%u\n" , + x_mm, y_mm); + data->x_res =1 ; + data->y_res =1 ; + }else { + data->x_res = (data->max_x +1 ) / x_mm; + data->y_res = (data->max_y +1 ) / y_mm; + } }if (device_property_read_bool (&client->dev,"elan,clickpad" ))
@@ -960,6 +977,7 @@ static void elan_report_contact(struct eif (data->report_features &ETP_FEATURE_REPORT_MK ) {unsigned int mk_x, mk_y, area_x, area_y; +int adj_width_x, adj_width_y;u8 mk_data = high_precision ? packet[ETP_MK_DATA_OFFSET + contact_num] : finger_data[3 ];
@@ -971,8 +989,14 @@ static void elan_report_contact(struct e* To avoid treating large finger as palm, let's reduce * the width x and y per trace. */ - area_x = mk_x * (data->width_x -ETP_FWIDTH_REDUCE ); - area_y = mk_y * (data->width_y -ETP_FWIDTH_REDUCE ); + + adj_width_x = data->width_x >ETP_FWIDTH_REDUCE ? + data->width_x -ETP_FWIDTH_REDUCE :0 ; + adj_width_y = data->width_y >ETP_FWIDTH_REDUCE ? + data->width_y -ETP_FWIDTH_REDUCE :0 ; + + area_x = mk_x * adj_width_x; + area_y = mk_y * adj_width_y;input_report_abs (input,ABS_TOOL_WIDTH , mk_x); input_report_abs(input, ABS_MT_TOUCH_MAJOR,
Greg Kroah-Hartman
maintainerPATCH 196/1067 usb: typec: ucsi: cancel pending work on system suspend
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Menzel <[email protected]>
commit 7c4a234bd31a64a8dbd0140dc812da592c5e0787 upstream.
On a Dell XPS 13 9360 (BIOS 2.21.0), entering system suspend (deep/S3) races a pending UCSI connector-change worker against the ACPI EC teardown. The worker evaluates the UCSI _DSM (GET_CONNECTOR_STATUS), whose AML accesses the Embedded Controller. By that point the ACPI EC has already been stopped for suspend, so the EC address space handler rejects the access with AE_BAD_PARAMETER, aborting the AML and failing the connector query:
[22314.689495] ACPI: EC: interrupt blocked
[22314.711981] ACPI: PM: Preparing to enter system sleep state S3
[22314.743260] ACPI: EC: event blocked
[22314.743265] ACPI: EC: EC stopped
[22314.743267] ACPI: PM: Saving platform NVS memory
[22314.744241] ACPI Error: AE_BAD_PARAMETER, Returned by Handler for [EmbeddedControl] (20260408/evregion-303)
[22314.744432] ACPI Error: Aborting method \_SB.PCI0.LPCB.ECDV.ECW1 due to previous error (AE_BAD_PARAMETER) (20260408/psparse-543)
[22314.744673] ACPI Error: Aborting method \ECWB due to previous error (AE_BAD_PARAMETER) (20260408/psparse-543)
[22314.745201] ACPI Error: Aborting method \_SB.UBTC._DSM due to previous error (AE_BAD_PARAMETER) (20260408/psparse-543)
[22314.745394] ACPI: \_SB_.UBTC: failed to evaluate _DSM c298836f-a47c-e411-ad36-631042b5008f rev:1 func:1 (0x1001)
[22314.745414] ucsi_acpi USBC000:00: ucsi_acpi_dsm: failed to evaluate _DSM 1
[22314.745424] ucsi_acpi USBC000:00: ucsi_handle_connector_change: GET_CONNECTOR_STATUS failed (-5)ucsi_acpi implements a resume callback but no suspend callback, so nothing cancels the connector-change work before the firmware/EC is torn down.
Add a ucsi_suspend() core helper that cancels the pending init and connector-change work, and wire it into ucsi_acpi's PM ops. The connector state is re-read on resume by ucsi_resume(), so cancelling the work loses nothing.
--- drivers/usb/typec/ucsi/ucsi.c | 20 ++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 1 + drivers/usb/typec/ucsi/ucsi_acpi.c | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-)
drivers/usb/typec/ucsi/ucsi.c +20 -0
@@ -1374,6 +1374,26 @@ static void ucsi_resume_work(struct work } } +int ucsi_suspend (struct ucsi *ucsi) +{ +int i; + +/* +* Cancel pending work so it cannot access the firmware after the ACPI +* EC is stopped for suspend; state is re-read on resume. +*/ +cancel_delayed_work_sync (&ucsi->work); + +if (!ucsi->connector) +return 0 ; + +for (i =0 ; i < ucsi->cap.num_connectors; i++) +cancel_work_sync (&ucsi->connector[i].work); + +return 0 ; +} +EXPORT_SYMBOL_GPL (ucsi_suspend); +int ucsi_resume (struct ucsi *ucsi) {if (ucsi->connector)
drivers/usb/typec/ucsi/ucsi.h +1 -0
@@ -351,6 +351,7 @@ int ucsi_send_command(struct ucsi *ucsi, void *retval, size_t size);void ucsi_altmode_update_active (struct ucsi_connector *con); +int ucsi_suspend (struct ucsi *ucsi);int ucsi_resume (struct ucsi *ucsi);#if IS_ENABLED (CONFIG_POWER_SUPPLY )
drivers/usb/typec/ucsi/ucsi_acpi.c +9 -1
@@ -290,6 +290,13 @@ static int ucsi_acpi_remove(struct platfreturn 0 ; } +static int ucsi_acpi_suspend (struct device *dev) +{ +struct ucsi_acpi *ua =dev_get_drvdata (dev); + +return ucsi_suspend (ua->ucsi); +} +static int ucsi_acpi_resume (struct device *dev) {struct ucsi_acpi *ua =dev_get_drvdata (dev);
@@ -297,7 +304,8 @@ static int ucsi_acpi_resume(struct devicreturn ucsi_resume (ua->ucsi); } -static DEFINE_SIMPLE_DEV_PM_OPS(ucsi_acpi_pm_ops, NULL, ucsi_acpi_resume); +static DEFINE_SIMPLE_DEV_PM_OPS(ucsi_acpi_pm_ops, ucsi_acpi_suspend, + ucsi_acpi_resume);static const struct acpi_device_id ucsi_acpi_match[] = { {"PNP0CA0" ,0 },
Greg Kroah-Hartman
maintainerPATCH 197/1067 iio: temperature: ltc2983: Fix n_wires default bypassing rotation check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liviu Stan <[email protected]>
[ Upstream commit 434c150752675f44dc52c384a7fa22e5176bc35a ]
When adi,number-of-wires is absent, n_wires is left at 0. The binding documents a default of 2 wires, matching the hardware default. However the current-rotate validation checks n_wires == 2 || n_wires == 3, so with n_wires = 0 the guard is bypassed and adi,current-rotate is accepted for a 2-wire RTD.
Initialize n_wires = 2 to match the binding default and ensure the rotation check fires correctly when the property is absent.
[ Liviu Stan: resolve conflict - keep fwnode_handle *ref declaration
which was removed upstream by a later refactor not in 6.1.y ]
--- drivers/iio/temperature/ltc2983.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/temperature/ltc2983.c +1 -1
@@ -706,7 +706,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st,int ret =0 ;struct device *dev = &st->spi->dev;struct fwnode_handle *ref; -u32 excitation_current =0 , n_wires =0 ; +u32 excitation_current =0 , n_wires =2 ; rtd =devm_kzalloc (dev,sizeof (*rtd),GFP_KERNEL );if (!rtd)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 198/1067 efivarfs: expose used and total size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anisse Astier <[email protected]>
[ Upstream commit d86ff3333cb1d5f42d8898fb5fdb304e143c0237 ]
When writing EFI variables, one might get errors with no other message on why it fails. Being able to see how much is used by EFI variables helps analyzing such issues.
Since this is not a conventional filesystem, block size is intentionally set to 1 instead of PAGE_SIZE.
x86 quirks of reserved size are taken into account; so that available and free size can be different, further helping debugging space issues.
With this patch, one can see the remaining space in EFI variable storage via efivarfs, like this:
$ df -h /sys/firmware/efi/efivars/ Filesystem Size Used Avail Use% Mounted on efivarfs 176K 106K 66K 62% /sys/firmware/efi/efivars
[ardb: - rename efi_reserved_space() to efivar_reserved_space()
- whitespace/coding style tweaks]
Adjusted for headers in linux-6.1.y
--- arch/x86/platform/efi/quirks.c | 8 +++++++ drivers/firmware/efi/efi.c | 1 + drivers/firmware/efi/vars.c | 12 +++++++++++ fs/efivarfs/super.c | 39 +++++++++++++++++++++++++++++++++- include/linux/efi.h | 11 ++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-)
arch/x86/platform/efi/quirks.c +8 -0
@@ -114,6 +114,14 @@ void efi_delete_dummy_variable(void) EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL); } +u64 efivar_reserved_space (void ) +{ +if (efi_no_storage_paranoia) +return 0 ; +return EFI_MIN_RESERVE ; +} +EXPORT_SYMBOL_GPL (efivar_reserved_space); +/* * In the nonblocking case we do not attempt to perform garbage * collection if we do not have enough free space. Rather, we do the
drivers/firmware/efi/efi.c +1 -0
@@ -211,6 +211,7 @@ static int generic_ops_register(void) generic_ops.get_variable = efi.get_variable; generic_ops.get_next_variable = efi.get_next_variable; generic_ops.query_variable_store = efi_query_variable_store; + generic_ops.query_variable_info = efi.query_variable_info;if (efi_rt_services_supported (EFI_RT_SUPPORTED_SET_VARIABLE )) { generic_ops.set_variable = efi.set_variable;
drivers/firmware/efi/vars.c +12 -0
@@ -250,3 +250,15 @@ efi_status_t efivar_set_variable(efi_char16_t *name, efi_guid_t *vendor,return status; }EXPORT_SYMBOL_NS_GPL (efivar_set_variable,EFIVAR ); + +efi_status_t efivar_query_variable_info (u32 attr, +u64 *storage_space, +u64 *remaining_space, +u64 *max_variable_size) +{ +if (!__efivars->ops->query_variable_info) +return EFI_UNSUPPORTED ; +return __efivars->ops->query_variable_info (attr, storage_space, + remaining_space, max_variable_size); +} +EXPORT_SYMBOL_NS_GPL (efivar_query_variable_info,EFIVAR );
fs/efivarfs/super.c +38 -1
@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/magic.h> #include <linux/printk.h> +#include <linux/statfs.h> #include "internal.h"
@@ -24,8 +25,44 @@ static void efivarfs_evict_inode(struct inode *inode)clear_inode (inode); } +static int efivarfs_statfs (struct dentry *dentry,struct kstatfs *buf) +{ +const u32 attr =EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS ; +u64 storage_space, remaining_space, max_variable_size; +efi_status_t status; + + status =efivar_query_variable_info (attr, &storage_space, &remaining_space, + &max_variable_size); +if (status !=EFI_SUCCESS ) +return efi_status_to_err (status); + +/* +* This is not a normal filesystem, so no point in pretending it has a block +* size; we declare f_bsize to 1, so that we can then report the exact value +* sent by EFI QueryVariableInfo in f_blocks and f_bfree +*/ + buf->f_bsize =1 ; + buf->f_namelen =NAME_MAX ; + buf->f_blocks = storage_space; + buf->f_bfree = remaining_space; + buf->f_type = dentry->d_sb->s_magic; + +/* +* In f_bavail we declare the free space that the kernel will allow writing +* when the storage_paranoia x86 quirk is active. To use more, users +* should boot the kernel with efi_no_storage_paranoia. +*/ +if (remaining_space >efivar_reserved_space ()) + buf->f_bavail = remaining_space -efivar_reserved_space (); +else + buf->f_bavail =0 ; + +return 0 ; +}static const struct super_operations efivarfs_ops = { - .statfs = simple_statfs, + .statfs = efivarfs_statfs, .drop_inode = generic_delete_inode, .evict_inode = efivarfs_evict_inode, };
include/linux/efi.h +11 -0
@@ -1039,6 +1039,7 @@ struct efivar_operations {efi_set_variable_t *set_variable;efi_set_variable_t *set_variable_nonblocking;efi_query_variable_store_t *query_variable_store; +efi_query_variable_info_t *query_variable_info; };struct efivars {
@@ -1047,6 +1048,12 @@ struct efivars {const struct efivar_operations *ops; }; +#ifdef CONFIG_X86 +u64 __attribute_const__ efivar_reserved_space(void); +#else +static inline u64 efivar_reserved_space (void ) {return 0 ; } +#endif +/* * The maximum size of VariableName + Data = 1024 * Therefore, it's reasonable to save that much
@@ -1081,6 +1088,10 @@ efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor,efi_status_t efivar_set_variable (efi_char16_t *name,efi_guid_t *vendor,u32 attr,unsigned long data_size,void *data); +efi_status_t efivar_query_variable_info (u32 attr,u64 *storage_space, +u64 *remaining_space, +u64 *max_variable_size); +#if IS_ENABLED (CONFIG_EFI_CAPSULE_LOADER )extern bool efi_capsule_pending (int *reset_type);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 199/1067 efivarfs: fix statfs() on efivarfs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Heinrich Schuchardt <[email protected]>
[ Upstream commit 79b83606abc778aa3cbee535b362ce905d0b9448 ]
Some firmware (notably U-Boot) provides GetVariable() and GetNextVariableName() but not QueryVariableInfo().
With commit d86ff3333cb1 ("efivarfs: expose used and total size") the statfs syscall was broken for such firmware.
If QueryVariableInfo() does not exist or returns EFI_UNSUPPORTED, just report the file system size as 0 as statfs_simple() previously did.
--- fs/efivarfs/super.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
fs/efivarfs/super.c +10 -4
@@ -33,10 +33,16 @@ static int efivarfs_statfs(struct dentry *dentry, struct kstatfs *buf)u64 storage_space, remaining_space, max_variable_size;efi_status_t status; - status =efivar_query_variable_info (attr, &storage_space, &remaining_space, - &max_variable_size); -if (status !=EFI_SUCCESS ) -return efi_status_to_err (status); +/* Some UEFI firmware does not implement QueryVariableInfo() */ + storage_space = remaining_space =0 ; +if (efi_rt_services_supported (EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO )) { + status =efivar_query_variable_info (attr, &storage_space, + &remaining_space, + &max_variable_size); +if (status !=EFI_SUCCESS && status !=EFI_UNSUPPORTED ) +pr_warn_ratelimited ("query_variable_info() failed: 0x%lx\n" , + status); + }/* * This is not a normal filesystem, so no point in pretending it has a block
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 200/1067 udf: validate free block extents against the partition length
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 5f0419457f89dce1a3f1c8e62a3adf2f39ab8168 upstream.
udf_free_blocks() checks the logical block number and count against the partition length, but drops the extent offset from that final bound. A crafted extent can pass the guard while logicalBlockNum + offset + count points past the partition, which later indexes past the space bitmap array.
A single ftruncate(2) on a file backed by such an extent reliably panics the kernel. This is a local availability issue. On desktop systems where UDisks/polkit allows the active user to mount removable UDF media without CAP_SYS_ADMIN, an unprivileged local user can supply the crafted filesystem and trigger the panic by truncating a writable file on it. Systems that require root or CAP_SYS_ADMIN to mount the image have a higher prerequisite.
No confidentiality or integrity impact is claimed: the reproduced primitive is an out-of-bounds read of a bitmap pointer slot followed by a kernel panic.
Use the already computed logicalBlockNum + offset + count value for the partition length check. Also make load_block_bitmap() reject an out-of-range block group before indexing s_block_bitmap[], so corrupted callers cannot walk past the flexible array.
--- fs/udf/balloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/udf/balloc.c +3 -2
@@ -86,8 +86,9 @@ static int __load_block_bitmap(struct suint nr_groups = bitmap->s_nr_groups;if (block_group >= nr_groups) { -udf_debug ("block_group (%u) > nr_groups (%d)\n" , +udf_debug ("block_group (%u) >= nr_groups (%d)\n" , block_group, nr_groups); +return -EFSCORRUPTED ; }if (bitmap->s_block_bitmap[block_group]) {
@@ -671,7 +672,7 @@ void udf_free_blocks(struct super_blockif (check_add_overflow (bloc->logicalBlockNum, offset, &blk) ||check_add_overflow (blk, count, &blk) || - bloc->logicalBlockNum + count > map->s_partition_len) { + blk > map->s_partition_len) { udf_debug("Invalid request to free blocks: (%d, %u), off %u, " "len %u, partition len %u\n", partition, bloc->logicalBlockNum, offset, count,
Greg Kroah-Hartman
maintainerPATCH 191/1067 usb: typec: class: drop PD lookup reference
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangpeng Bai <[email protected]>
commit 43ae2f90b70cda374c487c1639a01d0f14e5d583 upstream.
usb_power_delivery_find() wraps class_find_device_by_name(). That helper returns a device reference that must be released by the caller.
select_usb_power_delivery_store() only needs this reference while calling the pd_set callback. Drop it once the callback returns. Otherwise the sysfs write can pin the selected USB Power Delivery object and prevent it from being released on unregister.
--- drivers/usb/typec/class.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/typec/class.c +1 -0
@@ -1258,6 +1258,7 @@ static ssize_t select_usb_power_deliveryreturn -EINVAL ; ret = port->ops->pd_set (port, pd); +put_device (&pd->dev);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 239/1067 Input: iforce - bound the device-reported force-feedback effect index
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 0e9943d2e4c63496b6ca84bc66fd3c71d40558e2 upstream.
iforce_process_packet() handles a status report (packet id 0x02) by taking a force-feedback effect index straight from the device wire and using it to address the per-effect state array:
i = data[1] & 0x7f;
if (data[1] & 0x80) {
if (!test_and_set_bit(FF_CORE_IS_PLAYED,
iforce->core_effects[i].flags))
...
} else if (test_and_clear_bit(FF_CORE_IS_PLAYED,
iforce->core_effects[i].flags)) {
...
}The index is masked only with 0x7f, so it ranges 0..127, but core_effects[] holds only IFORCE_EFFECTS_MAX (32) entries. For an index of 32..127 the test_and_set_bit()/test_and_clear_bit() is an out-of-bounds single-bit read-modify-write past the array. core_effects[] is the second-to-last member of struct iforce, so the write lands in the trailing members and beyond the embedding kzalloc()'d iforce_serio / iforce_usb object.
data[1] is unvalidated device payload on both transports (the USB interrupt endpoint and serio), and the status path is not gated on force feedback being present, so a malicious or counterfeit device can set or clear a bit at an attacker-chosen offset past the object.
Reject an out-of-range index instead of indexing with it. Bound against the array dimension IFORCE_EFFECTS_MAX rather than dev->ff->max_effects so the check guarantees memory safety regardless of how many effects the device registered. A legitimate "effect started/stopped" status always carries an index below IFORCE_EFFECTS_MAX, so well-formed devices are unaffected; the neighbouring mark_core_as_ready() loop is already bounded and is left untouched.
--- drivers/input/joystick/iforce/iforce-packets.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +11 -7
@@ -192,14 +192,18 @@ void iforce_process_packet(struct iforce/* Check if an effect was just started or stopped */ i = data[1 ] &0x7f ; -if (data[1 ] &0x80 ) { -if (!test_and_set_bit (FF_CORE_IS_PLAYED , iforce->core_effects[i].flags)) { -/* Report play event */ -input_report_ff_status (dev, i,FF_STATUS_PLAYING ); +if (i <IFORCE_EFFECTS_MAX ) { +if (data[1 ] &0x80 ) { +if (!test_and_set_bit (FF_CORE_IS_PLAYED , + iforce->core_effects[i].flags)) { +/* Report play event */ +input_report_ff_status (dev, i,FF_STATUS_PLAYING ); + } + }else if (test_and_clear_bit (FF_CORE_IS_PLAYED , + iforce->core_effects[i].flags)) { +/* Report stop event */ +input_report_ff_status (dev, i,FF_STATUS_STOPPED ); } - }else if (test_and_clear_bit (FF_CORE_IS_PLAYED , iforce->core_effects[i].flags)) { -/* Report stop event */ -input_report_ff_status (dev, i,FF_STATUS_STOPPED ); }for (j =3 ; j < len; j +=2 )
Greg Kroah-Hartman
maintainerPATCH 248/1067 fuse: fix device node leak in cuse_process_init_reply()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alberto Ruiz <[email protected]>
commit 9fa4f7a53406430ee9982f2f636a15b338185122 upstream.
If device_add() succeeds during CUSE initialization but a subsequent step (cdev_alloc() or cdev_add()) fails, the error path calls put_device() without first calling device_del(). This leaks the devtmpfs entry created by device_add(), leaving a stale /dev/<name> node that persists until reboot.
Since the cuse_conn is never linked into cuse_conntbl on the failure path, cuse_channel_release() sees cc->dev == NULL and skips device_unregister(), so no other code path cleans up the node.
This has several consequences:
- The device name is permanently poisoned: any subsequent attempt to create a CUSE device with the same name hits the stale sysfs entry, device_add() fails, and the new device is aborted.
- The collision manifests as ENODEV returned to userspace with no dmesg diagnostic, making it very difficult to debug.
- The failure is self-perpetuating: once a name is leaked, all future attempts with that name fail identically.
Fix this by introducing an err_dev label that calls device_del() to undo device_add() before falling through to err_unlock. The existing err_unlock path from a device_add() failure correctly skips device_del() since the device was never added.
Testing instructions can be found at the lore link below.
--- fs/fuse/cuse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/fuse/cuse.c +3 -1
@@ -386,7 +386,7 @@ static void cuse_process_init_reply(stru rc = -ENOMEM ; cdev =cdev_alloc ();if (!cdev) - goto err_unlock; + goto err_dev; cdev->owner =THIS_MODULE ; cdev->ops = &cuse_frontend_fops;
@@ -412,6 +412,8 @@ out: err_cdev:cdev_del (cdev); +err_dev: +device_del (dev); err_unlock:mutex_unlock (&cuse_lock);put_device (dev);
Greg Kroah-Hartman
maintainerPATCH 249/1067 fuse: re-lock request before returning from fuse_ref_folio()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
commit b5befa80fdbe287a98480effed9564712924add5 upstream.
fuse_ref_folio() unlocks the request but does not re-lock it before returning. fuse_chan_abort() can end the request and the async end callback (eg fuse_writepage_free()) can free the args while the subsequent copy chain logic after fuse_ref_folio() accesses them, leading to use-after-free issues.
Fix this by locking the request in fuse_ref_folio() before returning.
--- fs/fuse/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev.c +1 -1
@@ -908,7 +908,7 @@ static int fuse_ref_page(struct fuse_cop cs->nr_segs++; cs->len =0 ; -return 0 ; +return lock_request (cs->req); }/*
Greg Kroah-Hartman
maintainerPATCH 250/1067 ipv4: account for fraggap on the paged allocation path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wongi Lee <[email protected]>
commit eca856950f7cb1a221e02b99d758409f2c5cec42 upstream.
In __ip_append_data(), when the paged-allocation branch is taken, alloclen and pagedlen are computed as
alloclen = fragheaderlen + transhdrlen; pagedlen = datalen - transhdrlen;
datalen already includes fraggap, but the fraggap bytes carried over from the previous skb are copied into the new skb's linear area at offset transhdrlen by the subsequent skb_copy_and_csum_bits(). The linear area is therefore undersized by fraggap bytes while pagedlen is overstated by the same amount.
The non-paged branch sets alloclen to fraglen, which already accounts for fraggap because datalen does. Bring the paged branch in line by adding fraggap to alloclen and subtracting it from pagedlen.
After this adjustment, copy no longer collapses to -fraggap on the paged path, so remove the stale comment describing that old arithmetic.
--- net/ipv4/ip_output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/ip_output.c +2 -2
@@ -1117,8 +1117,8 @@ alloc_new_skb: !(rt->dst.dev->features & NETIF_F_SG))) alloclen = fraglen; else { - alloclen = fragheaderlen + transhdrlen; - pagedlen = datalen - transhdrlen; + alloclen = fragheaderlen + transhdrlen + fraggap; + pagedlen = datalen - transhdrlen - fraggap; } alloclen += alloc_extra;
Greg Kroah-Hartman
maintainerPATCH 251/1067 smb: client: reject overlapping data areas in SMB2 responses
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shoichiro Miyamoto <[email protected]>
commit 8986c932905ea508d66da421eb2eb6e676ace1fe upstream.
Commit 53b7c271f06b ("smb: client: restrict implied bcc[0] exemption to responses without data area") restricted the implied bcc[0] length exception to responses without a data area. However, the overlap handling in __smb2_calc_size() clears data_length, which can make an invalid response appear to have no data area and so qualify for the exception.
Track data area overlap separately and reject such responses before applying the length compatibility exceptions.
--- fs/smb/client/smb2misc.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
fs/smb/client/smb2misc.c +25 -9
@@ -18,7 +18,8 @@#include "nterr.h" #include "cached_dir.h" -static unsigned int __smb2_calc_size (void *buf,bool *have_data); +static unsigned int __smb2_calc_size (void *buf,bool *have_data, +bool *data_area_overlap);static int check_smb2_hdr (struct smb2_hdr *shdr,__u64 mid)
@@ -146,6 +147,7 @@ smb2_check_message(char *buf, unsigned i__u32 calc_len;/* calculated length */ __u64 mid;bool have_data; +bool data_area_overlap;/* If server is a channel, select the primary channel */ pserver =CIFS_SERVER_IS_CHAN (server) ? server->primary_server : server;
@@ -230,7 +232,12 @@ smb2_check_message(char *buf, unsigned i } have_data = false; - calc_len =__smb2_calc_size (buf, &have_data); + data_area_overlap = false; + calc_len =__smb2_calc_size (buf, &have_data, &data_area_overlap); + +/* Reject responses whose data area overlaps the fixed area. */ +if (data_area_overlap) +return 1 ;/* For SMB2_IOCTL, OutputOffset and OutputLength are optional, so might * be 0, and not a real miscalculation */
@@ -414,14 +421,15 @@ smb2_get_data_area_len(int *off, int *le }/* -* Calculate the size of the SMB message based on the fixed header -* portion, the number of word parameters and the data portion of the message. -* If have_data is non-NULL, it is set to true when a non-empty data area was -* found (data_length > 0), allowing callers to distinguish the implied bcc[0] -* case (no data area) from an overreported data length. +* Calculate the size of the SMB message based on the fixed header, fixed +* parameter area, and variable data area. +* +* If have_data is not NULL, it is set when a non-empty data area is found. +* If data_area_overlap is not NULL, it is set when the data area overlaps +* the fixed area. */ static unsigned int -__smb2_calc_size (void *buf,bool *have_data) +__smb2_calc_size (void *buf,bool *have_data,bool *data_area_overlap) {struct smb2_pdu *pdu = buf;struct smb2_hdr *shdr = &pdu->hdr;
@@ -430,6 +438,11 @@ __smb2_calc_size(void *buf, bool *have_d/* Structure Size has already been checked to make sure it is 64 */ int len =le16_to_cpu (shdr->StructureSize); +if (have_data) + *have_data = false; +if (data_area_overlap) + *data_area_overlap = false; +/* * StructureSize2, ie length of fixed parameter area has already * been checked to make sure it is the correct length.
@@ -452,7 +465,10 @@ __smb2_calc_size(void *buf, bool *have_dif (offset +1 < len) {cifs_dbg (VFS ,"data area offset %d overlaps SMB2 header %d\n" , offset +1 , len); +if (data_area_overlap) + *data_area_overlap = true; data_length =0 ; + goto calc_size_exit; }else { len = offset + data_length; }
@@ -467,7 +483,7 @@ calc_size_exit:unsigned int smb2_calc_size (void *buf) { -return __smb2_calc_size (buf,NULL ); +return __smb2_calc_size (buf,NULL ,NULL ); }/* Note: caller must free return buffer */
Greg Kroah-Hartman
maintainerPATCH 252/1067 xfs: fail recovery on a committed log item with no regions
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit 2094dab19d45c487285617b7b68913d0cc0c1211 upstream.
If the first op of a transaction is a bare transaction header (len == sizeof(struct xfs_trans_header)), xlog_recover_add_to_trans() adds an item but no region, leaving it on r_itemq with ri_cnt == 0 and ri_buf == NULL.
The header can be split across op records, so later ops may still add regions; the item is only invalid if the transaction commits with none. The runtime commit path never emits such a transaction, so this only happens on a crafted log. It came from an AI-assisted code audit of the recovery parser.
xlog_recover_reorder_trans() calls ITEM_TYPE() on the item, which reads *(unsigned short *)item->ri_buf[0].iov_base and faults on the NULL ri_buf. Reject it there, before the commit handlers that also read ri_buf[0].
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:xlog_recover_reorder_trans (fs/xfs/xfs_log_recover.c:1836) xlog_recover_commit_trans (fs/xfs/xfs_log_recover.c:2043) xlog_recover_process_data (fs/xfs/xfs_log_recover.c:2501) xlog_do_recovery_pass (fs/xfs/xfs_log_recover.c:3244) xlog_recover (fs/xfs/xfs_log_recover.c:3493) xfs_log_mount (fs/xfs/xfs_log.c:618) xfs_mountfs (fs/xfs/xfs_mount.c:1034) xfs_fs_fill_super (fs/xfs/xfs_super.c:1938) vfs_get_tree (fs/super.c:1695) path_mount (fs/namespace.c:4161) __x64_sys_mount (fs/namespace.c:4367)
--- fs/xfs/xfs_log_recover.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/xfs/xfs_log_recover.c +9 -0
@@ -1878,6 +1878,15 @@ xlog_recover_reorder_trans(list_for_each_entry_safe (item, n, &sort_list, ri_list) {enum xlog_recover_reorder fate =XLOG_REORDER_ITEM_LIST ; +/* a committed item with no regions has a NULL ri_buf[0] */ +if (!item->ri_cnt || !item->ri_buf) { +xfs_warn (log->l_mp, +"%s: committed log item has no regions" , + __func__); + error = -EFSCORRUPTED ; +break ; + } + item->ri_ops =xlog_find_item_ops (item);if (!item->ri_ops) { xfs_warn(log->l_mp,
Greg Kroah-Hartman
maintainerPATCH 253/1067 xfs: resample the data fork mapping after cycling ILOCK
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 2f4acd0fcd862e22eab45690ec2c08c80b6ef2e7 upstream.
xfs_reflink_fill_{cow_hole,delalloc} are both presented with an inode, a data fork mapping, and a cow fork mapping. Unfortunately, these two helpers cycle the ILOCK to grab a transaction, which means that the mappings are stale as soon as we reacquire the ILOCK. Currently we refresh the cow fork mapping by re-calling xfs_find_trim_cow_extent, but we don't refresh the data fork mapping beforehand, which means that the xfs_bmap_trim_cow in that function queries the refcount btree about the wrong physical blocks and returns an inaccurate value in *shared.
If *shared is now false, the directio write proceeds with a stale data fork mapping. Fix this by querying the data fork mapping if the sequence counter changes across the ILOCK cycle.
--- fs/xfs/xfs_reflink.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
fs/xfs/xfs_reflink.c +36 -0
@@ -389,6 +389,7 @@ xfs_reflink_fill_cow_hole(struct xfs_trans *tp;xfs_filblks_t resaligned;xfs_extlen_t resblks; +unsigned int seq_before =READ_ONCE (ip->i_df.if_seq);int nimaps;int error;bool found;
@@ -407,6 +408,22 @@ xfs_reflink_fill_cow_hole( *lockmode =XFS_ILOCK_EXCL ; +/* +* The data fork mapping may have changed while we dropped the ILOCK +* (a racing O_DIRECT writer under IOLOCK_SHARED can complete a full +* CoW cycle including xfs_reflink_end_cow(), which remaps this offset +* and drops the refcount of the old shared block). Re-read it so the +* shared-status recheck below and the caller's in-place iomap both +* operate on the current mapping rather than a stale physical block. +*/ +if (seq_before !=READ_ONCE (ip->i_df.if_seq)) { + nimaps =1 ; + error =xfs_bmapi_read (ip, imap->br_startoff, + imap->br_blockcount, imap, &nimaps,0 ); +if (error) + goto out_trans_cancel; + } + error =xfs_find_trim_cow_extent (ip, imap, cmap, shared, &found);if (error || !*shared) goto out_trans_cancel;
@@ -455,6 +472,8 @@ xfs_reflink_fill_delalloc(bool found; do { + unsigned int seq_before = READ_ONCE(ip->i_df.if_seq); + xfs_iunlock(ip, *lockmode); *lockmode = 0;
@@ -465,6 +484,23 @@ xfs_reflink_fill_delalloc( *lockmode =XFS_ILOCK_EXCL ; +/* +* The data fork mapping may have changed while we dropped the +* ILOCK (a racing O_DIRECT writer under IOLOCK_SHARED can +* complete a full CoW cycle including xfs_reflink_end_cow(), +* which remaps this offset and drops the refcount of the old +* shared block). Re-read it so the shared-status recheck +* below and the caller's in-place iomap both operate on the +* current mapping rather than a stale physical block. +*/ +if (seq_before !=READ_ONCE (ip->i_df.if_seq)) { + nimaps =1 ; + error =xfs_bmapi_read (ip, imap->br_startoff, + imap->br_blockcount, imap, &nimaps,0 ); +if (error) + goto out_trans_cancel; + } + error =xfs_find_trim_cow_extent (ip, imap, cmap, shared, &found);if (error || !*shared)
Greg Kroah-Hartman
maintainerPATCH 254/1067 smb/server: do not require delete access for non-replacing links
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: ChenXiaoSong <[email protected]>
[ Upstream commit 851ed9e09639e0daf79a506ce26097b296ed5518 ]
Reproducer:
1. server: systemctl start ksmbd
2. client: mount -t cifs //${server_ip}/export /mnt
3. client: touch /mnt/file; ln /mnt/file /mnt/hardlink
4. client err log: ln: failed to create hard link 'hardlink' => 'file': Permission denied
5. server err log: ksmbd: no right to delete : 0x80
--- fs/smb/server/smb2pdu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/smb/server/smb2pdu.c +8 -6
@@ -6060,16 +6060,18 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp, }case FILE_LINK_INFORMATION : { -if (!(fp->daccess &FILE_DELETE_LE )) { -pr_err ("no right to delete : 0x%x\n" , fp->daccess); -return -EACCES ; - } +struct smb2_file_link_info *file_info;if (buf_len <sizeof (struct smb2_file_link_info ))return -EINVAL ; -return smb2_create_link (work, work->tcon->share_conf, - (struct smb2_file_link_info *)buffer, + file_info = (struct smb2_file_link_info *)buffer; +if (file_info->ReplaceIfExists && !(fp->daccess &FILE_DELETE_LE )) { +pr_err ("no right to delete : 0x%x\n" , fp->daccess); +return -EACCES ; + } + +return smb2_create_link (work, work->tcon->share_conf, file_info, buf_len, fp->filp, work->conn->local_nls); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 255/1067 sched/fair: Only update stats for allowed CPUs when looking for dst group
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adam Li <[email protected]>
[ Upstream commit 82d6e01a0699800efd8b048eb584c907ccb47b7a ]
Load imbalance is observed when the workload frequently forks new threads. Due to CPU affinity, the workload can run on CPU 0-7 in the first group, and only on CPU 8-11 in the second group. CPU 12-15 are always idle.
{ 0 1 2 3 4 5 6 7 } {8 9 10 11 12 13 14 15}
* * * * * * * * * * * *
When looking for dst group for newly forked threads, in many times update_sg_wakeup_stats() reports the second group has more idle CPUs than the first group. The scheduler thinks the second group is less busy. Then it selects least busy CPUs among CPU 8-11. Therefore CPU 8-11 can be crowded with newly forked threads, at the same time CPU 0-7 can be idle.
A task may not use all the CPUs in a schedule group due to CPU affinity. Only update schedule group statistics for allowed CPUs.
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
@@ -9550,7 +9550,7 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd,if (sd->flags &SD_ASYM_CPUCAPACITY ) sgs->group_misfit_task_load =1 ; -for_each_cpu (i,sched_group_span (group)) { +for_each_cpu_and (i,sched_group_span (group), p->cpus_ptr) {struct rq *rq =cpu_rq (i);unsigned int local;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 256/1067 fs: quota: create dedicated workqueue for quota_release_work
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shashank A P <[email protected]>
commit 72b7ceca857f38a8ca7c5629feffc63769638974 upstream.
There is a kernel panic due to WARN_ONCE when panic_on_warn is set.
This issue occurs when writeback is triggered due to sync call for an opened file(ie, writeback reason is WB_REASON_SYNC). When f2fs balance is needed at sync path, flush for quota_release_work is triggered. By default quota_release_work is queued to "events_unbound" queue which does not have WQ_MEM_RECLAIM flag. During f2fs balance "writeback" workqueue tries to flush quota_release_work causing kernel panic due to MEM_RECLAIM flag mismatch errors.
This patch creates dedicated workqueue with WQ_MEM_RECLAIM flag for work quota_release_work.
------------[ cut here ]------------ WARNING: CPU: 4 PID: 14867 at kernel/workqueue.c:3721 check_flush_dependency+0x13c/0x148 Call trace: check_flush_dependency+0x13c/0x148 __flush_work+0xd0/0x398 flush_delayed_work+0x44/0x5c dquot_writeback_dquots+0x54/0x318 f2fs_do_quota_sync+0xb8/0x1a8 f2fs_write_checkpoint+0x3cc/0x99c f2fs_gc+0x190/0x750 f2fs_balance_fs+0x110/0x168 f2fs_write_single_data_page+0x474/0x7dc f2fs_write_data_pages+0x7d0/0xd0c do_writepages+0xe0/0x2f4 __writeback_single_inode+0x44/0x4ac writeback_sb_inodes+0x30c/0x538 wb_writeback+0xf4/0x440 wb_workfn+0x128/0x5d4 process_scheduled_works+0x1c4/0x45c worker_thread+0x32c/0x3e8 kthread+0x11c/0x1b0 ret_from_fork+0x10/0x20 Kernel panic - not syncing: kernel: panic_on_warn set ...
--- fs/quota/dquot.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/quota/dquot.c +9 -1
@@ -163,6 +163,9 @@ static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES;/* SLAB cache for dquot structures */ static struct kmem_cache *dquot_cachep; +/* workqueue for work quota_release_work*/ +static struct workqueue_struct *quota_unbound_wq; +int register_quota_format (struct quota_format_type *fmt) {spin_lock (&dq_list_lock);
@@ -916,7 +919,7 @@ void dqput(struct dquot *dquot)put_releasing_dquots (dquot);atomic_dec (&dquot->dq_count);spin_unlock (&dq_list_lock); -queue_delayed_work (system_unbound_wq, "a_release_work,1 ); +queue_delayed_work (quota_unbound_wq, "a_release_work,1 ); }EXPORT_SYMBOL (dqput);
@@ -3091,6 +3094,11 @@ static int __init dquot_init(void)if (register_shrinker (&dqcache_shrinker,"dquota-cache" ))panic ("Cannot register dquot shrinker" ); + quota_unbound_wq =alloc_workqueue ("quota_events_unbound" , +WQ_UNBOUND |WQ_MEM_RECLAIM ,WQ_MAX_ACTIVE ); +if (!quota_unbound_wq) +panic ("Cannot create quota_unbound_wq\n" ); +return 0 ; }fs_initcall (dquot_init);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 257/1067 crypto: algif_skcipher - force synchronous processing on trees without ctx->state
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammet Kaan KILINÇ <[email protected]>
The AIO/async path in skcipher_recvmsg() passes the socket-wide ctx->iv directly into the skcipher request. After io_submit() the socket lock is dropped and the request is processed asynchronously, so a concurrent sendmsg(ALG_SET_IV) can overwrite ctx->iv and make the in-flight request run under an attacker-controlled IV. For CTR/stream modes this is IV/keystream reuse and lets an unprivileged user recover the plaintext of a concurrent operation.
Snapshotting ctx->iv into per-request storage for the async path is not sufficient. For ciphers with statesize == 0 - which includes cbc and ctr - the MSG_MORE inter-chunk IV chaining is carried solely by the in-place req->iv writeback, which a snapshot redirects into per-request memory that af_alg_free_resources() releases on completion, silently producing wrong output. Writing the IV back from the completion callback instead is not possible either: that would require lock_sock() there, but the callback can run in softirq/atomic context, so it must not sleep.
Make the operation synchronous instead, which removes both the IV race and any writeback race. This is equivalent to the upstream resolution, commit fcc77d33a34c ("net: Remove support for AIO on sockets"), which removed the AIO socket path across net/ entirely and so produces the same end state for this file. This patch deviates from that commit deliberately: rather than removing AIO socket support tree-wide, which would be far too invasive for stable, it removes only the AIO branch in crypto/algif_skcipher.c. io_submit() now completes synchronously; AF_ALG async is rarely used in practice.
The -EIOCBQUEUED check in skcipher_recvmsg() is now dead but harmless, and is left alone to keep the fix minimal.
Tested on 6.6.y: attacker IV injection dropped from 2296/200000 to 0/200000 after the change; MSG_MORE chunked CTR output bit-identical to single-shot.
--- crypto/algif_skcipher.c | 49 +++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 31 deletions(-)
crypto/algif_skcipher.c +18 -31
@@ -107,37 +107,24 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,skcipher_request_set_crypt (&areq->cra_u.skcipher_req, areq->tsgl, areq->first_rsgl.sgl.sg, len, ctx->iv); -if (msg->msg_iocb && !is_sync_kiocb (msg->msg_iocb)) { -/* AIO operation */ -sock_hold (sk); - areq->iocb = msg->msg_iocb; - -/* Remember output size that will be generated. */ - areq->outlen = len; - -skcipher_request_set_callback (&areq->cra_u.skcipher_req, -CRYPTO_TFM_REQ_MAY_SLEEP , - af_alg_async_cb, areq); - err = ctx->enc ? -crypto_skcipher_encrypt (&areq->cra_u.skcipher_req) : -crypto_skcipher_decrypt (&areq->cra_u.skcipher_req); - -/* AIO operation in progress */ -if (err == -EINPROGRESS ) -return -EIOCBQUEUED ; - -sock_put (sk); - }else { -/* Synchronous operation */ -skcipher_request_set_callback (&areq->cra_u.skcipher_req, -CRYPTO_TFM_REQ_MAY_SLEEP | -CRYPTO_TFM_REQ_MAY_BACKLOG , - crypto_req_done, &ctx->wait); - err =crypto_wait_req (ctx->enc ? -crypto_skcipher_encrypt (&areq->cra_u.skcipher_req) : -crypto_skcipher_decrypt (&areq->cra_u.skcipher_req), - &ctx->wait); - } +/* +* Force synchronous processing. The async (AIO) path passed the +* socket-wide ctx->iv into the request, which the worker +* dereferenced after the socket lock was dropped, letting a +* concurrent sendmsg(ALG_SET_IV) inject an attacker IV. Mainline +* removed the AIO socket path in commit fcc77d33a34c ("net: Remove +* support for AIO on sockets"); these stable trees lack the +* per-request ctx->state used by newer kernels, so the minimal safe +* fix is to always complete synchronously. +*/ +skcipher_request_set_callback (&areq->cra_u.skcipher_req, +CRYPTO_TFM_REQ_MAY_SLEEP | +CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &ctx->wait); + err =crypto_wait_req (ctx->enc ? +crypto_skcipher_encrypt (&areq->cra_u.skcipher_req) : +crypto_skcipher_decrypt (&areq->cra_u.skcipher_req), + &ctx->wait); free:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 240/1067 Input: touchwin - reset the packet index on every complete packet
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 478cdd736f2ce3114f90e775d7358136d3977b94 upstream.
tw_interrupt() accumulates each non-zero serial byte into a fixed three-byte buffer with a running index that is only reset once a full packet has been received *and* the device's two Y bytes agree:
tw->data[tw->idx++] = data;
if (tw->idx == TW_LENGTH && tw->data[1] == tw->data[2]) {
...
tw->idx = 0;
}The reset is gated on tw->data[1] == tw->data[2], a value the device controls. A malicious, malfunctioning or counterfeit Touchwindow peripheral can stream non-zero bytes whose 2nd and 3rd bytes differ: the index reaches TW_LENGTH without the equality holding, is never reset, and keeps growing, so tw->data[tw->idx++] walks off the end of the three-byte array and the rest of the heap-allocated struct tw, one attacker-chosen byte at a time -- an unbounded, device-driven heap out-of-bounds write.
Reset the index on every completed packet and report an event only when the two Y bytes match, like the other serio touchscreen drivers do.
--- drivers/input/touchscreen/touchwin.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/input/touchscreen/touchwin.c +9 -6
@@ -63,12 +63,15 @@ static irqreturn_t tw_interrupt(struct sif (data) {/* touch */ tw->touched =1 ; tw->data[tw->idx++] = data; -/* verify length and that the two Y's are the same */ -if (tw->idx ==TW_LENGTH && tw->data[1 ] == tw->data[2 ]) { -input_report_abs (dev,ABS_X , tw->data[0 ]); -input_report_abs (dev,ABS_Y , tw->data[1 ]); -input_report_key (dev,BTN_TOUCH ,1 ); -input_sync (dev); +/* a full packet ends the accumulation, valid or not */ +if (tw->idx ==TW_LENGTH ) { +/* report only if the two Y's are the same */ +if (tw->data[1 ] == tw->data[2 ]) { +input_report_abs (dev,ABS_X , tw->data[0 ]); +input_report_abs (dev,ABS_Y , tw->data[1 ]); +input_report_key (dev,BTN_TOUCH ,1 ); +input_sync (dev); + } tw->idx =0 ; } }else if (tw->touched) {/* untouch */
Greg Kroah-Hartman
maintainerPATCH 258/1067 tools/mm/slabinfo: fix total_objects attribute name
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
[ Upstream commit 892a7864730775c3dbee2a39e9ead4fa8d4256e7 ]
SLUB exports the total_objects sysfs attribute, but slabinfo tries to read objects_total. As a result, the lookup fails and the field remains zero.
Use the correct attribute name and rename the corresponding structure member to match.
--- tools/vm/slabinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/vm/slabinfo.c +2 -2
@@ -33,7 +33,7 @@ struct slabinfo {unsigned int hwcache_align, object_size, objs_per_slab;unsigned int sanity_checks, slab_size, store_user, trace;int order, poison, reclaim_account, red_zone; -unsigned long partial, objects, slabs, objects_partial, objects_total; +unsigned long partial, objects, slabs, objects_partial, total_objects;unsigned long alloc_fastpath, alloc_slowpath;unsigned long free_fastpath, free_slowpath;unsigned long free_frozen, free_add_partial, free_remove_partial;
@@ -1254,7 +1254,7 @@ static void read_slab_dir(void) slab->object_size =get_obj ("object_size" ); slab->objects =get_obj ("objects" ); slab->objects_partial =get_obj ("objects_partial" ); - slab->objects_total =get_obj ("objects_total" ); + slab->total_objects =get_obj ("total_objects" ); slab->objs_per_slab =get_obj ("objs_per_slab" ); slab->order =get_obj ("order" ); slab->partial =get_obj ("partial" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 259/1067 net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Oltean <[email protected]>
[ Upstream commit 499b2491d550677b824b828ff431e4ef4d1d3b9d ]
skb_mac_header() will no longer be available in the TX path when reverting commit 6d1ccff62780 ("net: reset mac header in dev_start_xmit()"). As preparation for that, let's use skb_eth_hdr() to get to the Ethernet header's MAC DA instead, helper which assumes this header is located at skb->data (assumption which holds true here).
[ sashal: adjusted context in ksz9477_xmit() and ksz9893_xmit() for
missing tail tag PRIO support in 6.1 ]
--- net/dsa/tag_ksz.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
net/dsa/tag_ksz.c +9 -9
@@ -50,18 +50,18 @@ static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,static struct sk_buff *ksz8795_xmit (struct sk_buff *skb,struct net_device *dev) {struct dsa_port *dp =dsa_slave_to_port (dev); +struct ethhdr *hdr;u8 *tag; -u8 *addr;if (skb->ip_summed ==CHECKSUM_PARTIAL &&skb_checksum_help (skb))return NULL ;/* Tag encoding */ tag =skb_put (skb,KSZ_INGRESS_TAG_LEN ); - addr =skb_mac_header (skb); + hdr =skb_eth_hdr (skb); *tag =1 << dp->index; -if (is_link_local_ether_addr (addr)) +if (is_link_local_ether_addr (hdr->h_dest)) *tag |=KSZ8795_TAIL_TAG_OVERRIDE ;return skb;
@@ -118,8 +118,8 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, struct net_device *dev) {struct dsa_port *dp =dsa_slave_to_port (dev); +struct ethhdr *hdr;__be16 *tag; -u8 *addr;u16 val;if (skb->ip_summed ==CHECKSUM_PARTIAL &&skb_checksum_help (skb))
@@ -127,11 +127,11 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb,/* Tag encoding */ tag =skb_put (skb,KSZ9477_INGRESS_TAG_LEN ); - addr =skb_mac_header (skb); + hdr =skb_eth_hdr (skb); val =BIT (dp->index); -if (is_link_local_ether_addr (addr)) +if (is_link_local_ether_addr (hdr->h_dest)) val |=KSZ9477_TAIL_TAG_OVERRIDE ; *tag =cpu_to_be16 (val);
@@ -177,7 +177,7 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb, struct net_device *dev) {struct dsa_port *dp =dsa_slave_to_port (dev); -u8 *addr; +struct ethhdr *hdr;u8 *tag;if (skb->ip_summed ==CHECKSUM_PARTIAL &&skb_checksum_help (skb))
@@ -185,11 +185,11 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,/* Tag encoding */ tag =skb_put (skb,KSZ_INGRESS_TAG_LEN ); - addr =skb_mac_header (skb); + hdr =skb_eth_hdr (skb); *tag =BIT (dp->index); -if (is_link_local_ether_addr (addr)) +if (is_link_local_ether_addr (hdr->h_dest)) *tag |=KSZ9893_TAIL_TAG_OVERRIDE ;return skb;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 260/1067 nvmet-tcp: check INIT_FAILED before nvmet_req_uninit in digest error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivam Kumar <[email protected]>
commit 4606467a75cfc16721937272ed29462a750b60c8 upstream.
In nvmet_tcp_try_recv_ddgst(), when a data digest mismatch is detected, nvmet_req_uninit() is called unconditionally. However, if the command arrived via the nvmet_tcp_handle_req_failure() path, nvmet_req_init() had returned false and percpu_ref_tryget_live() was never executed. The unconditional percpu_ref_put() inside nvmet_req_uninit() then causes a refcount underflow, leading to a WARNING in percpu_ref_switch_to_atomic_rcu, a use-after-free diagnostic, and eventually a permanent workqueue deadlock.
Check cmd->flags & NVMET_TCP_F_INIT_FAILED before calling nvmet_req_uninit(), matching the existing pattern in nvmet_tcp_execute_request().
--- drivers/nvme/target/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/target/tcp.c +2 -1
@@ -1258,7 +1258,8 @@ static int nvmet_tcp_try_recv_ddgst(stru queue->idx, cmd->req.cmd->common.command_id, queue->pdu.cmd.hdr.type,le32_to_cpu (cmd->recv_ddgst), le32_to_cpu(cmd->exp_ddgst)); -nvmet_req_uninit (&cmd->req); +if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_req_uninit (&cmd->req);nvmet_tcp_free_cmd_buffers (cmd);nvmet_tcp_fatal_error (queue); ret = -EPROTO ;
Greg Kroah-Hartman
maintainerPATCH 261/1067 nvmet-tcp: Fix potential UAF when ddgst mismatch
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sagi Grimberg <[email protected]>
commit dbbd07d0a7020b80f6a7028e561908f7b83b3d5a upstream.
Shivam Kumar found via vulnerability testing:
When data digest is enabled on an NVMe/TCP connection and a digest mismatch occurs on a non-final H2C_DATA PDU during an R2T-based data transfer, the digest error handler in nvmet_tcp_try_recv_ddgst() calls nvmet_req_uninit() — which performs percpu_ref_put() on the submission queue — but does NOT mark the command as completed. It does not set cqe->status, does not modify rbytes_done, and does not clear any flag. When the subsequent fatal error triggers queue teardown, nvmet_tcp_uninit_data_in_cmds() iterates all commands, checks nvmet_tcp_need_data_in() for each one, and finds that the already-uninited command still appears to need data (because rbytes_done < transfer_len and cqe->status == 0). It therefore calls nvmet_req_uninit() a second time on the same command — a double percpu_ref_put against a single percpu_ref_get.
--- drivers/nvme/target/tcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/target/tcp.c +3 -1
@@ -1258,8 +1258,10 @@ static int nvmet_tcp_try_recv_ddgst(stru queue->idx, cmd->req.cmd->common.command_id, queue->pdu.cmd.hdr.type,le32_to_cpu (cmd->recv_ddgst), le32_to_cpu(cmd->exp_ddgst)); -if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED )) +if (!(cmd->flags &NVMET_TCP_F_INIT_FAILED )) { + cmd->req.cqe->status =NVME_SC_CMD_SEQ_ERROR ;nvmet_req_uninit (&cmd->req); + }nvmet_tcp_free_cmd_buffers (cmd);nvmet_tcp_fatal_error (queue); ret = -EPROTO ;
Greg Kroah-Hartman
maintainerPATCH 262/1067 crypto: sun4i-ss - Remove insecure and unused rng_alg
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit b2c41fa9dd8fc740c489e060b199165771f268d1 upstream.
Remove sun4i_ss_rng, as it is insecure and unused:
- It has multiple vulnerabilities. sun4i_ss_prng_seed() is missing locking and has a buffer overflow. sun4i_ss_prng_generate() fails to fill the entire buffer with cryptographic random bytes, because it rounds the destination length down and also doesn't actually wait for the hardware to be ready before pulling bytes from it.
- No user of this code is known. It's usable only theoretically via the "rng" algorithm type of AF_ALG. But userspace actually just uses the actual Linux RNG (/dev/random etc) instead. And rng_algs don't contribute entropy to the actual Linux RNG either. (This may have been confused with hwrng, which does contribute entropy.)
The sun4i_ss_prng_seed() buffer overflow was reported by Tianchu Chen and discovered by Atuin - Automated Vulnerability Discovery Engine
There's no point in fixing all these vulnerabilities individually when this is unused code, so let's just remove it.
--- arch/arm/configs/sunxi_defconfig | 1 - drivers/crypto/allwinner/Kconfig | 8 --- drivers/crypto/allwinner/sun4i-ss/Makefile | 1 - .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 36 ---------- .../crypto/allwinner/sun4i-ss/sun4i-ss-prng.c | 69 ------------------- drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h | 20 ------ 6 files changed, 135 deletions(-) delete mode 100644 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
arch/arm/configs/sunxi_defconfig +0 -1
@@ -170,7 +170,6 @@ CONFIG_ROOT_NFS=y CONFIG_NLS_CODEPAGE_437=y CONFIG_NLS_ISO8859_1=y CONFIG_CRYPTO_DEV_SUN4I_SS=y -CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG=y CONFIG_CRYPTO_DEV_SUN8I_CE=y CONFIG_CRYPTO_DEV_SUN8I_SS=y CONFIG_DMA_CMA=y
drivers/crypto/allwinner/Kconfig +0 -8
@@ -24,14 +24,6 @@ config CRYPTO_DEV_SUN4I_SS To compile this driver as a module, choose M here: the module will be called sun4i-ss. -config CRYPTO_DEV_SUN4I_SS_PRNG - bool "Support for Allwinner Security System PRNG" - depends on CRYPTO_DEV_SUN4I_SS - select CRYPTO_RNG - help - Select this option if you want to provide kernel-side support for - the Pseudo-Random Number Generator found in the Security System. - config CRYPTO_DEV_SUN4I_SS_DEBUG bool "Enable sun4i-ss stats" depends on CRYPTO_DEV_SUN4I_SS
drivers/crypto/allwinner/sun4i-ss/Makefile +0 -1
@@ -1,4 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sun4i-ss.o sun4i-ss-y += sun4i-ss-core.o sun4i-ss-hash.o sun4i-ss-cipher.o -sun4i-ss-$(CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG) += sun4i-ss-prng.o
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c +0 -36
@@ -216,23 +216,6 @@ static struct sun4i_ss_alg_template ss_algs[] = { } } }, -#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG -{ - .type = CRYPTO_ALG_TYPE_RNG, - .alg.rng = { - .base = { - .cra_name = "stdrng", - .cra_driver_name = "sun4i_ss_rng", - .cra_priority = 300, - .cra_ctxsize = 0, - .cra_module = THIS_MODULE, - }, - .generate = sun4i_ss_prng_generate, - .seed = sun4i_ss_prng_seed, - .seedsize = SS_SEED_LEN / BITS_PER_BYTE, - } -}, -#endif };static int sun4i_ss_debugfs_show (struct seq_file *seq,void *v)
@@ -250,12 +233,6 @@ static int sun4i_ss_debugfs_show(struct seq_file *seq, void *v) ss_algs[i].stat_req, ss_algs[i].stat_opti, ss_algs[i].stat_fb, ss_algs[i].stat_bytes);break ; -case CRYPTO_ALG_TYPE_RNG : -seq_printf (seq,"%s %s reqs=%lu tsize=%lu\n" , - ss_algs[i].alg.rng.base.cra_driver_name, - ss_algs[i].alg.rng.base.cra_name, - ss_algs[i].stat_req, ss_algs[i].stat_bytes); -break ;case CRYPTO_ALG_TYPE_AHASH : seq_printf(seq, "%s %s reqs=%lu\n", ss_algs[i].alg.hash.halg.base.cra_driver_name,
@@ -474,13 +451,6 @@ static int sun4i_ss_probe(struct platform_device *pdev) goto error_alg; }break ; -case CRYPTO_ALG_TYPE_RNG : - err =crypto_register_rng (&ss_algs[i].alg.rng); -if (err) { -dev_err (ss->dev,"Fail to register %s\n" , - ss_algs[i].alg.rng.base.cra_name); - } -break ; } }
@@ -500,9 +470,6 @@ static int sun4i_ss_probe(struct platform_device *pdev)case CRYPTO_ALG_TYPE_AHASH :crypto_unregister_ahash (&ss_algs[i].alg.hash);break ; -case CRYPTO_ALG_TYPE_RNG : -crypto_unregister_rng (&ss_algs[i].alg.rng); -break ; } } error_pm:
@@ -523,9 +490,6 @@ static int sun4i_ss_remove(struct platform_device *pdev)case CRYPTO_ALG_TYPE_AHASH :crypto_unregister_ahash (&ss_algs[i].alg.hash);break ; -case CRYPTO_ALG_TYPE_RNG : -crypto_unregister_rng (&ss_algs[i].alg.rng); -break ; } }
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c deleted +0 -69
69 lines not on this page · raw message
drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h +0 -20
@@ -31,8 +31,6 @@#include <crypto/internal/skcipher.h> #include <crypto/aes.h> #include <crypto/internal/des.h> -#include <crypto/internal/rng.h> -#include <crypto/rng.h> #define SS_CTL 0x00#define SS_KEY0 0x04
@@ -62,10 +60,6 @@/* SS_CTL configuration values */ -/* PRNG generator mode - bit 15 */ -#define SS_PRNG_ONESHOT (0 << 15) -#define SS_PRNG_CONTINUE (1 << 15) -/* IV mode for hash */ #define SS_IV_ARBITRARY (1 << 14)
@@ -94,14 +88,10 @@#define SS_OP_3DES (2 << 4)#define SS_OP_SHA1 (3 << 4)#define SS_OP_MD5 (4 << 4) -#define SS_OP_PRNG (5 << 4)/* Data end bit - bit 2 */ #define SS_DATA_END (1 << 2) -/* PRNG start bit - bit 1 */ -#define SS_PRNG_START (1 << 1) -/* SS Enable bit - bit 0 */ #define SS_DISABLED (0 << 0)#define SS_ENABLED (1 << 0)
@@ -128,9 +118,6 @@#define SS_RXFIFO_EMP_INT_ENABLE (1 << 2)#define SS_TXFIFO_AVA_INT_ENABLE (1 << 0) -#define SS_SEED_LEN 192 -#define SS_DATA_LEN 160 -/* * struct ss_variant - Describe SS hardware variant * @sha1_in_be: The SHA1 digest is given by SS in BE, and so need to be inverted.
@@ -151,9 +138,6 @@ struct sun4i_ss_ctx {char buf[4 *SS_RX_MAX ];/* buffer for linearize SG src */ char bufo[4 *SS_TX_MAX ];/* buffer for linearize SG dst */ spinlock_t slock;/* control the use of the device */ -#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG -u32 seed[SS_SEED_LEN /BITS_PER_LONG ]; -#endif struct dentry *dbgfs_dir;struct dentry *dbgfs_stats; };
@@ -164,7 +148,6 @@ struct sun4i_ss_alg_template {union {struct skcipher_alg crypto;struct ahash_alg hash; -struct rng_alg rng; } alg;struct sun4i_ss_ctx *ss;unsigned long stat_req;
@@ -231,6 +214,3 @@ int sun4i_ss_des_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen);int sun4i_ss_des3_setkey (struct crypto_skcipher *tfm,const u8 *key,unsigned int keylen); -int sun4i_ss_prng_generate (struct crypto_rng *tfm,const u8 *src, -unsigned int slen,u8 *dst,unsigned int dlen); -int sun4i_ss_prng_seed (struct crypto_rng *tfm,const u8 *seed,unsigned int slen);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 263/1067 x86/mm: Fix check/use ordering in switch_mm_irqs_off()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Dolan <[email protected]>
This is a stable-specific fix. There is no single upstream commit to cherry-pick; the equivalent mainline fix is commit 83b0177a6c48 ("x86/mm: Fix SMP ordering in switch_mm_irqs_off()"), which is in v6.18 but does not apply to these trees because the surrounding code was refactored.
The backports of commit fea4e317f9e7 ("x86/mm: Eliminate window where TLB flushes may be inadvertently skipped") -- the fix for CVE-2025-37964 -- to the 6.1, 6.6 and 6.12 trees ended up with two code blocks in the wrong order relative to mainline. The fix depends on setting cpu_tlbstate.loaded_mm to LOADED_MM_SWITCHING *before* reading tlb_gen, so that a concurrent TLB shootdown either sees LOADED_MM_SWITCHING and sends the IPI, or the switching CPU sees the updated tlb_gen. In the stable trees the write of LOADED_MM_SWITCHING was placed after the tlb_gen read, so the race window fea4e317f9e7 was meant to close is still open and CVE-2025-37964 is unfixed there:
a process can be left running with stale TLB entries, which typically manifests as rare, hard-to-bisect memory corruption or segfaults.
This has been confirmed by several independent parties:
- reproduced on 6.1.y/6.6.y/6.12.y with the test program in [1], and confirmed fixed by this patch
- Seth Forshee saw segfaults on 6.12.y within ~30 minutes of running a test workload; with this patch it ran 18 hours cleanly [2]
- Greg Thelen reports 6.6.y- and 6.12.y-based test failures fixed by this patch [3]
Dave Hansen acked the patch [4] and has no objection to it going into stable [5].
The patch below is against 6.12.y; the identical change applies to 6.1.y and 6.6.y. (The cpumask_test_cpu()/smp_mb() portion of the mainline fix is not needed here because commit 209954cbc7d0 ("x86/mm/tlb: Update mm_cpumask lazily") was never backported to these trees.)
[1] https://lore.kernel.org/lkml/CAHDw0oGd0B4=uuv8NGqbUQ_ZVmSheU2bN70e4QhFXWvuAZdt2w@mail.gmail.com/
[2] https://lore.kernel.org/lkml/aZYWXe739XUJrBld@do-x1carbon/
[3] https://lore.kernel.org/lkml/CAHH2K0brx9omC9QYyB6Lio3t_1Lf8v=VaFoiaG23UgQ-aec89Q@mail.gmail.com/
[4] https://lore.kernel.org/lkml/[email protected]/
[5] https://lore.kernel.org/lkml/[email protected]/
--- arch/x86/mm/tlb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/mm/tlb.c +8 -8
@@ -597,6 +597,14 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,*/ cond_mitigation (tsk); +/* +* Indicate that CR3 is about to change. nmi_uaccess_okay() +* and others are sensitive to the window where mm_cpumask(), +* CR3 and cpu_tlbstate.loaded_mm are not all in sync. +*/ +this_cpu_write (cpu_tlbstate.loaded_mm,LOADED_MM_SWITCHING ); +barrier (); +/* * Stop remote flushes for the previous mm. * Skip kernel threads; we never send init_mm TLB flushing IPIs,
@@ -616,14 +624,6 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, next_tlb_gen =atomic64_read (&next->context.tlb_gen);choose_new_asid (next, next_tlb_gen, &new_asid, &need_flush); - -/* -* Indicate that CR3 is about to change. nmi_uaccess_okay() -* and others are sensitive to the window where mm_cpumask(), -* CR3 and cpu_tlbstate.loaded_mm are not all in sync. -*/ -this_cpu_write (cpu_tlbstate.loaded_mm,LOADED_MM_SWITCHING ); -barrier (); }if (need_flush) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 264/1067 crypto: crypto4xx - Remove ahash-related code
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Herbert Xu <[email protected]>
commit 97855e7f1ccf4917f305baab199edb9f2595ff5b upstream.
The hash implementation in crypto4xx has been disabled since 2009. As nobody has tried to fix this remove all the dead code.
--- drivers/crypto/amcc/crypto4xx_alg.c | 106 --------------------------- drivers/crypto/amcc/crypto4xx_core.c | 43 +---------- drivers/crypto/amcc/crypto4xx_core.h | 7 -- 3 files changed, 1 insertion(+), 155 deletions(-)
drivers/crypto/amcc/crypto4xx_alg.c +0 -106
@@ -12,9 +12,6 @@#include <linux/interrupt.h> #include <linux/spinlock_types.h> #include <linux/scatterlist.h> -#include <linux/crypto.h> -#include <linux/hash.h> -#include <crypto/internal/hash.h> #include <linux/dma-mapping.h> #include <crypto/algapi.h> #include <crypto/aead.h>
@@ -616,106 +613,3 @@ int crypto4xx_decrypt_aes_gcm(struct aead_request *req) {return crypto4xx_crypt_aes_gcm (req, true); } - -/* -* HASH SHA1 Functions -*/ -static int crypto4xx_hash_alg_init (struct crypto_tfm *tfm, -unsigned int sa_len, -unsigned char ha, -unsigned char hm) -{ -struct crypto_alg *alg = tfm->__crt_alg; -struct crypto4xx_alg *my_alg; -struct crypto4xx_ctx *ctx =crypto_tfm_ctx (tfm); -struct dynamic_sa_hash160 *sa; -int rc; - - my_alg = container_of(__crypto_ahash_alg(alg), struct crypto4xx_alg, - alg.u.hash); - ctx->dev = my_alg->dev; - -/* Create SA */ -if (ctx->sa_in || ctx->sa_out) -crypto4xx_free_sa (ctx); - - rc =crypto4xx_alloc_sa (ctx, sa_len); -if (rc) -return rc; - -crypto_ahash_set_reqsize (__crypto_ahash_cast (tfm), -sizeof (struct crypto4xx_ctx )); - sa = (struct dynamic_sa_hash160 *)ctx->sa_in; -set_dynamic_sa_command_0 (&sa->ctrl,SA_SAVE_HASH ,SA_NOT_SAVE_IV , -SA_NOT_LOAD_HASH ,SA_LOAD_IV_FROM_SA , -SA_NO_HEADER_PROC , ha,SA_CIPHER_ALG_NULL , -SA_PAD_TYPE_ZERO ,SA_OP_GROUP_BASIC , -SA_OPCODE_HASH ,DIR_INBOUND ); -set_dynamic_sa_command_1 (&sa->ctrl,0 ,SA_HASH_MODE_HASH , -CRYPTO_FEEDBACK_MODE_NO_FB ,SA_EXTENDED_SN_OFF , -SA_SEQ_MASK_OFF ,SA_MC_ENABLE , -SA_NOT_COPY_PAD ,SA_NOT_COPY_PAYLOAD , -SA_NOT_COPY_HDR ); -/* Need to zero hash digest in SA */ -memset (sa->inner_digest,0 ,sizeof (sa->inner_digest)); -memset (sa->outer_digest,0 ,sizeof (sa->outer_digest)); - -return 0 ; -} - -int crypto4xx_hash_init (struct ahash_request *req) -{ -struct crypto4xx_ctx *ctx =crypto_tfm_ctx (req->base.tfm); -int ds; -struct dynamic_sa_ctl *sa; - - sa = ctx->sa_in; - ds =crypto_ahash_digestsize ( -__crypto_ahash_cast (req->base.tfm)); - sa->sa_command_0.bf.digest_len = ds >>2 ; - sa->sa_command_0.bf.load_hash_state =SA_LOAD_HASH_FROM_SA ; - -return 0 ; -} - -int crypto4xx_hash_update (struct ahash_request *req) -{ -struct crypto_ahash *ahash =crypto_ahash_reqtfm (req); -struct crypto4xx_ctx *ctx =crypto_tfm_ctx (req->base.tfm); -struct scatterlist dst; -unsigned int ds =crypto_ahash_digestsize (ahash); - -sg_init_one (&dst, req->result, ds); - -return crypto4xx_build_pd (&req->base, ctx, req->src, &dst, - req->nbytes,NULL ,0 , ctx->sa_in, - ctx->sa_len,0 ,NULL ); -} - -int crypto4xx_hash_final (struct ahash_request *req) -{ -return 0 ; -} - -int crypto4xx_hash_digest (struct ahash_request *req) -{ -struct crypto_ahash *ahash =crypto_ahash_reqtfm (req); -struct crypto4xx_ctx *ctx =crypto_tfm_ctx (req->base.tfm); -struct scatterlist dst; -unsigned int ds =crypto_ahash_digestsize (ahash); - -sg_init_one (&dst, req->result, ds); - -return crypto4xx_build_pd (&req->base, ctx, req->src, &dst, - req->nbytes,NULL ,0 , ctx->sa_in, - ctx->sa_len,0 ,NULL ); -} - -/* -* SHA1 Algorithm -*/ -int crypto4xx_sha1_alg_init (struct crypto_tfm *tfm) -{ -return crypto4xx_hash_alg_init (tfm,SA_HASH160_LEN ,SA_HASH_ALG_SHA1 , -SA_HASH_MODE_HASH ); -}
drivers/crypto/amcc/crypto4xx_core.c +1 -42
79 lines not on this page · raw message
drivers/crypto/amcc/crypto4xx_core.h +0 -7
@@ -16,7 +16,6 @@#include <linux/ratelimit.h> #include <linux/mutex.h> #include <linux/scatterlist.h> -#include <crypto/internal/hash.h> #include <crypto/internal/aead.h> #include <crypto/internal/rng.h> #include <crypto/internal/skcipher.h>
@@ -135,7 +134,6 @@ struct crypto4xx_alg_common {u32 type;union {struct skcipher_alg cipher; -struct ahash_alg hash;struct aead_alg aead;struct rng_alg rng; } u;
@@ -182,11 +180,6 @@ int crypto4xx_encrypt_noiv_block(struct skcipher_request *req);int crypto4xx_decrypt_noiv_block (struct skcipher_request *req);int crypto4xx_rfc3686_encrypt (struct skcipher_request *req);int crypto4xx_rfc3686_decrypt (struct skcipher_request *req); -int crypto4xx_sha1_alg_init (struct crypto_tfm *tfm); -int crypto4xx_hash_digest (struct ahash_request *req); -int crypto4xx_hash_final (struct ahash_request *req); -int crypto4xx_hash_update (struct ahash_request *req); -int crypto4xx_hash_init (struct ahash_request *req);/* * Note: Only use this function to copy items that is word aligned.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 265/1067 crypto: crypto4xx - Remove insecure and unused rng_alg
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 7811ec9e973d2c9e465083699f0c8240b98cb8c4 upstream.
Remove crypto4xx_rng, as it is insecure and unused:
- It has only a 64-bit security strength, which is highly inadequate. This can be seen by the fact that crypto4xx_hw_init() seeds it with only 64 bits of entropy, and the fact that the original commit mentions that it implements ANSI X9.17 Annex C.
Another issue was that this driver didn't implement the crypto_rng API correctly, as crypto4xx_prng_generate() didn't return 0 on success.
- No user of this code is known. It's usable only theoretically via the "rng" algorithm type of AF_ALG. But userspace actually just uses the actual Linux RNG (/dev/random etc) instead. And rng_algs don't contribute entropy to the actual Linux RNG either. (This may have been confused with hwrng, which does contribute entropy.)
--- drivers/crypto/amcc/crypto4xx_core.c | 87 ------------------------- drivers/crypto/amcc/crypto4xx_core.h | 4 -- drivers/crypto/amcc/crypto4xx_reg_def.h | 11 ---- 3 files changed, 102 deletions(-)
drivers/crypto/amcc/crypto4xx_core.c +0 -87
@@ -31,11 +31,9 @@#include <crypto/ctr.h> #include <crypto/gcm.h> #include <crypto/sha1.h> -#include <crypto/rng.h> #include <crypto/scatterwalk.h> #include <crypto/skcipher.h> #include <crypto/internal/aead.h> -#include <crypto/internal/rng.h> #include <crypto/internal/skcipher.h> #include "crypto4xx_reg_def.h" #include "crypto4xx_core.h"
@@ -989,10 +987,6 @@ static int crypto4xx_register_alg(struct crypto4xx_device *sec_dev, rc =crypto_register_aead (&alg->alg.u.aead);break ; -case CRYPTO_ALG_TYPE_RNG : - rc =crypto_register_rng (&alg->alg.u.rng); -break ; -default : rc =crypto_register_skcipher (&alg->alg.u.cipher);break ;
@@ -1018,10 +1012,6 @@ static void crypto4xx_unregister_alg(struct crypto4xx_device *sec_dev)crypto_unregister_aead (&alg->alg.u.aead);break ; -case CRYPTO_ALG_TYPE_RNG : -crypto_unregister_rng (&alg->alg.u.rng); -break ; -default :crypto_unregister_skcipher (&alg->alg.u.cipher); }
@@ -1080,69 +1070,6 @@ static irqreturn_t crypto4xx_ce_interrupt_handler_revb(int irq, void *data) PPC4XX_TMO_ERR_INT); } -static int ppc4xx_prng_data_read (struct crypto4xx_device *dev, -u8 *data,unsigned int max) -{ -unsigned int i, curr =0 ; -u32 val[2 ]; - -do { -/* trigger PRN generation */ -writel (PPC4XX_PRNG_CTRL_AUTO_EN , - dev->ce_base +CRYPTO4XX_PRNG_CTRL ); - -for (i =0 ; i <1024 ; i++) { -/* usually 19 iterations are enough */ -if ((readl (dev->ce_base +CRYPTO4XX_PRNG_STAT ) & -CRYPTO4XX_PRNG_STAT_BUSY )) -continue ; - - val[0 ] =readl_be (dev->ce_base +CRYPTO4XX_PRNG_RES_0 ); - val[1 ] =readl_be (dev->ce_base +CRYPTO4XX_PRNG_RES_1 ); -break ; - } -if (i ==1024 ) -return -ETIMEDOUT ; - -if ((max - curr) >=8 ) { -memcpy (data, &val,8 ); - data +=8 ; - curr +=8 ; - }else { -/* copy only remaining bytes */ -memcpy (data, &val, max - curr); -break ; - } - }while (curr < max); - -return curr; -} - -static int crypto4xx_prng_generate (struct crypto_rng *tfm, -const u8 *src,unsigned int slen, -u8 *dstn,unsigned int dlen) -{ -struct rng_alg *alg =crypto_rng_alg (tfm); -struct crypto4xx_alg *amcc_alg; -struct crypto4xx_device *dev; -int ret; - - amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.rng); - dev = amcc_alg->dev; - -mutex_lock (&dev->core_dev->rng_lock); - ret =ppc4xx_prng_data_read (dev, dstn, dlen); -mutex_unlock (&dev->core_dev->rng_lock); -return ret; -} - - -static int crypto4xx_prng_seed (struct crypto_rng *tfm,const u8 *seed, -unsigned int slen) -{ -return 0 ; -} -/* * Supported Crypto Algorithms */
@@ -1312,18 +1239,6 @@ static struct crypto4xx_alg_common crypto4xx_alg[] = { .cra_module = THIS_MODULE, }, } }, - { .type = CRYPTO_ALG_TYPE_RNG, .u.rng = { - .base = { - .cra_name = "stdrng", - .cra_driver_name = "crypto4xx_rng", - .cra_priority = 300, - .cra_ctxsize = 0, - .cra_module = THIS_MODULE, - }, - .generate = crypto4xx_prng_generate, - .seed = crypto4xx_prng_seed, - .seedsize = 0, - } }, };/*
@@ -1401,7 +1316,6 @@ static int crypto4xx_probe(struct platform_device *ofdev) core_dev->dev->core_dev = core_dev; core_dev->dev->is_revb = is_revb; core_dev->device = dev; -mutex_init (&core_dev->rng_lock);spin_lock_init (&core_dev->lock);INIT_LIST_HEAD (&core_dev->dev->alg_list);ratelimit_default_init (&core_dev->dev->aead_ratelimit);
@@ -1479,7 +1393,6 @@ static int crypto4xx_remove(struct platform_device *ofdev)tasklet_kill (&core_dev->tasklet);/* Un-register with Linux CryptoAPI */ crypto4xx_unregister_alg (core_dev->dev); -mutex_destroy (&core_dev->rng_lock);/* Free all allocated memory */ crypto4xx_stop_all (core_dev);
drivers/crypto/amcc/crypto4xx_core.h +0 -4
@@ -14,10 +14,8 @@#define __CRYPTO4XX_CORE_H__#include <linux/ratelimit.h> -#include <linux/mutex.h> #include <linux/scatterlist.h> #include <crypto/internal/aead.h> -#include <crypto/internal/rng.h> #include <crypto/internal/skcipher.h> #include "crypto4xx_reg_def.h" #include "crypto4xx_sa.h"
@@ -111,7 +109,6 @@ struct crypto4xx_core_device {u32 irq;struct tasklet_struct tasklet;spinlock_t lock; -struct mutex rng_lock; };struct crypto4xx_ctx {
@@ -135,7 +132,6 @@ struct crypto4xx_alg_common {union {struct skcipher_alg cipher;struct aead_alg aead; -struct rng_alg rng; } u; };
drivers/crypto/amcc/crypto4xx_reg_def.h +0 -11
@@ -90,20 +90,9 @@#define CRYPTO4XX_BYTE_ORDER_CFG 0x000600d8#define CRYPTO4XX_ENDIAN_CFG 0x000600d8 -#define CRYPTO4XX_PRNG_STAT 0x00070000 -#define CRYPTO4XX_PRNG_STAT_BUSY 0x1#define CRYPTO4XX_PRNG_CTRL 0x00070004#define CRYPTO4XX_PRNG_SEED_L 0x00070008#define CRYPTO4XX_PRNG_SEED_H 0x0007000c - -#define CRYPTO4XX_PRNG_RES_0 0x00070020 -#define CRYPTO4XX_PRNG_RES_1 0x00070024 -#define CRYPTO4XX_PRNG_RES_2 0x00070028 -#define CRYPTO4XX_PRNG_RES_3 0x0007002C - -#define CRYPTO4XX_PRNG_LFSR_L 0x00070030 -#define CRYPTO4XX_PRNG_LFSR_H 0x00070034 -/* * Initialize CRYPTO ENGINE registers, and memory bases. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 266/1067 crypto: af_alg - Remove zero-copy support from skcipher and aead
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit ffdd2bc378953b525aca61902534e753f1f8e734 upstream.
The zero-copy support is one of the riskiest aspects of AF_ALG. It allows userspace to request cryptographic operations directly on pagecache pages of files like the 'su' binary. It also allows userspace to concurrently modify the memory which is being operated on, a recipe for TOCTOU vulnerabilities.
While zero-copy support is more valuable in other areas of the kernel like the frequently used networking and file I/O code, it has far less value in AF_ALG, which is a niche UAPI. AF_ALG primarily just exists for backwards compatibility with a small set of userspace programs such as 'iwd' that haven't yet been fixed to use userspace crypto code.
Originally AF_ALG was intended to be used to access hardware crypto accelerators. However, it isn't an efficient interface for that anyway, and it turned out to be rarely used in this way in practice.
Thus, the risks of the zero-copy support in AF_ALG vastly outweigh its benefits. Let's just remove it.
This commit removes it from the "skcipher" and "aead" algorithm types. "hash" will be handled separately.
This is a soft break, not a hard break. Even after this commit, it still works to use splice() or sendfile() to transfer data to an AF_ALG request socket from a pipe or any file, respectively. What changes is just that the kernel now makes an internal, stable copy of the data before doing the crypto operation. So performance is slightly reduced, but the UAPI isn't broken. And, very importantly, it's much safer.
Tested with libkcapi/test.sh. All its test cases still pass. I also verified that this would have prevented the copy.fail exploit as well. I also used a custom test program to verify that sendfile() still works.
[Backport-notes: this actually does nothing on 6.1, since zero-copy
support was already removed from skcipher and aead accidentally on 6.1. Namely, a commit that changed af_alg_sendpage() to use MSG_SPLICE_PAGES was backported, but the actual implementation of MSG_SPLICE_PAGES wasn't backported. I'm including this commit anyway since people might think this is missing on 6.1 if it's the only LTS kernel without this.]
--- Documentation/crypto/userspace-if.rst | 31 ++++----------------------- crypto/af_alg.c | 2 +- 2 files changed, 5 insertions(+), 28 deletions(-)
Documentation/crypto/userspace-if.rst +4 -27
@@ -328,33 +328,10 @@ CRYPTO_USER_API_RNG_CAVP option: Zero-Copy Interface ------------------- -In addition to the send/write/read/recv system call family, the AF_ALG -interface can be accessed with the zero-copy interface of -splice/vmsplice. As the name indicates, the kernel tries to avoid a copy -operation into kernel space. - -The zero-copy operation requires data to be aligned at the page -boundary. Non-aligned data can be used as well, but may require more -operations of the kernel which would defeat the speed gains obtained -from the zero-copy interface. - -The system-inherent limit for the size of one zero-copy operation is 16 -pages. If more data is to be sent to AF_ALG, user space must slice the -input into segments with a maximum size of 16 pages. - -Zero-copy can be used with the following code example (a complete -working example is provided with libkcapi): - -:: - - int pipes[2]; - - pipe(pipes); - /* input data in iov */ - vmsplice(pipes[1], iov, iovlen, SPLICE_F_GIFT); - /* opfd is the file descriptor returned from accept() system call */ - splice(pipes[0], NULL, opfd, NULL, ret, 0); - read(opfd, out, outlen); +AF_ALG used to have zero-copy support, but it was removed due to it being a +frequent source of vulnerabilities. For backwards compatibility the splice() +and sendfile() system calls are still supported, but the kernel will make an +internal copy of the data before passing it to the crypto code. Setsockopt Interface
crypto/af_alg.c +1 -1
@@ -977,7 +977,7 @@ ssize_t af_alg_sendpage(struct socket *sock, struct page *page, {struct bio_vec bvec;struct msghdr msg = { - .msg_flags = flags |MSG_SPLICE_PAGES , + .msg_flags = flags, };if (flags &MSG_SENDPAGE_NOTLAST )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 267/1067 crypto: hisi-trng - Remove crypto_rng interface
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 216a7795ec210bdabd5dad42323eee70bbfc8d90 upstream.
drivers/crypto/hisilicon/trng/trng.c exposes the same hardware through two completely separate interfaces, crypto_rng and hwrng. However, the implementation of this is buggy because it permits generation operations from these interfaces to run concurrently with each other, accessing the same registers. That is, hisi_trng_generate() synchronizes with itself but not with hisi_trng_read(). This results in potential repetition of output from the RNG, output of non-random values, etc.
Fortunately, there's actually no point in hardware RNG drivers implementing the crypto_rng interface. It's not actually used by anything besides the "rng" algorithm type of AF_ALG, which in turn is not actually used in practice. Other crypto_rng hardware drivers are likewise being phased out, leaving just the hwrng support.
Thus, remove it to simplify the code and avoid conflict (and confusion) with the hwrng interface which is the one that actually matters.
--- drivers/crypto/hisilicon/Kconfig | 1 - drivers/crypto/hisilicon/trng/trng.c | 298 +-------------------------- 2 files changed, 2 insertions(+), 297 deletions(-)
drivers/crypto/hisilicon/Kconfig +0 -1
@@ -79,6 +79,5 @@ config CRYPTO_DEV_HISI_TRNG tristate "Support for HISI TRNG Driver" depends on ARM64 && ACPI select HW_RANDOM - select CRYPTO_RNG help Support for HiSilicon TRNG Driver.
drivers/crypto/hisilicon/trng/trng.c +2 -296
355 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 241/1067 Input: maplemouse - fix NULL pointer dereference in open()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fuchs <[email protected]>
commit ee89db004238bd0b034f2a6176e175561658750b upstream.
Commit 555c765b0cc2 ("Input: mouse - drop unnecessary calls to input_set_drvdata") dropped the input_set_drvdata() call in probe because the data appeared to be unused. However, dc_mouse_open() and dc_mouse_close() were using maple_get_drvdata(to_maple_dev(&dev->dev)). This appears to be accessing the data attached to an instance of maple_device structure, while in reality this actually retrieves driver data from the input device's embedded struct device (doing invalid conversion of input device structure to maple device). After input_set_drvdata() was removed, that lookup started returning NULL and opening the input device dereferences mse->mdev.
Restore input_set_drvdata() and convert open() and close() to use input_get_drvdata() so the dependency is no longer hidden.
--- drivers/input/mouse/maplemouse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/mouse/maplemouse.c +3 -2
@@ -48,7 +48,7 @@ static void dc_mouse_callback(struct mapstatic int dc_mouse_open (struct input_dev *dev) { -struct dc_mouse *mse =maple_get_drvdata (to_maple_dev (&dev->dev)); +struct dc_mouse *mse =input_get_drvdata (dev);maple_getcond_callback (mse->mdev, dc_mouse_callback,HZ /50 ,MAPLE_FUNC_MOUSE );
@@ -58,7 +58,7 @@ static int dc_mouse_open(struct input_destatic void dc_mouse_close (struct input_dev *dev) { -struct dc_mouse *mse =maple_get_drvdata (to_maple_dev (&dev->dev)); +struct dc_mouse *mse =input_get_drvdata (dev);maple_getcond_callback (mse->mdev, dc_mouse_callback,0 ,MAPLE_FUNC_MOUSE );
@@ -88,6 +88,7 @@ static int probe_maple_mouse(struct devi mse->dev = input_dev; mse->mdev = mdev; +input_set_drvdata (input_dev, mse); input_dev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_REL ); input_dev->keybit[BIT_WORD (BTN_MOUSE )] =BIT_MASK (BTN_LEFT ) |BIT_MASK (BTN_RIGHT ) |BIT_MASK (BTN_MIDDLE );
Greg Kroah-Hartman
maintainerPATCH 268/1067 media: uvcvideo: Avoid partial metadata buffers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
commit a15b773fe4ffa450b56347cc506b2d1405600f5d upstream.
If the metadata queue that is empty receives a new buffer while we are in the middle of processing a frame, the first metadata buffer will contain partial information.
Avoid this by tracking the state of the metadata buffer and making sure that it is in sync with the data buffer.
Now that we are at it, make sure that we skip buffers of size 1 or 0. They are not allowed by the spec... but it is a simple check to add and better be safe than sorry.
--- drivers/media/usb/uvc/uvc_video.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/media/usb/uvc/uvc_video.c +9 -4
@@ -1085,7 +1085,9 @@ static void uvc_video_stats_stop(struct* uvc_video_decode_end will never be called with a NULL buffer. */ static int uvc_video_decode_start (struct uvc_streaming *stream, -struct uvc_buffer *buf,const u8 *data,int len) +struct uvc_buffer *buf, +struct uvc_buffer *meta_buf, +const u8 *data,int len) {u8 fid;
@@ -1156,6 +1158,8 @@ static int uvc_video_decode_start(struct/* TODO: Handle PTS and SCR. */ buf->state =UVC_BUF_STATE_ACTIVE ; +if (meta_buf) + meta_buf->state =UVC_BUF_STATE_ACTIVE ; }/*
@@ -1350,7 +1354,7 @@ static void uvc_video_decode_meta(structktime_t time;const u8 *scr; -if (!meta_buf || length ==2 ) +if (length <=2 || !meta_buf || meta_buf->state !=UVC_BUF_STATE_ACTIVE )return ; has_pts = mem[1 ] &UVC_STREAM_PTS ;
@@ -1467,7 +1471,7 @@ static void uvc_video_decode_isoc(struct/* Decode the payload header. */ mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset; do { - ret = uvc_video_decode_start(stream, buf, mem, + ret = uvc_video_decode_start(stream, buf, meta_buf, mem, urb->iso_frame_desc[i].actual_length); if (ret == -EAGAIN) uvc_video_next_buffers(stream, &buf, &meta_buf);
@@ -1516,7 +1520,8 @@ static void uvc_video_decode_bulk(struct*/ if (stream->bulk.header_size ==0 && !stream->bulk.skip_payload) {do { - ret =uvc_video_decode_start (stream, buf, mem, len); + ret =uvc_video_decode_start (stream, buf, meta_buf, mem, + len);if (ret == -EAGAIN )uvc_video_next_buffers (stream, &buf, &meta_buf); }while (ret == -EAGAIN );
Greg Kroah-Hartman
maintainerPATCH 269/1067 media: uvcvideo: Fix buffer sequence in frame gaps
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
commit 2f24ac8dd87983a55f0498898f34a5f2b735b802 upstream.
In UVC, the FID flips with every frame. For every FID flip, we increase the stream sequence number.
Now, if a FID flips multiple times and there is no data transferred between the flips, the buffer sequence number will be set to the value of the stream sequence number after the first flip.
Userspace uses the buffer sequence number to determine if there have been missing frames. With the current behaviour, userspace will think that the gap is in the wrong location.
This patch modifies uvc_video_decode_start() to provide the correct buffer sequence number and timestamp.
--- drivers/media/usb/uvc/uvc_video.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/media/usb/uvc/uvc_video.c +13 -4
@@ -1112,6 +1112,19 @@ static int uvc_video_decode_start(struct stream->sequence++;if (stream->sequence)uvc_video_stats_update (stream); + +/* +* On a FID flip initialize sequence number and timestamp. +* +* The driver already takes care of injecting FID flips for +* UVC_QUIRK_STREAM_NO_FID and UVC_QUIRK_MJPEG_NO_EOF. +*/ +if (buf) { + buf->buf.field =V4L2_FIELD_NONE ; + buf->buf.sequence = stream->sequence; + buf->buf.vb2_buf.timestamp = +ktime_to_ns (uvc_video_get_time ()); + } }uvc_video_clock_decode (stream, buf, data, len);
@@ -1152,10 +1165,6 @@ static int uvc_video_decode_start(structreturn -ENODATA ; } - buf->buf.field =V4L2_FIELD_NONE ; - buf->buf.sequence = stream->sequence; - buf->buf.vb2_buf.timestamp =ktime_to_ns (uvc_video_get_time ()); -/* TODO: Handle PTS and SCR. */ buf->state =UVC_BUF_STATE_ACTIVE ;if (meta_buf)
Greg Kroah-Hartman
maintainerPATCH 270/1067 dt-bindings: media: sun4i-a10-video-engine: Add interconnect properties
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
commit 018f2dc3a42098d3b04edd1480adc51d268adb14 upstream.
The Allwinner video engine sits behind the MBUS that is represented as an interconnect.
Make sure that the interconnect properties are valid in the binding.
--- Documentation/devicetree/bindings/media/allwinner,sun4i-a10-video-engine.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/media/allwinner,sun4i-a10-video-engine.yaml +10 -0
@@ -63,6 +63,16 @@ properties: CMA pool to use for buffers allocation instead of the default CMA pool. + # FIXME: This should be made required eventually once every SoC will + # have the MBUS declared. + interconnects: + maxItems: 1 + + # FIXME: This should be made required eventually once every SoC will + # have the MBUS declared. + interconnect-names: + const: dma-mem + required: - compatible - reg
Greg Kroah-Hartman
maintainerPATCH 271/1067 dt-bindings: power: imx93: Add MIPI PHY power domain
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guoniu Zhou <[email protected]>
commit 6aa38ef0eab32df5409b72d62509de6ba09cea50 upstream.
Add MIPI PHY power domain for shared PHY resources used by both MIPI DSI and CSI blocks.
--- include/dt-bindings/power/fsl,imx93-power.h | 1 + 1 file changed, 1 insertion(+)
include/dt-bindings/power/fsl,imx93-power.h +1 -0
@@ -11,5 +11,6 @@#define IMX93_MEDIABLK_PD_PXP 2#define IMX93_MEDIABLK_PD_LCDIF 3#define IMX93_MEDIABLK_PD_ISI 4 +#define IMX93_MEDIABLK_PD_MIPI_PHY 5#endif
Signature · 1 line
2.55.0