6.18.40-rc1 review
Subsystems (13)
Greg Kroah-Hartman
maintainerPATCH 1550/1611 ksmbd: fix path resolution in ksmbd_vfs_kern_path_create
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Davide Ornaghi <[email protected]>
[ Upstream commit 1c8951963d8ed357f70f59e0ad4ddce2199d2016 ]
The SMB2 open lookup is rooted at the share with LOOKUP_BENEATH, but the create/mkdir/hardlink sink is not: ksmbd_vfs_kern_path_create() builds an absolute path with convert_to_unix_name() and resolves it from AT_FDCWD via start_creating_path(), so a ".." component is walked from the real filesystem root and escapes the export.
An authenticated client races a missing path component so the rooted open lookup returns -ENOENT (taking the create branch) while the same component is present (a directory) when the create walk runs; the create then resolves ".." out of the share.
Root the create walk at the share like the lookup and rename paths already
are: resolve the parent with vfs_path_parent_lookup(..., LOOKUP_BENEATH, &share_conf->vfs_path) and create the final component with start_creating_noperm(). convert_to_unix_name() then has no callers and is removed.
--- fs/smb/server/misc.c | 33 --------------------------------- fs/smb/server/misc.h | 1 - fs/smb/server/vfs.c | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 40 deletions(-)
fs/smb/server/misc.c +0 -33
@@ -278,39 +278,6 @@ char *ksmbd_extract_sharename(struct unireturn ksmbd_casefold_sharename (um, name); } -/** -* convert_to_unix_name() - convert windows name to unix format -* @share: ksmbd_share_config pointer -* @name: file name that is relative to share -* -* Return: converted name on success, otherwise NULL -*/ -char *convert_to_unix_name (struct ksmbd_share_config *share,const char *name) -{ -int no_slash =0 , name_len, path_len; -char *new_name; - -if (name[0 ] =='/' ) - name++; - - path_len = share->path_sz; - name_len =strlen (name); - new_name =kmalloc (path_len + name_len +2 ,KSMBD_DEFAULT_GFP ); -if (!new_name) -return new_name; - -memcpy (new_name, share->path, path_len); -if (new_name[path_len -1 ] !='/' ) { - new_name[path_len] ='/' ; - no_slash =1 ; - } - -memcpy (new_name + path_len + no_slash, name, name_len); - path_len += name_len + no_slash; - new_name[path_len] =0x00 ; -return new_name; -} -char *ksmbd_convert_dir_info_name (struct ksmbd_dir_info *d_info,const struct nls_table *local_nls,int *conv_len)
fs/smb/server/misc.h +0 -1
@@ -22,7 +22,6 @@ void ksmbd_strip_last_slash(char *path);void ksmbd_conv_path_to_windows (char *path);char *ksmbd_casefold_sharename (struct unicode_map *um,const char *name);char *ksmbd_extract_sharename (struct unicode_map *um,const char *treename); -char *convert_to_unix_name (struct ksmbd_share_config *share,const char *name);#define KSMBD_DIR_INFO_ALIGNMENT 8struct ksmbd_dir_info ;
fs/smb/server/vfs.c +32 -6
@@ -1338,15 +1338,41 @@ struct dentry *ksmbd_vfs_kern_path_creatunsigned int flags, struct path *path) { - char *abs_name; + struct ksmbd_share_config *share_conf = work->tcon->share_conf; + struct filename *filename __free(putname) = NULL; +struct qstr last;struct dentry *dent; +int err, type; - abs_name =convert_to_unix_name (work->tcon->share_conf, name); -if (!abs_name) -return ERR_PTR (-ENOMEM ); +/* resolve the name beneath the share root so ".." cannot escape */ + filename =getname_kernel (name); +if (IS_ERR (filename)) +return ERR_CAST (filename); - dent =start_creating_path (AT_FDCWD , abs_name, path, flags); -kfree (abs_name); + err =vfs_path_parent_lookup (filename, flags |LOOKUP_BENEATH , + path, &last, &type, + &share_conf->vfs_path); +if (err) +return ERR_PTR (err); + +if (unlikely (type !=LAST_NORM )) { +path_put (path); +return ERR_PTR (-EINVAL ); + } + + err =mnt_want_write (path->mnt); +if (err) { +path_put (path); +return ERR_PTR (err); + } + +inode_lock_nested (path->dentry->d_inode,I_MUTEX_PARENT ); + dent =lookup_one_qstr_excl (&last, path->dentry,LOOKUP_CREATE ); +if (IS_ERR (dent)) { +inode_unlock (path->dentry->d_inode); +mnt_drop_write (path->mnt); +path_put (path); + }return dent; }
Greg Kroah-Hartman
maintainerPATCH 1551/1611 ksmbd: centralize ksmbd_conn final release to plug transport leak
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit b1f1e80620deb49daf63c2e677046599b693dc1f ]
ksmbd_conn_free() is one of four sites that can observe the last refcount drop of a struct ksmbd_conn. The other three
fs/smb/server/connection.c ksmbd_conn_r_count_dec()
fs/smb/server/oplock.c __free_opinfo()
fs/smb/server/vfs_cache.c session_fd_check()end the conn with a bare kfree(), skipping ida_destroy(&conn->async_ida) and conn->transport->ops->free_transport(conn->transport). Whenever one of them is the last putter, the embedded async_ida and the entire transport struct leak -- for TCP, that is also the struct socket and the kvec iov.
__free_opinfo() being a final putter is not theoretical. opinfo_put() queues the callback via call_rcu(&opinfo->rcu, free_opinfo_rcu), so ksmbd_server_terminate_conn() can deposit N opinfo releases in RCU and have ksmbd_conn_free() run in the handler thread before any of them fire. ksmbd_conn_free() then observes refcnt > 0 and short-circuits; the last RCU-delivered __free_opinfo() falls onto its bare kfree(conn) branch and the transport is lost.
A/B validation in a QEMU/virtme guest, mounting //127.0.0.1/testshare:
each iteration holds 8 files open via sleep processes, force-closes TCP with "ss -K sport = :445", kills the holders, lazy-umounts; repeated 10 times, then ksmbd shutdown and kmemleak scan.
state conn_alloc conn_free tcp_free opi_rcu kmemleak
---------- ---------- --------- -------- ------- --------
pre-patch 20 20 10 160 7
with patch 20 20 20 160 0Pre-patch conn_free=20 with tcp_free=10 directly demonstrates the bare-kfree paths skipping transport cleanup; kmemleak backtraces point into struct tcp_transport / iov. With this patch tcp_free matches conn_free at 20/20 and kmemleak is clean.
Move the per-struct final release into __ksmbd_conn_release_work() and route the three bare-kfree final-put sites through a new ksmbd_conn_put(). Those sites now pair ida_destroy() and free_transport() with kfree(conn) regardless of which holder happens to release the last reference. stop_sessions() only triggers the transport shutdown and does not itself drop the last conn reference, so it is unaffected.
The centralized release reaches sock_release() -> tcp_close() -> lock_sock_nested() (might_sleep) from every final putter, including __free_opinfo() invoked from an RCU softirq callback, which trips CONFIG_DEBUG_ATOMIC_SLEEP. Defer the release to a dedicated ksmbd_conn_wq workqueue so ksmbd_conn_put() is safe from any non-sleeping context.
Make ksmbd_file own a strong connection reference while fp->conn is non-NULL so durable-preserve and final-close paths cannot dereference a stale connection. ksmbd_open_fd() and ksmbd_reopen_durable_fd() take the reference via ksmbd_conn_get() (the latter also reorders the fp->conn / fp->tcon assignments before __open_id() so the published fp is never observed with fp->conn == NULL); session_fd_check() and __ksmbd_close_fd() drop it via ksmbd_conn_put(). With that invariant, session_fd_check() can take a local conn pointer once and use it across the m_op_list and lock_list iterations even though op->conn puts may otherwise drop the last reference.
At module exit the workqueue is flushed and destroyed after rcu_barrier(), so any release queued by a trailing RCU callback is drained before the inode hash and module text go away.
Stable-dep-of: c1016dd1d8b2 ("ksmbd: track the connection owning a byte-range lock")
--- fs/smb/server/connection.c | 101 ++++++++++++++++++++++++++++++++++++++------- fs/smb/server/connection.h | 6 ++ fs/smb/server/oplock.c | 7 --- fs/smb/server/server.c | 12 +++++ fs/smb/server/vfs_cache.c | 60 ++++++++++++++++++++++---- 5 files changed, 156 insertions(+), 30 deletions(-)
fs/smb/server/connection.c +86 -15
@@ -22,6 +22,81 @@ static struct ksmbd_conn_ops default_conDEFINE_HASHTABLE (conn_list,CONN_HASH_BITS );DECLARE_RWSEM (conn_list_lock); +static struct workqueue_struct *ksmbd_conn_wq; + +int ksmbd_conn_wq_init (void ) +{ + ksmbd_conn_wq =alloc_workqueue ("ksmbd-conn-release" , +WQ_UNBOUND |WQ_MEM_RECLAIM ,0 ); +if (!ksmbd_conn_wq) +return -ENOMEM ; +return 0 ; +} + +void ksmbd_conn_wq_destroy (void ) +{ +if (ksmbd_conn_wq) { +destroy_workqueue (ksmbd_conn_wq); + ksmbd_conn_wq =NULL ; + } +} + +/* +* __ksmbd_conn_release_work() - perform the final, once-per-struct cleanup +* of a ksmbd_conn whose refcount has just dropped to zero. +* +* This is the common release path used by ksmbd_conn_put() for the embedded +* state that outlives the connection thread: async_ida and the attached +* transport (which owns the socket and iov for TCP). Called from a workqueue +* so that sleep-allowed teardown (sock_release -> tcp_close -> +* lock_sock_nested) never runs from an RCU softirq callback (free_opinfo_rcu) +* or any other non-sleeping putter context. +*/ +static void __ksmbd_conn_release_work (struct work_struct *work) +{ +struct ksmbd_conn *conn = + container_of(work, struct ksmbd_conn, release_work); + +ida_destroy (&conn->async_ida); + conn->transport->ops->free_transport (conn->transport); +kfree (conn); +} + +/** +* ksmbd_conn_get() - take a reference on @conn and return it. +* +* Returns @conn unchanged so callers can write +* "fp->conn = ksmbd_conn_get(work->conn);" in one expression. Returns NULL +* if @conn is NULL. +*/ +struct ksmbd_conn *ksmbd_conn_get (struct ksmbd_conn *conn) +{ +if (!conn) +return NULL ; + +atomic_inc (&conn->refcnt); +return conn; +} + +/** +* ksmbd_conn_put() - drop a reference and, if it was the last, queue the +* release onto ksmbd_conn_wq so it runs from process context. +* +* Callable from any context including RCU softirq callbacks and non-sleeping +* locks; the actual release is deferred to the workqueue. ksmbd_conn_wq is +* created in ksmbd_server_init() before any conn can be allocated and is +* destroyed in ksmbd_server_exit() after rcu_barrier(), so it is always +* non-NULL while a conn reference is held. +*/ +void ksmbd_conn_put (struct ksmbd_conn *conn) +{ +if (!conn) +return ; + +if (atomic_dec_and_test (&conn->refcnt)) +queue_work (ksmbd_conn_wq, &conn->release_work); +} +/** * ksmbd_conn_free() - free resources of the connection instance *
@@ -36,23 +111,19 @@ void ksmbd_conn_free(struct ksmbd_conn *hash_del (&conn->hlist);up_write (&conn_list_lock); +/* +* request_buf / preauth_info / mechToken are only ever accessed by the +* connection handler thread that owns @conn. ksmbd_conn_free() is +* called from the transport free_transport() path when that thread is +* exiting, so it is safe to release them unconditionally even when +* ksmbd_conn_put() below is not the final putter (oplock / ksmbd_file +* holders only retain the conn pointer, not these per-thread buffers). +*/ xa_destroy (&conn->sessions);kvfree (conn->request_buf);kfree (conn->preauth_info);kfree (conn->mechToken); -if (atomic_dec_and_test (&conn->refcnt)) { -/* -* async_ida is embedded in struct ksmbd_conn, so pair -* ida_destroy() with the final kfree() rather than with -* the unconditional field teardown above. This keeps -* the IDA valid for the entire lifetime of the struct, -* even while other refcount holders (oplock / vfs -* durable handles) still reference the connection. -*/ -ida_destroy (&conn->async_ida); - conn->transport->ops->free_transport (conn->transport); -kfree (conn); - } +ksmbd_conn_put (conn); }/**
@@ -79,6 +150,7 @@ struct ksmbd_conn *ksmbd_conn_alloc(void conn->um =ERR_PTR (-EOPNOTSUPP );if (IS_ERR (conn->um)) conn->um =NULL ; +INIT_WORK (&conn->release_work, __ksmbd_conn_release_work);atomic_set (&conn->req_running,0 );atomic_set (&conn->r_count,0 );atomic_set (&conn->refcnt,1 );
@@ -458,8 +530,7 @@ void ksmbd_conn_r_count_dec(struct ksmbdif (!atomic_dec_return (&conn->r_count) &&waitqueue_active (&conn->r_count_q))wake_up (&conn->r_count_q); -if (atomic_dec_and_test (&conn->refcnt)) -kfree (conn); +ksmbd_conn_put (conn); }int ksmbd_conn_transport_init (void )
fs/smb/server/connection.h +6 -0
@@ -15,6 +15,7 @@#include <linux/kthread.h> #include <linux/nls.h> #include <linux/unicode.h> +#include <linux/workqueue.h> #include "smb_common.h" #include "ksmbd_work.h"
@@ -119,6 +120,7 @@ struct ksmbd_conn {bool binding;atomic_t refcnt;bool is_aapl; +struct work_struct release_work; };struct ksmbd_conn_ops {
@@ -164,6 +166,10 @@ void ksmbd_conn_wait_idle(struct ksmbd_cint ksmbd_conn_wait_idle_sess_id (struct ksmbd_conn *curr_conn,u64 sess_id);struct ksmbd_conn *ksmbd_conn_alloc (void );void ksmbd_conn_free (struct ksmbd_conn *conn); +struct ksmbd_conn *ksmbd_conn_get (struct ksmbd_conn *conn); +void ksmbd_conn_put (struct ksmbd_conn *conn); +int ksmbd_conn_wq_init (void ); +void ksmbd_conn_wq_destroy (void );bool ksmbd_conn_lookup_dialect (struct ksmbd_conn *c);int ksmbd_conn_write (struct ksmbd_work *work); int ksmbd_conn_rdma_read(struct ksmbd_conn *conn,
fs/smb/server/oplock.c +2 -5
@@ -30,7 +30,6 @@ static DEFINE_RWLOCK(lease_list_lock);static struct oplock_info *alloc_opinfo (struct ksmbd_work *work,u64 id,__u16 Tid) { -struct ksmbd_conn *conn = work->conn;struct ksmbd_session *sess = work->sess;struct oplock_info *opinfo;
@@ -39,7 +38,7 @@ static struct oplock_info *alloc_opinfo(return NULL ; opinfo->sess = sess; - opinfo->conn = conn; + opinfo->conn =ksmbd_conn_get (work->conn); opinfo->level =SMB2_OPLOCK_LEVEL_NONE ; opinfo->op_state =OPLOCK_STATE_NONE ; opinfo->pending_break =0 ;
@@ -50,7 +49,6 @@ static struct oplock_info *alloc_opinfo(init_waitqueue_head (&opinfo->oplock_brk);atomic_set (&opinfo->refcount,1 );atomic_set (&opinfo->breaking_cnt,0 ); -atomic_inc (&opinfo->conn->refcnt);return opinfo; }
@@ -132,8 +130,7 @@ static void __free_opinfo(struct oplock_ {if (opinfo->is_lease)free_lease (opinfo); -if (opinfo->conn &&atomic_dec_and_test (&opinfo->conn->refcnt)) -kfree (opinfo->conn); +ksmbd_conn_put (opinfo->conn);kfree (opinfo); }
fs/smb/server/server.c +12 -0
@@ -588,8 +588,14 @@ static int __init ksmbd_server_init(voidif (ret) goto err_crypto_destroy; + ret =ksmbd_conn_wq_init (); +if (ret) + goto err_workqueue_destroy; +return 0 ; +err_workqueue_destroy: +ksmbd_workqueue_destroy (); err_crypto_destroy:ksmbd_crypto_destroy (); err_release_inode_hash:
@@ -615,6 +621,12 @@ static void __exit ksmbd_server_exit(voi {ksmbd_server_shutdown ();rcu_barrier (); +/* +* ksmbd_conn_put() defers the final release onto ksmbd_conn_wq, +* so drain it after rcu_barrier() has fired any pending RCU +* callbacks that may have queued a release. +*/ +ksmbd_conn_wq_destroy ();ksmbd_release_inode_hash (); }
fs/smb/server/vfs_cache.c +50 -10
123 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 1552/1611 ksmbd: track the connection owning a byte-range lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit c1016dd1d8b2bcd1158bbaabe94a31bb7e7431fb ]
SMB2_LOCK adds each granted byte-range lock to both the file lock list and the lock list of the connection which handled the request. The final close and durable handle paths, however, remove the connection list entry while holding fp->conn->llist_lock.
With SMB3 multichannel, the connection handling the LOCK request can be different from the connection which opened the file. The entry can therefore be removed under a different spinlock from the one protecting the list it belongs to. A concurrent traversal can then access freed struct ksmbd_lock and struct file_lock objects.
Record the connection owning each lock's clist entry and hold a reference to it while the entry is linked. Use that connection and its llist_lock for unlock, rollback, close, and durable preserve. Durable reconnect assigns the new connection as the owner when publishing the locks again.
--- fs/smb/server/smb2pdu.c | 10 ++++++++-- fs/smb/server/vfs_cache.c | 23 +++++++++++++++++------ fs/smb/server/vfs_cache.h | 1 + 3 files changed, 26 insertions(+), 8 deletions(-)
fs/smb/server/smb2pdu.c +8 -2
@@ -7660,9 +7660,11 @@ int smb2_lock(struct ksmbd_work *work) nolock =0 ;list_del (&cmp_lock->flist);list_del (&cmp_lock->clist); + cmp_lock->conn =NULL ;spin_unlock (&conn->llist_lock);up_read (&conn_list_lock); +ksmbd_conn_put (conn);locks_free_lock (cmp_lock->fl);kfree (cmp_lock); goto out_check_cl;
@@ -7797,6 +7799,7 @@ skip: goto out2; }else if (!rc) {list_add (&smb_lock->llist, &rollback_list); + smb_lock->conn =ksmbd_conn_get (work->conn);spin_lock (&work->conn->llist_lock);list_add_tail (&smb_lock->clist, &work->conn->lock_list);
@@ -7851,11 +7854,14 @@ out: }list_del (&smb_lock->llist); -spin_lock (&work->conn->llist_lock); + conn = smb_lock->conn; +spin_lock (&conn->llist_lock);if (!list_empty (&smb_lock->flist))list_del (&smb_lock->flist);list_del (&smb_lock->clist); -spin_unlock (&work->conn->llist_lock); + smb_lock->conn =NULL ; +spin_unlock (&conn->llist_lock); +ksmbd_conn_put (conn);locks_free_lock (smb_lock->fl);if (rlock)
fs/smb/server/vfs_cache.c +17 -6
@@ -391,10 +391,14 @@ static void __ksmbd_close_fd(struct ksmb* there are not accesses to fp->lock_list. */ list_for_each_entry_safe (smb_lock, tmp_lock, &fp->lock_list, flist) { -if (!list_empty (&smb_lock->clist) && fp->conn) { -spin_lock (&fp->conn->llist_lock); -list_del (&smb_lock->clist); -spin_unlock (&fp->conn->llist_lock); +struct ksmbd_conn *conn = smb_lock->conn; + +if (conn) { +spin_lock (&conn->llist_lock); +list_del_init (&smb_lock->clist); + smb_lock->conn =NULL ; +spin_unlock (&conn->llist_lock); +ksmbd_conn_put (conn); }list_del (&smb_lock->flist);
@@ -1086,9 +1090,15 @@ static bool session_fd_check(struct ksmbup_write (&ci->m_lock);list_for_each_entry_safe (smb_lock, tmp_lock, &fp->lock_list, flist) { -spin_lock (&conn->llist_lock); +struct ksmbd_conn *lock_conn = smb_lock->conn; + +if (!lock_conn) +continue ; +spin_lock (&lock_conn->llist_lock);list_del_init (&smb_lock->clist); -spin_unlock (&conn->llist_lock); + smb_lock->conn =NULL ; +spin_unlock (&lock_conn->llist_lock); +ksmbd_conn_put (lock_conn); } fp->conn =NULL ;
@@ -1209,6 +1219,7 @@ int ksmbd_reopen_durable_fd(struct ksmbd }list_for_each_entry (smb_lock, &fp->lock_list, flist) { + smb_lock->conn =ksmbd_conn_get (conn);spin_lock (&conn->llist_lock);list_add_tail (&smb_lock->clist, &conn->lock_list);spin_unlock (&conn->llist_lock);
fs/smb/server/vfs_cache.h +1 -0
@@ -32,6 +32,7 @@ struct ksmbd_session;struct ksmbd_lock {struct file_lock *fl; +struct ksmbd_conn *conn;struct list_head clist;struct list_head flist;struct list_head llist;
Greg Kroah-Hartman
maintainerPATCH 1553/1611 ksmbd: Use SHA-512 library for SMB3.1.1 preauth hash
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
[ Upstream commit e009cb1e3093977c5b96a1c6697a7dc9332222d5 ]
Convert ksmbd_gen_preauth_integrity_hash() to use the SHA-512 library instead of a "sha512" crypto_shash. This is simpler and faster. With the library there's no need to allocate memory, no need to handle errors, and the SHA-512 code is accessed directly without inefficient indirect calls and other unnecessary API overhead.
Stable-dep-of: 954d196bebb2 ("ksmbd: validate NTLMv2 response before updating session key")
--- fs/smb/server/Kconfig | 2 +- fs/smb/server/auth.c | 41 +++++++---------------------------------- fs/smb/server/crypto_ctx.c | 8 -------- fs/smb/server/crypto_ctx.h | 4 ---- fs/smb/server/server.c | 1 - 5 files changed, 8 insertions(+), 48 deletions(-)
fs/smb/server/Kconfig +1 -1
@@ -13,10 +13,10 @@ config SMB_SERVER select CRYPTO_LIB_ARC4 select CRYPTO_LIB_DES select CRYPTO_LIB_SHA256 + select CRYPTO_LIB_SHA512 select CRYPTO_LIB_UTILS select CRYPTO_SHA256 select CRYPTO_CMAC - select CRYPTO_SHA512 select CRYPTO_AEAD2 select CRYPTO_CCM select CRYPTO_GCM
fs/smb/server/auth.c +7 -34
61 lines not on this page · raw message
fs/smb/server/crypto_ctx.c +0 -8
@@ -75,9 +75,6 @@ static struct shash_desc *alloc_shash_decase CRYPTO_SHASH_CMACAES : tfm =crypto_alloc_shash ("cmac(aes)" ,0 ,0 );break ; -case CRYPTO_SHASH_SHA512 : - tfm =crypto_alloc_shash ("sha512" ,0 ,0 ); -break ;default :return NULL ; }
@@ -195,11 +192,6 @@ struct ksmbd_crypto_ctx *ksmbd_crypto_ctreturn ____crypto_shash_ctx_find (CRYPTO_SHASH_CMACAES ); } -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512 (void ) -{ -return ____crypto_shash_ctx_find (CRYPTO_SHASH_SHA512 ); -} -static struct ksmbd_crypto_ctx *____crypto_aead_ctx_find (int id) {struct ksmbd_crypto_ctx *ctx;
fs/smb/server/crypto_ctx.h +0 -4
@@ -13,7 +13,6 @@ enum {CRYPTO_SHASH_HMACMD5 =0 ,CRYPTO_SHASH_HMACSHA256 ,CRYPTO_SHASH_CMACAES , -CRYPTO_SHASH_SHA512 , CRYPTO_SHASH_MAX, };
@@ -38,13 +37,11 @@ struct ksmbd_crypto_ctx {#define CRYPTO_HMACMD5 (c) ((c)->desc[CRYPTO_SHASH_HMACMD5])#define CRYPTO_HMACSHA256 (c) ((c)->desc[CRYPTO_SHASH_HMACSHA256])#define CRYPTO_CMACAES (c) ((c)->desc[CRYPTO_SHASH_CMACAES]) -#define CRYPTO_SHA512 (c) ((c)->desc[CRYPTO_SHASH_SHA512])#define CRYPTO_HMACMD5_TFM (c) ((c)->desc[CRYPTO_SHASH_HMACMD5]->tfm)#define CRYPTO_HMACSHA256_TFM (c)\ ((c)->desc[CRYPTO_SHASH_HMACSHA256]->tfm)#define CRYPTO_CMACAES_TFM (c) ((c)->desc[CRYPTO_SHASH_CMACAES]->tfm) -#define CRYPTO_SHA512_TFM (c) ((c)->desc[CRYPTO_SHASH_SHA512]->tfm)#define CRYPTO_GCM (c) ((c)->ccmaes[CRYPTO_AEAD_AES_GCM])#define CRYPTO_CCM (c) ((c)->ccmaes[CRYPTO_AEAD_AES_CCM])
@@ -53,7 +50,6 @@ void ksmbd_release_crypto_ctx(struct ksmstruct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5 (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacsha256 (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes (void ); -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512 (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_gcm (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_ccm (void );void ksmbd_crypto_destroy (void );
fs/smb/server/server.c +0 -1
@@ -640,7 +640,6 @@ MODULE_SOFTDEP("pre: nls");MODULE_SOFTDEP ("pre: aes" );MODULE_SOFTDEP ("pre: cmac" );MODULE_SOFTDEP ("pre: sha256" ); -MODULE_SOFTDEP ("pre: sha512" );MODULE_SOFTDEP ("pre: aead2" );MODULE_SOFTDEP ("pre: ccm" );MODULE_SOFTDEP ("pre: gcm" );
Greg Kroah-Hartman
maintainerPATCH 1554/1611 ksmbd: Use HMAC-SHA256 library for message signing and key generation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
[ Upstream commit 924067ef183bd17f39d790752190f99982524598 ]
Convert ksmbd_sign_smb2_pdu() and generate_key() to use the HMAC-SHA256 library instead of a "hmac(sha256)" crypto_shash. This is simpler and faster. With the library there's no need to allocate memory, no need to handle errors, and the HMAC-SHA256 code is accessed directly without inefficient indirect calls and other unnecessary API overhead.
Stable-dep-of: 954d196bebb2 ("ksmbd: validate NTLMv2 response before updating session key")
--- fs/smb/server/Kconfig | 1 fs/smb/server/auth.c | 180 ++++++++++----------------------------------- fs/smb/server/auth.h | 10 +- fs/smb/server/crypto_ctx.c | 8 -- fs/smb/server/crypto_ctx.h | 5 - fs/smb/server/server.c | 1 fs/smb/server/smb2pdu.c | 25 +----- fs/smb/server/smb_common.h | 2 8 files changed, 54 insertions(+), 178 deletions(-)
fs/smb/server/Kconfig +0 -1
@@ -15,7 +15,6 @@ config SMB_SERVER select CRYPTO_LIB_SHA256 select CRYPTO_LIB_SHA512 select CRYPTO_LIB_UTILS - select CRYPTO_SHA256 select CRYPTO_CMAC select CRYPTO_AEAD2 select CRYPTO_CCM
fs/smb/server/auth.c +41 -139
245 lines not on this page · raw message
fs/smb/server/auth.h +5 -5
@@ -52,18 +52,18 @@ ksmbd_build_ntlmssp_challenge_blob(struc struct ksmbd_conn *conn);int ksmbd_krb5_authenticate (struct ksmbd_session *sess,char *in_blob,int in_len,char *out_blob,int *out_len); -int ksmbd_sign_smb2_pdu (struct ksmbd_conn *conn,char *key,struct kvec *iov, -int n_vec,char *sig); +void ksmbd_sign_smb2_pdu (struct ksmbd_conn *conn,char *key,struct kvec *iov, +int n_vec,char *sig);int ksmbd_sign_smb3_pdu (struct ksmbd_conn *conn,char *key,struct kvec *iov,int n_vec,char *sig);int ksmbd_gen_smb30_signingkey (struct ksmbd_session *sess,struct ksmbd_conn *conn);int ksmbd_gen_smb311_signingkey (struct ksmbd_session *sess,struct ksmbd_conn *conn); -int ksmbd_gen_smb30_encryptionkey (struct ksmbd_conn *conn, -struct ksmbd_session *sess); -int ksmbd_gen_smb311_encryptionkey (struct ksmbd_conn *conn, +void ksmbd_gen_smb30_encryptionkey (struct ksmbd_conn *conn,struct ksmbd_session *sess); +void ksmbd_gen_smb311_encryptionkey (struct ksmbd_conn *conn, +struct ksmbd_session *sess);int ksmbd_gen_preauth_integrity_hash (struct ksmbd_conn *conn,char *buf,__u8 *pi_hash);#endif
fs/smb/server/crypto_ctx.c +0 -8
@@ -69,9 +69,6 @@ static struct shash_desc *alloc_shash_decase CRYPTO_SHASH_HMACMD5 : tfm =crypto_alloc_shash ("hmac(md5)" ,0 ,0 );break ; -case CRYPTO_SHASH_HMACSHA256 : - tfm =crypto_alloc_shash ("hmac(sha256)" ,0 ,0 ); -break ;case CRYPTO_SHASH_CMACAES : tfm =crypto_alloc_shash ("cmac(aes)" ,0 ,0 );break ;
@@ -182,11 +179,6 @@ struct ksmbd_crypto_ctx *ksmbd_crypto_ctreturn ____crypto_shash_ctx_find (CRYPTO_SHASH_HMACMD5 ); } -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacsha256 (void ) -{ -return ____crypto_shash_ctx_find (CRYPTO_SHASH_HMACSHA256 ); -} -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes (void ) {return ____crypto_shash_ctx_find (CRYPTO_SHASH_CMACAES );
fs/smb/server/crypto_ctx.h +0 -5
@@ -11,7 +11,6 @@enum {CRYPTO_SHASH_HMACMD5 =0 , -CRYPTO_SHASH_HMACSHA256 ,CRYPTO_SHASH_CMACAES ,CRYPTO_SHASH_MAX , };
@@ -35,12 +34,9 @@ struct ksmbd_crypto_ctx { };#define CRYPTO_HMACMD5 (c) ((c)->desc[CRYPTO_SHASH_HMACMD5]) -#define CRYPTO_HMACSHA256 (c) ((c)->desc[CRYPTO_SHASH_HMACSHA256])#define CRYPTO_CMACAES (c) ((c)->desc[CRYPTO_SHASH_CMACAES])#define CRYPTO_HMACMD5_TFM (c) ((c)->desc[CRYPTO_SHASH_HMACMD5]->tfm) -#define CRYPTO_HMACSHA256_TFM (c)\ - ((c)->desc[CRYPTO_SHASH_HMACSHA256]->tfm)#define CRYPTO_CMACAES_TFM (c) ((c)->desc[CRYPTO_SHASH_CMACAES]->tfm)#define CRYPTO_GCM (c) ((c)->ccmaes[CRYPTO_AEAD_AES_GCM])
@@ -48,7 +44,6 @@ struct ksmbd_crypto_ctx {void ksmbd_release_crypto_ctx (struct ksmbd_crypto_ctx *ctx);struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5 (void ); -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacsha256 (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_gcm (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_ccm (void );
fs/smb/server/server.c +0 -1
@@ -639,7 +639,6 @@ MODULE_SOFTDEP("pre: md5");MODULE_SOFTDEP ("pre: nls" );MODULE_SOFTDEP ("pre: aes" );MODULE_SOFTDEP ("pre: cmac" ); -MODULE_SOFTDEP ("pre: sha256" );MODULE_SOFTDEP ("pre: aead2" );MODULE_SOFTDEP ("pre: ccm" );MODULE_SOFTDEP ("pre: gcm" );
fs/smb/server/smb2pdu.c +7 -18
@@ -1552,12 +1552,7 @@ static int ntlm_authenticate(struct ksmbif (smb3_encryption_negotiated (conn) && !(req->Flags &SMB2_SESSION_REQ_FLAG_BINDING )) { - rc = conn->ops->generate_encryptionkey (conn, sess); -if (rc) { -ksmbd_debug (SMB , -"SMB3 encryption key generation failed\n" ); -return -EINVAL ; - } + conn->ops->generate_encryptionkey (conn, sess); sess->enc = true;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION ) rsp->SessionFlags =SMB2_SESSION_FLAG_ENCRYPT_DATA_LE ;
@@ -1656,12 +1651,7 @@ static int krb5_authenticate(struct ksmbif (smb3_encryption_negotiated (conn) && !(req->Flags &SMB2_SESSION_REQ_FLAG_BINDING )) { - retval = conn->ops->generate_encryptionkey (conn, sess); -if (retval) { -ksmbd_debug (SMB , -"SMB3 encryption key generation failed\n" ); -return -EINVAL ; - } + conn->ops->generate_encryptionkey (conn, sess); sess->enc = true;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION ) rsp->SessionFlags =SMB2_SESSION_FLAG_ENCRYPT_DATA_LE ;
@@ -9077,9 +9067,8 @@ int smb2_check_sign_req(struct ksmbd_wor iov[0 ].iov_base = (char *)&hdr->ProtocolId; iov[0 ].iov_len = len; -if (ksmbd_sign_smb2_pdu (work->conn, work->sess->sess_key, iov,1 , - signature)) -return 0 ; +ksmbd_sign_smb2_pdu (work->conn, work->sess->sess_key, iov,1 , + signature);if (crypto_memneq (signature, signature_req,SMB2_SIGNATURE_SIZE )) {pr_err ("bad smb2 signature\n" );
@@ -9112,9 +9101,9 @@ void smb2_set_sign_rsp(struct ksmbd_work iov = &work->iov[work->iov_idx]; } -if (!ksmbd_sign_smb2_pdu (work->conn, work->sess->sess_key, iov, n_vec, - signature)) -memcpy (hdr->Signature, signature,SMB2_SIGNATURE_SIZE ); +ksmbd_sign_smb2_pdu (work->conn, work->sess->sess_key, iov, n_vec, + signature); +memcpy (hdr->Signature, signature,SMB2_SIGNATURE_SIZE ); }/**
fs/smb/server/smb_common.h +1 -1
@@ -373,7 +373,7 @@ struct smb_version_ops {int (*check_sign_req)(struct ksmbd_work *work);void (*set_sign_rsp)(struct ksmbd_work *work);int (*generate_signingkey)(struct ksmbd_session *sess,struct ksmbd_conn *conn); -int (*generate_encryptionkey)(struct ksmbd_conn *conn,struct ksmbd_session *sess); +void (*generate_encryptionkey)(struct ksmbd_conn *conn,struct ksmbd_session *sess);bool (*is_transform_hdr)(void *buf);int (*decrypt_req)(struct ksmbd_work *work);int (*encrypt_resp)(struct ksmbd_work *work);
Greg Kroah-Hartman
maintainerPATCH 1555/1611 ksmbd: Use HMAC-MD5 library for NTLMv2
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
[ Upstream commit 3a597e6e9701eb7af04864ffdc0a6a91bc8c6496 ]
For the HMAC-MD5 computations in NTLMv2, use the HMAC-MD5 library instead of a "hmac(md5)" crypto_shash. This is simpler and faster. With the library there's no need to allocate memory, no need to handle errors, and the HMAC-MD5 code is accessed directly without inefficient indirect calls and other unnecessary API overhead.
To preserve the existing behavior of NTLMv2 support being disabled when the kernel is booted with "fips=1", make ksmbd_auth_ntlmv2() check fips_enabled itself. Previously it relied on the error from crypto_alloc_shash("hmac(md5)") being bubbled up. I don't know for sure that this is actually needed, but this preserves the existing behavior.
Stable-dep-of: 954d196bebb2 ("ksmbd: validate NTLMv2 response before updating session key")
--- fs/smb/server/Kconfig | 3 fs/smb/server/auth.c | 175 ++++++--------------------------------------- fs/smb/server/crypto_ctx.c | 8 -- fs/smb/server/crypto_ctx.h | 6 - fs/smb/server/server.c | 2 5 files changed, 28 insertions(+), 166 deletions(-)
fs/smb/server/Kconfig +1 -2
@@ -7,11 +7,10 @@ config SMB_SERVER select NLS_UTF8 select NLS_UCS2_UTILS select CRYPTO - select CRYPTO_MD5 - select CRYPTO_HMAC select CRYPTO_ECB select CRYPTO_LIB_ARC4 select CRYPTO_LIB_DES + select CRYPTO_LIB_MD5 select CRYPTO_LIB_SHA256 select CRYPTO_LIB_SHA512 select CRYPTO_LIB_UTILS
fs/smb/server/auth.c +26 -149
225 lines not on this page · raw message
fs/smb/server/crypto_ctx.c +0 -8
@@ -66,9 +66,6 @@ static struct shash_desc *alloc_shash_destruct shash_desc *shash;switch (id) { -case CRYPTO_SHASH_HMACMD5 : - tfm =crypto_alloc_shash ("hmac(md5)" ,0 ,0 ); -break ;case CRYPTO_SHASH_CMACAES : tfm =crypto_alloc_shash ("cmac(aes)" ,0 ,0 );break ;
@@ -174,11 +171,6 @@ static struct ksmbd_crypto_ctx *____crypreturn NULL ; } -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5 (void ) -{ -return ____crypto_shash_ctx_find (CRYPTO_SHASH_HMACMD5 ); -} -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes (void ) {return ____crypto_shash_ctx_find (CRYPTO_SHASH_CMACAES );
fs/smb/server/crypto_ctx.h +1 -5
@@ -10,8 +10,7 @@#include <crypto/aead.h> enum { -CRYPTO_SHASH_HMACMD5 =0 , -CRYPTO_SHASH_CMACAES , +CRYPTO_SHASH_CMACAES =0 ,CRYPTO_SHASH_MAX , };
@@ -33,17 +32,14 @@ struct ksmbd_crypto_ctx {struct crypto_aead *ccmaes[CRYPTO_AEAD_MAX ]; }; -#define CRYPTO_HMACMD5 (c) ((c)->desc[CRYPTO_SHASH_HMACMD5])#define CRYPTO_CMACAES (c) ((c)->desc[CRYPTO_SHASH_CMACAES]) -#define CRYPTO_HMACMD5_TFM (c) ((c)->desc[CRYPTO_SHASH_HMACMD5]->tfm)#define CRYPTO_CMACAES_TFM (c) ((c)->desc[CRYPTO_SHASH_CMACAES]->tfm)#define CRYPTO_GCM (c) ((c)->ccmaes[CRYPTO_AEAD_AES_GCM])#define CRYPTO_CCM (c) ((c)->ccmaes[CRYPTO_AEAD_AES_CCM])void ksmbd_release_crypto_ctx (struct ksmbd_crypto_ctx *ctx); -struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5 (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_gcm (void );struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_ccm (void );
fs/smb/server/server.c +0 -2
@@ -634,8 +634,6 @@ MODULE_AUTHOR("Namjae Jeon <linkinjeon@kMODULE_DESCRIPTION ("Linux kernel CIFS/SMB SERVER" );MODULE_LICENSE ("GPL" );MODULE_SOFTDEP ("pre: ecb" ); -MODULE_SOFTDEP ("pre: hmac" ); -MODULE_SOFTDEP ("pre: md5" );MODULE_SOFTDEP ("pre: nls" );MODULE_SOFTDEP ("pre: aes" );MODULE_SOFTDEP ("pre: cmac" );
Greg Kroah-Hartman
maintainerPATCH 1556/1611 ksmbd: validate NTLMv2 response before updating session key
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haofeng Li <[email protected]>
[ Upstream commit 954d196bebb2b50151cb96454c72dc113b2af1ac ]
ksmbd_auth_ntlmv2() derives the NTLMv2 session key into sess->sess_key before it verifies the NTLMv2 response. ksmbd_decode_ntlmssp_auth_blob() then continues into KEY_XCH even when ksmbd_auth_ntlmv2() failed.
With SMB3 multichannel binding, the failed authentication operates on an existing session and the session setup error path does not expire binding sessions. A client can send a binding session setup with a bad NT proof and KEY_XCH and still modify sess->sess_key before STATUS_LOGON_FAILURE is returned.
Relevant path:
smb2_sess_setup()
-> conn->binding = true
-> ntlm_authenticate()
-> session_user()
-> ksmbd_decode_ntlmssp_auth_blob()
-> ksmbd_auth_ntlmv2()
-> calc_ntlmv2_hash()
-> hmac_md5_usingrawkey(..., sess->sess_key)
-> crypto_memneq() returns mismatch
-> KEY_XCH arc4_crypt(..., sess->sess_key, ...)
-> out_err without expiring the binding sessionDerive the base session key into a local buffer and copy it to sess->sess_key only after the proof matches. Return immediately on authentication failure so KEY_XCH is only processed after successful authentication.
--- fs/smb/server/auth.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
fs/smb/server/auth.c +16 -4
@@ -142,6 +142,7 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn {char ntlmv2_hash[CIFS_ENCPWD_SIZE ];char ntlmv2_rsp[CIFS_HMAC_MD5_HASH_SIZE ]; +char sess_key[SMB2_NTLMV2_SESSKEY_SIZE ];struct hmac_md5_ctx ctx;int rc;
@@ -164,12 +165,21 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn/* Generate the session key */ hmac_md5_usingrawkey (ntlmv2_hash,CIFS_HMAC_MD5_HASH_SIZE , ntlmv2_rsp,CIFS_HMAC_MD5_HASH_SIZE , - sess->sess_key); + sess_key);if (crypto_memneq (ntlmv2->ntlmv2_hash, ntlmv2_rsp, -CIFS_HMAC_MD5_HASH_SIZE )) -return -EINVAL ; -return 0 ; +CIFS_HMAC_MD5_HASH_SIZE )) { + rc = -EINVAL ; + goto out; + } + +memcpy (sess->sess_key, sess_key,sizeof (sess_key)); + rc =0 ; +out: +memzero_explicit (ntlmv2_hash,sizeof (ntlmv2_hash)); +memzero_explicit (ntlmv2_rsp,sizeof (ntlmv2_rsp)); +memzero_explicit (sess_key,sizeof (sess_key)); +return rc; }/**
@@ -226,6 +236,8 @@ int ksmbd_decode_ntlmssp_auth_blob(struc nt_len -CIFS_ENCPWD_SIZE , domain_name, conn->ntlmssp.cryptkey);kfree (domain_name); +if (ret) +return ret;/* The recovered secondary session key */ if (conn->ntlmssp.client_flags &NTLMSSP_NEGOTIATE_KEY_XCH ) {
Greg Kroah-Hartman
maintainerPATCH 1557/1611 proc: rename proc_setattr to proc_nochmod_setattr
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 690005b0b1e6b567c88b7790e6d90d4d6c9e09cc ]
What is currently proc_setattr is a special version added after the more general procfs ->seattr in commit 6d76fa58b050 ("Don't allow chmod() on the /proc/<pid>/ files"). Give it a name that reflects that to free the proc_setattr name and better describe what is doing.
Stable-dep-of: 6255da28d4bb ("proc: protect ptrace_may_access() with exec_update_lock (FD links)")
--- fs/proc/base.c | 22 +++++++++++----------- fs/proc/fd.c | 6 +++--- fs/proc/internal.h | 4 ++-- fs/proc/namespaces.c | 4 ++-- fs/proc/proc_net.c | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-)
fs/proc/base.c +11 -11
@@ -721,7 +721,7 @@ static bool proc_fd_access_allowed(strucreturn allowed; } -int proc_setattr (struct mnt_idmap *idmap,struct dentry *dentry, +int proc_nochmod_setattr (struct mnt_idmap *idmap,struct dentry *dentry,struct iattr *attr) {int error;
@@ -794,7 +794,7 @@ static int proc_pid_permission(struct mnstatic const struct inode_operations proc_def_inode_operations = { - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, };static int proc_single_show (struct seq_file *m,void *v)
@@ -1866,7 +1866,7 @@ out:const struct inode_operations proc_pid_link_inode_operations = { .readlink = proc_pid_readlink, .get_link = proc_pid_get_link, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, };
@@ -2319,7 +2319,7 @@ proc_map_files_get_link(struct dentry *dstatic const struct inode_operations proc_map_files_link_inode_operations = { .readlink = proc_pid_readlink, .get_link = proc_map_files_get_link, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, }; static struct dentry *
@@ -2398,7 +2398,7 @@ out:static const struct inode_operations proc_map_files_inode_operations = { .lookup = proc_map_files_lookup, .permission = proc_fd_permission, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, }; static int
@@ -2885,7 +2885,7 @@ static struct dentry *proc_##LSM##_attr_ static const struct inode_operations proc_##LSM##_attr_dir_inode_ops = { \ .lookup = proc_##LSM##_attr_dir_lookup, \ .getattr = pid_getattr, \ - .setattr = proc_setattr, \ + .setattr = proc_nochmod_setattr, \ }#ifdef CONFIG_SECURITY_SMACK
@@ -2944,7 +2944,7 @@ static struct dentry *proc_attr_dir_lookstatic const struct inode_operations proc_attr_dir_inode_operations = { .lookup = proc_attr_dir_lookup, .getattr = pid_getattr, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, };#endif
@@ -3460,7 +3460,7 @@ static struct dentry *proc_tgid_base_loostatic const struct inode_operations proc_tgid_base_inode_operations = { .lookup = proc_tgid_base_lookup, .getattr = pid_getattr, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, .permission = proc_pid_permission, };
@@ -3659,7 +3659,7 @@ static int proc_tid_comm_permission(stru }static const struct inode_operations proc_tid_comm_inode_operations = { - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, .permission = proc_tid_comm_permission, };
@@ -3788,7 +3788,7 @@ static const struct file_operations procstatic const struct inode_operations proc_tid_base_inode_operations = { .lookup = proc_tid_base_lookup, .getattr = pid_getattr, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, }; static struct dentry *proc_task_instantiate(struct dentry *dentry,
@@ -4001,7 +4001,7 @@ static loff_t proc_dir_llseek(struct filstatic const struct inode_operations proc_task_inode_operations = { .lookup = proc_task_lookup, .getattr = proc_task_getattr, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, .permission = proc_pid_permission, };
fs/proc/fd.c +3 -3
@@ -102,7 +102,7 @@ static int proc_fdinfo_permission(structstatic const struct inode_operations proc_fdinfo_file_inode_operations = { .permission = proc_fdinfo_permission, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, };static const struct file_operations proc_fdinfo_file_operations = {
@@ -361,7 +361,7 @@ const struct inode_operations proc_fd_in .lookup = proc_lookupfd, .permission = proc_fd_permission, .getattr = proc_fd_getattr, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, }; static struct dentry *proc_fdinfo_instantiate(struct dentry *dentry,
@@ -402,7 +402,7 @@ static int proc_fdinfo_iterate(struct ficonst struct inode_operations proc_fdinfo_inode_operations = { .lookup = proc_lookupfdinfo, .permission = proc_fdinfo_permission, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, };const struct file_operations proc_fdinfo_operations = {
fs/proc/internal.h +2 -2
@@ -257,8 +257,8 @@ extern int proc_pid_statm(struct seq_filextern const struct dentry_operations pid_dentry_operations;extern int pid_getattr (struct mnt_idmap *,const struct path *,struct kstat *,u32 ,unsigned int ); -extern int proc_setattr (struct mnt_idmap *,struct dentry *, -struct iattr *); +int proc_nochmod_setattr (struct mnt_idmap *idmap,struct dentry *dentry, +struct iattr *attr);extern void proc_pid_evict_inode (struct proc_inode *);extern struct inode *proc_pid_make_inode (struct super_block *,struct task_struct *,umode_t );extern void pid_update_inode (struct task_struct *,struct inode *);
fs/proc/namespaces.c +2 -2
@@ -92,7 +92,7 @@ static int proc_ns_readlink(struct dentrstatic const struct inode_operations proc_ns_link_inode_operations = { .readlink = proc_ns_readlink, .get_link = proc_ns_get_link, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, }; static struct dentry *proc_ns_instantiate(struct dentry *dentry,
@@ -178,5 +178,5 @@ out_no_task:const struct inode_operations proc_ns_dir_inode_operations = { .lookup = proc_ns_dir_lookup, .getattr = pid_getattr, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, };
fs/proc/proc_net.c +1 -1
@@ -322,7 +322,7 @@ static int proc_tgid_net_getattr(structconst struct inode_operations proc_net_inode_operations = { .lookup = proc_tgid_net_lookup, .getattr = proc_tgid_net_getattr, - .setattr = proc_setattr, + .setattr = proc_nochmod_setattr, };static int proc_tgid_net_readdir (struct file *file,struct dir_context *ctx)
Greg Kroah-Hartman
maintainerPATCH 1558/1611 proc: protect ptrace_may_access() with exec_update_lock (FD links)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
[ Upstream commit 6255da28d4bb5349fe18e84cb043ccd394eba75d ]
proc_pid_get_link() and proc_pid_readlink() currently look up the task from the pid once, then do the ptrace access check on that task, then look up the task from the pid a second time to do the actual access. That's racy in several ways.
To fix it, pass the task to the ->proc_get_link() handler, and instead of proc_fd_access_allowed(), introduce a new helper call_proc_get_link() that looks up and locks the task, does the access check, and calls ->proc_get_link().
--- fs/proc/base.c | 119 ++++++++++++++++++++--------------------------------- fs/proc/fd.c | 25 ++++------- fs/proc/internal.h | 2 3 files changed, 58 insertions(+), 88 deletions(-)
fs/proc/base.c +47 -72
@@ -218,33 +218,24 @@ static int get_task_root(struct task_strreturn result; } -static int proc_cwd_link (struct dentry *dentry,struct path *path) +static int proc_cwd_link (struct dentry *dentry,struct path *path, +struct task_struct *task) { -struct task_struct *task =get_proc_task (d_inode (dentry));int result = -ENOENT ; -if (task) { -task_lock (task); -if (task->fs) { -get_fs_pwd (task->fs, path); - result =0 ; - } -task_unlock (task); -put_task_struct (task); +task_lock (task); +if (task->fs) { +get_fs_pwd (task->fs, path); + result =0 ; } +task_unlock (task);return result; } -static int proc_root_link (struct dentry *dentry,struct path *path) +static int proc_root_link (struct dentry *dentry,struct path *path, +struct task_struct *task) { -struct task_struct *task =get_proc_task (d_inode (dentry)); -int result = -ENOENT ; - -if (task) { - result =get_task_root (task, path); -put_task_struct (task); - } -return result; +return get_task_root (task, path); }/*
@@ -704,23 +695,6 @@ static int proc_pid_syscall(struct seq_f/* Here the fs part begins */ /************************************************************************/ -/* permission checks */ -static bool proc_fd_access_allowed (struct inode *inode) -{ -struct task_struct *task; -bool allowed = false; -/* Allow access to a task's file descriptors if it is us or we -* may use ptrace attach to the process and find out that -* information. -*/ - task =get_proc_task (inode); -if (task) { - allowed =ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS ); -put_task_struct (task); - } -return allowed; -} -int proc_nochmod_setattr (struct mnt_idmap *idmap,struct dentry *dentry,struct iattr *attr) {
@@ -1777,16 +1751,12 @@ static const struct file_operations proc .release = single_release, }; -static int proc_exe_link (struct dentry *dentry,struct path *exe_path) +static int proc_exe_link (struct dentry *dentry,struct path *exe_path, +struct task_struct *task) { -struct task_struct *task;struct file *exe_file; - task =get_proc_task (d_inode (dentry)); -if (!task) -return -ENOENT ; exe_file =get_task_exe_file (task); -put_task_struct (task);if (exe_file) { *exe_path = exe_file->f_path;path_get (&exe_file->f_path);
@@ -1796,26 +1766,42 @@ static int proc_exe_link(struct dentry *return -ENOENT ; } +static int call_proc_get_link (struct dentry *dentry,struct inode *inode,struct path *path_out) +{ +struct task_struct *task; +int ret; + + task =get_proc_task (inode); +if (!task) +return -ENOENT ; + ret =down_read_killable (&task->signal->exec_update_lock); +if (ret) + goto out_put_task; +if (!ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS )) { + ret = -EACCES ; + goto out; + } + ret =PROC_I (inode)->op.proc_get_link (dentry, path_out, task); + +out: +up_read (&task->signal->exec_update_lock); +out_put_task: +put_task_struct (task); +return ret; +} +static const char *proc_pid_get_link (struct dentry *dentry,struct inode *inode,struct delayed_call *done) {struct path path; -int error = -EACCES ; +int error;if (!dentry)return ERR_PTR (-ECHILD ); - -/* Are we allowed to snoop on the tasks file descriptors? */ -if (!proc_fd_access_allowed (inode)) - goto out; - - error =PROC_I (inode)->op.proc_get_link (dentry, &path); -if (error) - goto out; - - error =nd_jump_link (&path); -out: + error =call_proc_get_link (dentry, inode, &path); +if (!error) + error =nd_jump_link (&path);return ERR_PTR (error); }
@@ -1849,17 +1835,11 @@ static int proc_pid_readlink(struct dentstruct inode *inode =d_inode (dentry);struct path path; -/* Are we allowed to snoop on the tasks file descriptors? */ -if (!proc_fd_access_allowed (inode)) - goto out; - - error =PROC_I (inode)->op.proc_get_link (dentry, &path); -if (error) - goto out; - - error =do_proc_readlink (&path, buffer, buflen); -path_put (&path); -out: + error =call_proc_get_link (dentry, inode, &path); +if (!error) { + error =do_proc_readlink (&path, buffer, buflen); +path_put (&path); + }return error; }
@@ -2250,21 +2230,16 @@ static const struct dentry_operations ti .d_delete = pid_delete_dentry, }; -static int map_files_get_link (struct dentry *dentry,struct path *path) +static int map_files_get_link (struct dentry *dentry,struct path *path, +struct task_struct *task) {unsigned long vm_start, vm_end;struct vm_area_struct *vma; -struct task_struct *task;struct mm_struct *mm;int rc; rc = -ENOENT ; - task =get_proc_task (d_inode (dentry)); -if (!task) - goto out; - mm =get_task_mm (task); -put_task_struct (task);if (!mm) goto out;
fs/proc/fd.c +10 -15
@@ -171,24 +171,19 @@ static const struct dentry_operations ti .d_delete = pid_delete_dentry, }; -static int proc_fd_link (struct dentry *dentry,struct path *path) +static int proc_fd_link (struct dentry *dentry,struct path *path, +struct task_struct *task) { -struct task_struct *task;int ret = -ENOENT ; +unsigned int fd =proc_fd (d_inode (dentry)); +struct file *fd_file; - task =get_proc_task (d_inode (dentry)); -if (task) { -unsigned int fd =proc_fd (d_inode (dentry)); -struct file *fd_file; - - fd_file =fget_task (task, fd); -if (fd_file) { - *path = fd_file->f_path; -path_get (&fd_file->f_path); - ret =0 ; -fput (fd_file); - } -put_task_struct (task); + fd_file =fget_task (task, fd); +if (fd_file) { + *path = fd_file->f_path; +path_get (&fd_file->f_path); + ret =0 ; +fput (fd_file); }return ret;
fs/proc/internal.h +1 -1
@@ -107,7 +107,7 @@ extern struct kmem_cache *proc_dir_entryvoid pde_free (struct proc_dir_entry *pde);union proc_op { -int (*proc_get_link)(struct dentry *,struct path *); +int (*proc_get_link)(struct dentry *,struct path *,struct task_struct *);int (*proc_show)(struct seq_file *m,struct pid_namespace *ns,struct pid *pid,struct task_struct *task);
Greg Kroah-Hartman
maintainerPATCH 1559/1611 seqlock: Introduce scoped_seqlock_read()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
[ Upstream commit cc39f3872c0865bef992b713338df369554fa9e0 ]
The read_seqbegin/need_seqretry/done_seqretry API is cumbersome and error prone. With the new helper the "typical" code like
int seq, nextseq;
unsigned long flags;
nextseq = 0;
do {
seq = nextseq;
flags = read_seqbegin_or_lock_irqsave(&seqlock, &seq);
// read-side critical section
nextseq = 1;
} while (need_seqretry(&seqlock, seq));
done_seqretry_irqrestore(&seqlock, seq, flags);can be rewritten as
scoped_seqlock_read (&seqlock, ss_lock_irqsave) {
// read-side critical section
}Original idea by Oleg Nesterov; with contributions from Linus.
Stable-dep-of: 6650527444da ("proc: protect ptrace_may_access() with exec_update_lock (part 1)")
--- include/linux/seqlock.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+)
include/linux/seqlock.h +111 -0
@@ -1209,4 +1209,115 @@ done_seqretry_irqrestore(seqlock_t *lockif (seq &1 )read_sequnlock_excl_irqrestore (lock, flags); } + +enum ss_state { + ss_done =0 , + ss_lock, + ss_lock_irqsave, + ss_lockless, +}; + +struct ss_tmp { +enum ss_state state; +unsigned long data; +spinlock_t *lock; +spinlock_t *lock_irqsave; +}; + +static inline void __scoped_seqlock_cleanup (struct ss_tmp *sst) +{ +if (sst->lock) +spin_unlock (sst->lock); +if (sst->lock_irqsave) +spin_unlock_irqrestore (sst->lock_irqsave, sst->data); +} + +extern void __scoped_seqlock_invalid_target (void ); + +#if defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <90000 +/* +* For some reason some GCC-8 architectures (nios2, alpha) have trouble +* determining that the ss_done state is impossible in __scoped_seqlock_next() +* below. +*/ +static inline void __scoped_seqlock_bug (void ) { } +#else +/* +* Canary for compiler optimization -- if the compiler doesn't realize this is +* an impossible state, it very likely generates sub-optimal code here. +*/ +extern void __scoped_seqlock_bug (void ); +#endif + +static inline void +__scoped_seqlock_next (struct ss_tmp *sst,seqlock_t *lock,enum ss_state target) +{ +switch (sst->state) { +case ss_done: +__scoped_seqlock_bug (); +return ; + +case ss_lock: +case ss_lock_irqsave: + sst->state = ss_done; +return ; + +case ss_lockless: +if (!read_seqretry (lock, sst->data)) { + sst->state = ss_done; +return ; + } +break ; + } + +switch (target) { +case ss_done: +__scoped_seqlock_invalid_target (); +return ; + +case ss_lock: + sst->lock = &lock->lock; +spin_lock (sst->lock); + sst->state = ss_lock; +return ; + +case ss_lock_irqsave: + sst->lock_irqsave = &lock->lock; +spin_lock_irqsave (sst->lock_irqsave, sst->data); + sst->state = ss_lock_irqsave; +return ; + +case ss_lockless: + sst->data =read_seqbegin (lock); +return ; + } +} + +#define __scoped_seqlock_read (_seqlock, _target, _s) \ + for (struct ss_tmp _s __cleanup(__scoped_seqlock_cleanup) = \ + { .state = ss_lockless, .data = read_seqbegin(_seqlock) }; \ + _s.state != ss_done; \ + __scoped_seqlock_next(&_s, _seqlock, _target)) + +/** +* scoped_seqlock_read (lock, ss_state) - execute the read side critical +* section without manual sequence +* counter handling or calls to other +* helpers +* @lock: pointer to seqlock_t protecting the data +* @ss_state: one of {ss_lock, ss_lock_irqsave, ss_lockless} indicating +* the type of critical read section +* +* Example: +* +* scoped_seqlock_read (&lock, ss_lock) { +* // read-side critical section +* } +* +* Starts with a lockess pass first. If it fails, restarts the critical +* section with the lock held. +*/ +#define scoped_seqlock_read (_seqlock, _target) \ + __scoped_seqlock_read(_seqlock, _target, __UNIQUE_ID(seqlock)) +#endif /* __LINUX_SEQLOCK_H */
Greg Kroah-Hartman
maintainerPATCH 1560/1611 seqlock: Change do_task_stat() to use scoped_seqlock_read()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleg Nesterov <[email protected]>
[ Upstream commit b76f72bea2c601afec81829ea427fc0d20f83216 ]
To simplify the code and make it more readable.
Stable-dep-of: 6650527444da ("proc: protect ptrace_may_access() with exec_update_lock (part 1)")
--- fs/proc/array.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
fs/proc/array.c +2 -7
@@ -481,7 +481,6 @@ static int do_task_stat(struct seq_fileunsigned long flags;int exit_code = task->exit_code;struct signal_struct *sig = task->signal; -unsigned int seq =1 ; state = *get_task_state (task); vsize = eip = esp =0 ;
@@ -538,10 +537,7 @@ static int do_task_stat(struct seq_fileif (permitted && (!whole || num_threads <2 )) wchan = !task_is_running (task); - do { - seq++; /* 2 on the 1st/lockless path, otherwise odd */ - flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq); - + scoped_seqlock_read (&sig->stats_lock, ss_lock_irqsave) { cmin_flt = sig->cmin_flt; cmaj_flt = sig->cmaj_flt; cutime = sig->cutime;
@@ -563,8 +559,7 @@ static int do_task_stat(struct seq_file }rcu_read_unlock (); } - }while (need_seqretry (&sig->stats_lock, seq)); -done_seqretry_irqrestore (&sig->stats_lock, seq, flags); + }if (whole) {thread_group_cputime_adjusted (task, &utime, &stime);
Greg Kroah-Hartman
maintainerPATCH 1561/1611 proc: protect ptrace_may_access() with exec_update_lock (part 1)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
[ Upstream commit 6650527444dadc63d84aa939d14ecba4fadb2f69 ]
Fix the easy cases where procfs currently calls ptrace_may_access() without exec_update_lock protection, where the fix is to simply add the extra lock or use mm_access():
- do_task_stat(): grab exec_update_lock
- proc_pid_wchan(): grab exec_update_lock
- proc_map_files_lookup(): use mm_access() instead of get_task_mm()
- proc_map_files_readdir(): use mm_access() instead of get_task_mm()
- proc_ns_get_link(): grab exec_update_lock
- proc_ns_readlink(): grab exec_update_lock
--- fs/proc/array.c | 6 ++++++ fs/proc/base.c | 41 ++++++++++++++++++++++------------------- fs/proc/namespaces.c | 12 ++++++++++++ 3 files changed, 40 insertions(+), 19 deletions(-)
fs/proc/array.c +6 -0
@@ -481,6 +481,11 @@ static int do_task_stat(struct seq_fileunsigned long flags;int exit_code = task->exit_code;struct signal_struct *sig = task->signal; +int ret; + + ret =down_read_killable (&task->signal->exec_update_lock); +if (ret) +return ret; state = *get_task_state (task); vsize = eip = esp =0 ;
@@ -656,6 +661,7 @@ static int do_task_stat(struct seq_fileseq_puts (m," 0" );seq_putc (m,'\n' ); +up_read (&task->signal->exec_update_lock);if (mm)mmput (mm);return 0 ;
fs/proc/base.c +22 -19
101 lines not on this page · raw message
fs/proc/namespaces.c +12 -0
@@ -55,6 +55,10 @@ static const char *proc_ns_get_link(struif (!task)return ERR_PTR (-EACCES ); + error =down_read_killable (&task->signal->exec_update_lock); +if (error) + goto out_put_task; +if (!ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS )) goto out;
@@ -64,6 +68,8 @@ static const char *proc_ns_get_link(stru error =nd_jump_link (&ns_path); out: +up_read (&task->signal->exec_update_lock); +out_put_task:put_task_struct (task);return ERR_PTR (error); }
@@ -80,11 +86,17 @@ static int proc_ns_readlink(struct dentrif (!task)return res; + res =down_read_killable (&task->signal->exec_update_lock); +if (res) + goto out_put_task; +if (ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS )) { res =ns_get_name (name,sizeof (name), task, ns_ops);if (res >=0 ) res =readlink_copy (buffer, buflen, name,strlen (name)); } +up_read (&task->signal->exec_update_lock); +out_put_task:put_task_struct (task);return res; }
Greg Kroah-Hartman
maintainerPATCH 1562/1611 hfs/hfsplus: prevent getting negative values of offset/length
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viacheslav Dubeyko <[email protected]>
[ Upstream commit 00c14a09a70e10ae18eb3707d0059291425c04bd ]
The syzbot reported KASAN out-of-bounds issue inhfs_bnode_move():
[ 45.588165][ T9821] hfs: dst 14, src 65536, len -65536 [ 45.588895][ T9821] ================================================================== [ 45.590114][ T9821] BUG: KASAN: out-of-bounds in hfs_bnode_move+0xfd/0x140 [ 45.591127][ T9821] Read of size 18446744073709486080 at addr ffff888035935400 by task repro/9821 [ 45.592207][ T9821] [ 45.592420][ T9821] CPU: 0 UID: 0 PID: 9821 Comm: repro Not tainted 6.16.0-rc7-dirty #42 PREEMPT(full) [ 45.592428][ T9821] Hardware name: QEMU Ubuntu 24.04 PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 45.592431][ T9821] Call Trace: [ 45.592434][ T9821] <TASK> [ 45.592437][ T9821] dump_stack_lvl+0x1c1/0x2a0 [ 45.592446][ T9821] ? __virt_addr_valid+0x1c8/0x5c0 [ 45.592454][ T9821] ? __pfx_dump_stack_lvl+0x10/0x10 [ 45.592461][ T9821] ? rcu_is_watching+0x15/0xb0 [ 45.592469][ T9821] ? lock_release+0x4b/0x3e0 [ 45.592476][ T9821] ? __virt_addr_valid+0x1c8/0x5c0 [ 45.592483][ T9821] ? __virt_addr_valid+0x4a5/0x5c0 [ 45.592491][ T9821] print_report+0x17e/0x7c0 [ 45.592497][ T9821] ? __virt_addr_valid+0x1c8/0x5c0 [ 45.592504][ T9821] ? __virt_addr_valid+0x4a5/0x5c0 [ 45.592511][ T9821] ? __phys_addr+0xd3/0x180 [ 45.592519][ T9821] ? hfs_bnode_move+0xfd/0x140 [ 45.592526][ T9821] kasan_report+0x147/0x180 [ 45.592531][ T9821] ? _printk+0xcf/0x120 [ 45.592537][ T9821] ? hfs_bnode_move+0xfd/0x140 [ 45.592544][ T9821] ? hfs_bnode_move+0xfd/0x140 [ 45.592552][ T9821] kasan_check_range+0x2b0/0x2c0 [ 45.592557][ T9821] ? hfs_bnode_move+0xfd/0x140 [ 45.592565][ T9821] __asan_memmove+0x29/0x70 [ 45.592572][ T9821] hfs_bnode_move+0xfd/0x140 [ 45.592580][ T9821] hfs_brec_remove+0x473/0x560 [ 45.592589][ T9821] hfs_cat_move+0x6fb/0x960 [ 45.592598][ T9821] ? __pfx_hfs_cat_move+0x10/0x10 [ 45.592607][ T9821] ? seqcount_lockdep_reader_access+0x122/0x1c0 [ 45.592614][ T9821] ? lockdep_hardirqs_on+0x9c/0x150 [ 45.592631][ T9821] ? __lock_acquire+0xaec/0xd80 [ 45.592641][ T9821] hfs_rename+0x1dc/0x2d0 [ 45.592649][ T9821] ? __pfx_hfs_rename+0x10/0x10 [ 45.592657][ T9821] vfs_rename+0xac6/0xed0 [ 45.592664][ T9821] ? __pfx_vfs_rename+0x10/0x10 [ 45.592670][ T9821] ? d_alloc+0x144/0x190 [ 45.592677][ T9821] ? bpf_lsm_path_rename+0x9/0x20 [ 45.592683][ T9821] ? security_path_rename+0x17d/0x490 [ 45.592691][ T9821] do_renameat2+0x890/0xc50 [ 45.592699][ T9821] ? __pfx_do_renameat2+0x10/0x10 [ 45.592707][ T9821] ? getname_flags+0x1e5/0x540 [ 45.592714][ T9821] __x64_sys_rename+0x82/0x90 [ 45.592720][ T9821] ? entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 45.592725][ T9821] do_syscall_64+0xf3/0x3a0 [ 45.592741][ T9821] ? exc_page_fault+0x9f/0xf0 [ 45.592748][ T9821] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 45.592754][ T9821] RIP: 0033:0x7f7f73fe3fc9 [ 45.592760][ T9821] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 48 [ 45.592765][ T9821] RSP: 002b:00007ffc7e116cf8 EFLAGS: 00000283 ORIG_RAX: 0000000000000052 [ 45.592772][ T9821] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f7f73fe3fc9 [ 45.592776][ T9821] RDX: 0000200000000871 RSI: 0000200000000780 RDI: 00002000000003c0 [ 45.592781][ T9821] RBP: 00007ffc7e116d00 R08: 0000000000000000 R09: 00007ffc7e116d30 [ 45.592784][ T9821] R10: fffffffffffffff0 R11: 0000000000000283 R12: 00005557e81f8250 [ 45.592788][ T9821] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 45.592795][ T9821] </TASK> [ 45.592797][ T9821] [ 45.619721][ T9821] The buggy address belongs to the physical page: [ 45.620300][ T9821] page: refcount:1 mapcount:1 mapping:0000000000000000 index:0x559a88174 pfn:0x35935 [ 45.621150][ T9821] memcg:ffff88810a1d5b00 [ 45.621531][ T9821] anon flags: 0xfff60000020838(uptodate|dirty|lru|owner_2|swapbacked|node=0|zone=1|lastcpupid=0x7ff) [ 45.622496][ T9821] raw: 00fff60000020838 ffffea0000d64d88 ffff888021753e10 ffff888029da0771 [ 45.623260][ T9821] raw: 0000000559a88174 0000000000000000 0000000100000000 ffff88810a1d5b00 [ 45.624030][ T9821] page dumped because: kasan: bad access detected [ 45.624602][ T9821] page_owner tracks the page as allocated [ 45.625115][ T9821] page last allocated via order 0, migratetype Movable, gfp_mask 0x140dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO0 [ 45.626685][ T9821] post_alloc_hook+0x240/0x2a0 [ 45.627127][ T9821] get_page_from_freelist+0x2101/0x21e0 [ 45.627628][ T9821] __alloc_frozen_pages_noprof+0x274/0x380 [ 45.628154][ T9821] alloc_pages_mpol+0x241/0x4b0 [ 45.628593][ T9821] vma_alloc_folio_noprof+0xe4/0x210 [ 45.629066][ T9821] folio_prealloc+0x30/0x180 [ 45.629487][ T9821] __handle_mm_fault+0x34bd/0x5640 [ 45.629957][ T9821] handle_mm_fault+0x40e/0x8e0 [ 45.630392][ T9821] do_user_addr_fault+0xa81/0x1390 [ 45.630862][ T9821] exc_page_fault+0x76/0xf0 [ 45.631273][ T9821] asm_exc_page_fault+0x26/0x30 [ 45.631712][ T9821] page last free pid 5269 tgid 5269 stack trace: [ 45.632281][ T9821] free_unref_folios+0xc73/0x14c0 [ 45.632740][ T9821] folios_put_refs+0x55b/0x640 [ 45.633177][ T9821] free_pages_and_swap_cache+0x26d/0x510 [ 45.633685][ T9821] tlb_flush_mmu+0x3a0/0x680 [ 45.634105][ T9821] tlb_finish_mmu+0xd4/0x200 [ 45.634525][ T9821] exit_mmap+0x44c/0xb70 [ 45.634914][ T9821] __mmput+0x118/0x420 [ 45.635286][ T9821] exit_mm+0x1da/0x2c0 [ 45.635659][ T9821] do_exit+0x652/0x2330 [ 45.636039][ T9821] do_group_exit+0x21c/0x2d0 [ 45.636457][ T9821] __x64_sys_exit_group+0x3f/0x40 [ 45.636915][ T9821] x64_sys_call+0x21ba/0x21c0 [ 45.637342][ T9821] do_syscall_64+0xf3/0x3a0 [ 45.637756][ T9821] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 45.638290][ T9821] page has been migrated, last migrate reason: numa_misplaced [ 45.638956][ T9821] [ 45.639173][ T9821] Memory state around the buggy address: [ 45.639677][ T9821] ffff888035935300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 45.640397][ T9821] ffff888035935380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 45.641117][ T9821] >ffff888035935400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 45.641837][ T9821] ^ [ 45.642207][ T9821] ffff888035935480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 45.642929][ T9821] ffff888035935500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 45.643650][ T9821] ==================================================================
This commit [1] fixes the issue if an offset inside of b-tree node or length of the request is bigger than b-tree node. However, this fix is still not ready for negative values
of the offset or length. Moreover, negative values of the offset or length doesn't make sense for b-tree's operations. Because we could try to access the memory address outside of the beginning of memory page's addresses range. Also, using of negative values make logic very complicated, unpredictable, and we could access the wrong item(s)
in the b-tree node.
This patch changes b-tree interface by means of converting signed integer arguments of offset and length on u32 type. Such conversion has goal to prevent of using negative values unintentionally or by mistake in b-tree operations.
[1] 'commit a431930c9bac ("hfs: fix slab-out-of-bounds in hfs_bnode_read()")'
Stable-dep-of: 966cb76fb285 ("hfs/hfsplus: fix u32 overflow in check_and_correct_requested_length")
--- fs/hfs/bfind.c | 2 - fs/hfs/bnode.c | 52 ++++++++++++++-------------- fs/hfs/brec.c | 2 - fs/hfs/btree.c | 2 - fs/hfs/btree.h | 71 +++++++++++++++++++------------------- fs/hfs/hfs_fs.h | 88 ++++++++++++++++++++++++++++-------------------- fs/hfs/inode.c | 3 + fs/hfsplus/bfind.c | 2 - fs/hfsplus/bnode.c | 60 ++++++++++++++++---------------- fs/hfsplus/brec.c | 2 - fs/hfsplus/btree.c | 2 - fs/hfsplus/hfsplus_fs.h | 38 ++++++++++---------- 12 files changed, 171 insertions(+), 153 deletions(-)
fs/hfs/bfind.c +1 -1
@@ -167,7 +167,7 @@ release:return res; } -int hfs_brec_read (struct hfs_find_data *fd,void *rec,int rec_len) +int hfs_brec_read (struct hfs_find_data *fd,void *rec,u32 rec_len) {int res;
fs/hfs/bnode.c +26 -26
172 lines not on this page · raw message
fs/hfs/brec.c +1 -1
@@ -62,7 +62,7 @@ u16 hfs_brec_keylen(struct hfs_bnode *noreturn retval; } -int hfs_brec_insert (struct hfs_find_data *fd,void *entry,int entry_len) +int hfs_brec_insert (struct hfs_find_data *fd,void *entry,u32 entry_len) {struct hfs_btree *tree;struct hfs_bnode *node, *new_node;
fs/hfs/btree.c +1 -1
@@ -259,7 +259,7 @@ static struct hfs_bnode *hfs_bmap_new_bm }/* Make sure @tree has enough space for the @rsvd_nodes */ -int hfs_bmap_reserve (struct hfs_btree *tree,int rsvd_nodes) +int hfs_bmap_reserve (struct hfs_btree *tree,u32 rsvd_nodes) {struct inode *inode = tree->inode;u32 count;
fs/hfs/btree.h +36 -35
84 lines not on this page · raw message
fs/hfs/hfs_fs.h +52 -36
126 lines not on this page · raw message
fs/hfs/inode.c +2 -1
@@ -45,7 +45,8 @@ static void hfs_write_failed(struct addr }int hfs_write_begin (const struct kiocb *iocb,struct address_space *mapping, -loff_t pos,unsigned len,struct folio **foliop,void **fsdata) +loff_t pos,unsigned int len,struct folio **foliop, +void **fsdata) {int ret;
fs/hfsplus/bfind.c +1 -1
@@ -210,7 +210,7 @@ release:return res; } -int hfs_brec_read (struct hfs_find_data *fd,void *rec,int rec_len) +int hfs_brec_read (struct hfs_find_data *fd,void *rec,u32 rec_len) {int res;
fs/hfsplus/bnode.c +30 -30
200 lines not on this page · raw message
fs/hfsplus/brec.c +1 -1
@@ -60,7 +60,7 @@ u16 hfs_brec_keylen(struct hfs_bnode *noreturn retval; } -int hfs_brec_insert (struct hfs_find_data *fd,void *entry,int entry_len) +int hfs_brec_insert (struct hfs_find_data *fd,void *entry,u32 entry_len) {struct hfs_btree *tree;struct hfs_bnode *node, *new_node;
fs/hfsplus/btree.c +1 -1
@@ -344,7 +344,7 @@ static struct hfs_bnode *hfs_bmap_new_bm }/* Make sure @tree has enough space for the @rsvd_nodes */ -int hfs_bmap_reserve (struct hfs_btree *tree,int rsvd_nodes) +int hfs_bmap_reserve (struct hfs_btree *tree,u32 rsvd_nodes) {struct inode *inode = tree->inode;struct hfsplus_inode_info *hip =HFSPLUS_I (inode);
fs/hfsplus/hfsplus_fs.h +19 -19
@@ -357,21 +357,21 @@ u32 hfsplus_calc_btree_clump_size(u32 blstruct hfs_btree *hfs_btree_open (struct super_block *sb,u32 id);void hfs_btree_close (struct hfs_btree *tree);int hfs_btree_write (struct hfs_btree *tree); -int hfs_bmap_reserve (struct hfs_btree *tree,int rsvd_nodes); +int hfs_bmap_reserve (struct hfs_btree *tree,u32 rsvd_nodes);struct hfs_bnode *hfs_bmap_alloc (struct hfs_btree *tree);void hfs_bmap_free (struct hfs_bnode *node);/* bnode.c */ -void hfs_bnode_read (struct hfs_bnode *node,void *buf,int off,int len); -u16 hfs_bnode_read_u16 (struct hfs_bnode *node,int off); -u8 hfs_bnode_read_u8 (struct hfs_bnode *node,int off); -void hfs_bnode_read_key (struct hfs_bnode *node,void *key,int off); -void hfs_bnode_write (struct hfs_bnode *node,void *buf,int off,int len); -void hfs_bnode_write_u16 (struct hfs_bnode *node,int off,u16 data); -void hfs_bnode_clear (struct hfs_bnode *node,int off,int len); -void hfs_bnode_copy (struct hfs_bnode *dst_node,int dst, -struct hfs_bnode *src_node,int src,int len); -void hfs_bnode_move (struct hfs_bnode *node,int dst,int src,int len); +void hfs_bnode_read (struct hfs_bnode *node,void *buf,u32 off,u32 len); +u16 hfs_bnode_read_u16 (struct hfs_bnode *node,u32 off); +u8 hfs_bnode_read_u8 (struct hfs_bnode *node,u32 off); +void hfs_bnode_read_key (struct hfs_bnode *node,void *key,u32 off); +void hfs_bnode_write (struct hfs_bnode *node,void *buf,u32 off,u32 len); +void hfs_bnode_write_u16 (struct hfs_bnode *node,u32 off,u16 data); +void hfs_bnode_clear (struct hfs_bnode *node,u32 off,u32 len); +void hfs_bnode_copy (struct hfs_bnode *dst_node,u32 dst, +struct hfs_bnode *src_node,u32 src,u32 len); +void hfs_bnode_move (struct hfs_bnode *node,u32 dst,u32 src,u32 len);void hfs_bnode_dump (struct hfs_bnode *node);void hfs_bnode_unlink (struct hfs_bnode *node);struct hfs_bnode *hfs_bnode_findhash (struct hfs_btree *tree,u32 cnid);
@@ -386,7 +386,7 @@ bool hfs_bnode_need_zeroout(struct hfs_b/* brec.c */ u16 hfs_brec_lenoff (struct hfs_bnode *node,u16 rec,u16 *off);u16 hfs_brec_keylen (struct hfs_bnode *node,u16 rec); -int hfs_brec_insert (struct hfs_find_data *fd,void *entry,int entry_len); +int hfs_brec_insert (struct hfs_find_data *fd,void *entry,u32 entry_len);int hfs_brec_remove (struct hfs_find_data *fd);/* bfind.c */
@@ -399,7 +399,7 @@ int hfs_find_rec_by_key(struct hfs_bnodeint __hfs_brec_find (struct hfs_bnode *bnode,struct hfs_find_data *fd,search_strategy_t rec_found);int hfs_brec_find (struct hfs_find_data *fd,search_strategy_t do_key_compare); -int hfs_brec_read (struct hfs_find_data *fd,void *rec,int rec_len); +int hfs_brec_read (struct hfs_find_data *fd,void *rec,u32 rec_len);int hfs_brec_goto (struct hfs_find_data *fd,int cnt);/* catalog.c */
@@ -560,14 +560,14 @@ hfsplus_btree_lock_class(struct hfs_btre }static inline -bool is_bnode_offset_valid (struct hfs_bnode *node,int off) +bool is_bnode_offset_valid (struct hfs_bnode *node,u32 off) {bool is_valid = off < node->tree->node_size;if (!is_valid) {pr_err ("requested invalid offset: " "NODE: id %u, type %#x, height %u, " -"node_size %u, offset %d\n" , +"node_size %u, offset %u\n" , node->this, node->type, node->height, node->tree->node_size, off); }
@@ -576,7 +576,7 @@ bool is_bnode_offset_valid(struct hfs_bn }static inline -int check_and_correct_requested_length (struct hfs_bnode *node,int off,int len) +u32 check_and_correct_requested_length (struct hfs_bnode *node,u32 off,u32 len) {unsigned int node_size;
@@ -586,12 +586,12 @@ int check_and_correct_requested_length(s node_size = node->tree->node_size;if ((off + len) > node_size) { -int new_len = (int )node_size - off; +u32 new_len = node_size - off;pr_err ("requested length has been corrected: " "NODE: id %u, type %#x, height %u, " -"node_size %u, offset %d, " -"requested_len %d, corrected_len %d\n" , +"node_size %u, offset %u, " +"requested_len %u, corrected_len %u\n" , node->this, node->type, node->height, node->tree->node_size, off, len, new_len);
Greg Kroah-Hartman
maintainerPATCH 1563/1611 hfs/hfsplus: fix u32 overflow in check_and_correct_requested_length
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
[ Upstream commit 966cb76fb2857a4242cab6ea2ea17acf818a3da7 ]
check_and_correct_requested_length() compares (off + len) against node_size using u32 arithmetic. When the caller passes a large len value (e.g. from an underflowed subtraction in hfs_brec_remove()), off + len can wrap past 2^32 and produce a small result, causing the bounds check to pass when it should fail.
For example, with off=14 and len=0xFFFFFFF2 (underflowed from data_off - keyoffset - size in hfs_brec_remove), off + len wraps to 6, which is less than a typical node_size of 512, so the check passes and the subsequent memmove reads ~4GB past the node buffer.
Fix this by widening the addition to u64 before comparing against node_size. This prevents the u32 wrap while keeping the logic straightforward.
--- fs/hfs/bnode.c | 2 +- fs/hfsplus/hfsplus_fs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/hfs/bnode.c +1 -1
@@ -41,7 +41,7 @@ u32 check_and_correct_requested_length(s node_size = node->tree->node_size; -if ((off + len) > node_size) { +if ((u64 )off + len > node_size) {u32 new_len = node_size - off; pr_err("requested length has been corrected: "
fs/hfsplus/hfsplus_fs.h +1 -1
@@ -585,7 +585,7 @@ u32 check_and_correct_requested_length(s node_size = node->tree->node_size; -if ((off + len) > node_size) { +if ((u64 )off + len > node_size) {u32 new_len = node_size - off; pr_err("requested length has been corrected: "
Greg Kroah-Hartman
maintainerPATCH 1564/1611 xfs: initialize iomap->flags earlier in xfs_bmbt_to_iomap
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 327e58826eb72f8bae9419cf1a4e722b57c85694 ]
Otherwise we lose the IOMAP_IOEND_BOUNDARY assingment for writes to the first block in a realtime group, and could cause incorrect merges for such writes.
--- fs/xfs/xfs_iomap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_iomap.c +1 -1
@@ -113,6 +113,7 @@ xfs_bmbt_to_iomap(return xfs_alert_fsblock_zero (ip, imap); } + iomap->flags = iomap_flags;if (imap->br_startblock ==HOLESTARTBLOCK ) { iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_HOLE ;
@@ -147,7 +148,6 @@ xfs_bmbt_to_iomap( iomap->dax_dev = target->bt_daxdev; else iomap->bdev = target->bt_bdev; - iomap->flags = iomap_flags;/* * If the inode is dirty for datasync purposes, let iomap know so it
Greg Kroah-Hartman
maintainerPATCH 1565/1611 bpf: Consistently use reg_state() for register access in the verifier
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mykyta Yatsenko <[email protected]>
[ Upstream commit 7af3339948601e188d93d7e03326aeb8fcbd6bea ]
Replace the pattern of declaring a local regs array from cur_regs() and then indexing into it with the more concise reg_state() helper. This simplifies the code by eliminating intermediate variables and makes register access more consistent throughout the verifier.
Stable-dep-of: 53040a81ae57 ("bpf: Keep dynamic inner array lookups nullable")
--- kernel/bpf/verifier.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-)
kernel/bpf/verifier.c +19 -23
@@ -5690,8 +5690,8 @@ static int check_stack_write(struct bpf_static int check_map_access_type (struct bpf_verifier_env *env,u32 regno,int off,int size,enum bpf_access_type type) { -struct bpf_reg_state *regs =cur_regs (env); -struct bpf_map *map = regs[regno].map_ptr; +struct bpf_reg_state *reg =reg_state (env, regno); +struct bpf_map *map = reg->map_ptr;u32 cap =bpf_map_flags_to_cap (map);if (type ==BPF_WRITE && !(cap &BPF_MAP_CAN_WRITE )) {
@@ -6195,8 +6195,7 @@ static bool may_access_direct_pkt_data(sstatic int check_packet_access (struct bpf_verifier_env *env,u32 regno,int off,int size,bool zero_size_allowed) { -struct bpf_reg_state *regs =cur_regs (env); -struct bpf_reg_state *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);int err;/* We may have added a variable offset to the packet pointer; but any
@@ -6283,8 +6282,7 @@ static int check_sock_access(struct bpf_ u32 regno, int off, int size, enum bpf_access_type t) { - struct bpf_reg_state *regs = cur_regs(env); -struct bpf_reg_state *reg = ®s[regno]; + struct bpf_reg_state *reg = reg_state(env, regno);struct bpf_insn_access_aux info = {};bool valid;
@@ -7469,8 +7467,7 @@ static int check_stack_access_within_bou int regno, int off, int access_size, enum bpf_access_type type) { - struct bpf_reg_state *regs = cur_regs(env); -struct bpf_reg_state *reg = regs + regno; + struct bpf_reg_state *reg = reg_state(env, regno);struct bpf_func_state *state =func (env, reg);s64 min_off, max_off;int err;
@@ -8414,7 +8411,7 @@ static int process_spin_lock(struct bpf_ {bool is_lock = flags &PROCESS_SPIN_LOCK , is_res_lock = flags &PROCESS_RES_LOCK ;const char *lock_str = is_res_lock ?"bpf_res_spin" :"bpf_spin" ; -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);struct bpf_verifier_state *cur = env->cur_state;bool is_const =tnum_is_const (reg->var_off);bool is_irq = flags &PROCESS_LOCK_IRQ ;
@@ -8530,7 +8527,7 @@ static int process_spin_lock(struct bpf_static int check_map_field_pointer (struct bpf_verifier_env *env,u32 regno,enum btf_field_type field_type) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);bool is_const =tnum_is_const (reg->var_off);struct bpf_map *map = reg->map_ptr;u64 val = reg->var_off.value;
@@ -8577,7 +8574,7 @@ static int check_map_field_pointer(strucstatic int process_timer_func (struct bpf_verifier_env *env,int regno,struct bpf_call_arg_meta *meta) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);struct bpf_map *map = reg->map_ptr;int err;
@@ -8601,7 +8598,7 @@ static int process_timer_func(struct bpfstatic int process_wq_func (struct bpf_verifier_env *env,int regno,struct bpf_kfunc_call_arg_meta *meta) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);struct bpf_map *map = reg->map_ptr;int err;
@@ -8622,7 +8619,7 @@ static int process_wq_func(struct bpf_vestatic int process_task_work_func (struct bpf_verifier_env *env,int regno,struct bpf_kfunc_call_arg_meta *meta) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);struct bpf_map *map = reg->map_ptr;int err;
@@ -8642,7 +8639,7 @@ static int process_task_work_func(structstatic int process_kptr_func (struct bpf_verifier_env *env,int regno,struct bpf_call_arg_meta *meta) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);struct btf_field *kptr_field;struct bpf_map *map_ptr;struct btf_record *rec;
@@ -8715,7 +8712,7 @@ static int process_kptr_func(struct bpf_static int process_dynptr_func (struct bpf_verifier_env *env,int regno,int insn_idx,enum bpf_arg_type arg_type,int clone_ref_obj_id) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);int err;if (reg->type !=PTR_TO_STACK && reg->type !=CONST_PTR_TO_DYNPTR ) {
@@ -8835,7 +8832,7 @@ static bool is_kfunc_arg_iter(struct bpfstatic int process_iter_arg (struct bpf_verifier_env *env,int regno,int insn_idx,struct bpf_kfunc_call_arg_meta *meta) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);const struct btf_type *t;int spi, err, i, nr_slots, btf_id;
@@ -9307,7 +9304,7 @@ static int check_reg_type(struct bpf_verconst u32 *arg_btf_id, struct bpf_call_arg_meta *meta) { - struct bpf_reg_state *regs = cur_regs(env), *reg = ®s[regno]; + struct bpf_reg_state *reg = reg_state(env, regno);enum bpf_reg_type expected, type = reg->type;const struct bpf_reg_types *compatible;int i, j;
@@ -9720,7 +9717,7 @@ static int check_func_arg(struct bpf_ver int insn_idx) {u32 regno =BPF_REG_1 + arg; -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);enum bpf_arg_type arg_type = fn->arg_type[arg];enum bpf_reg_type type = reg->type;u32 *arg_btf_id =NULL ;
@@ -11250,7 +11247,7 @@ record_func_key(struct bpf_verifier_env int func_id, int insn_idx) {struct bpf_insn_aux_data *aux = &env->insn_aux_data[insn_idx]; -struct bpf_reg_state *regs =cur_regs (env), *reg; +struct bpf_reg_state *reg;struct bpf_map *map = meta->map_ptr;u64 val, max;int err;
@@ -11262,7 +11259,7 @@ record_func_key(struct bpf_verifier_envreturn -EINVAL ; } - reg = ®s[BPF_REG_3 ]; + reg =reg_state (env,BPF_REG_3 ); val = reg->var_off.value; max = map->max_entries;
@@ -11408,8 +11405,7 @@ static struct bpf_insn_aux_data *cur_auxstatic bool loop_flag_is_zero (struct bpf_verifier_env *env) { -struct bpf_reg_state *regs =cur_regs (env); -struct bpf_reg_state *reg = ®s[BPF_REG_4 ]; +struct bpf_reg_state *reg =reg_state (env,BPF_REG_4 );bool reg_is_null =register_is_null (reg);if (reg_is_null)
@@ -12680,7 +12676,7 @@ static int process_kf_arg_ptr_to_btf_id(static int process_irq_flag (struct bpf_verifier_env *env,int regno,struct bpf_kfunc_call_arg_meta *meta) { -struct bpf_reg_state *regs =cur_regs (env), *reg = ®s[regno]; +struct bpf_reg_state *reg =reg_state (env, regno);int err, kfunc_class =IRQ_NATIVE_KFUNC ;bool irq_save;
Greg Kroah-Hartman
maintainerPATCH 1566/1611 bpf: Introduce struct bpf_map_desc in verifier
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mykyta Yatsenko <[email protected]>
[ Upstream commit 98c4fd2963cb2bc5eae22b5365e6bbf3a5cd0f14 ]
Introduce struct bpf_map_desc to hold bpf_map pointer and map uid. Use this struct in both bpf_call_arg_meta and bpf_kfunc_call_arg_meta instead of having different representations:
- bpf_call_arg_meta had separate map_ptr and map_uid fields
- bpf_kfunc_call_arg_meta had an anonymous inline struct
This unifies the map fields layout across both metadata structures, making the code more consistent and preparing for further refactoring of map field pointer validation.
Stable-dep-of: 53040a81ae57 ("bpf: Keep dynamic inner array lookups nullable")
--- kernel/bpf/verifier.c | 79 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-)
kernel/bpf/verifier.c +40 -39
@@ -274,8 +274,13 @@ static bool bpf_pseudo_kfunc_call(const insn->src_reg ==BPF_PSEUDO_KFUNC_CALL ; } +struct bpf_map_desc { +struct bpf_map *ptr; +int uid; +}; +struct bpf_call_arg_meta { -struct bpf_map *map_ptr; +struct bpf_map_desc map;bool raw_mode;bool pkt_access;u8 release_regno;
@@ -285,7 +290,6 @@ struct bpf_call_arg_meta {u64 msize_max_value;int ref_obj_id;int dynptr_id; -int map_uid;int func_id;struct btf *btf;u32 btf_id;
@@ -345,10 +349,7 @@ struct bpf_kfunc_call_arg_meta {u8 spi;u8 frameno; } iter; -struct { -struct bpf_map *ptr; -int uid; - } map; +struct bpf_map_desc map;u64 mem_size; };
@@ -8582,7 +8583,7 @@ static int process_timer_func(struct bpfif (err)return err; -if (meta->map_ptr) { +if (meta->map.ptr) {verifier_bug (env,"Two map pointers in a timer helper" );return -EFAULT ; }
@@ -8590,8 +8591,8 @@ static int process_timer_func(struct bpfverbose (env,"bpf_timer cannot be used for PREEMPT_RT.\n" );return -EOPNOTSUPP ; } - meta->map_uid = reg->map_uid; - meta->map_ptr = map; + meta->map.uid = reg->map_uid; + meta->map.ptr = map;return 0 ; }
@@ -8655,7 +8656,7 @@ static int process_kptr_func(struct bpf_return -EINVAL ; } rec = map_ptr->record; - meta->map_ptr = map_ptr; + meta->map.ptr = map_ptr; }if (!tnum_is_const (reg->var_off)) {
@@ -9162,13 +9163,13 @@ static int resolve_map_arg_type(struct b const struct bpf_call_arg_meta *meta, enum bpf_arg_type *arg_type) { - if (!meta->map_ptr) { + if (!meta->map.ptr) { /* kernel subsystem misconfigured verifier */ verifier_bug(env, "invalid map_ptr to access map->type");return -EFAULT ; } -switch (meta->map_ptr->map_type) { +switch (meta->map.ptr->map_type) {case BPF_MAP_TYPE_SOCKMAP :case BPF_MAP_TYPE_SOCKHASH :if (*arg_type ==ARG_PTR_TO_MAP_VALUE ) {
@@ -9817,7 +9818,7 @@ skip_type_check:switch (base_type (arg_type)) {case ARG_CONST_MAP_PTR :/* bpf_map_xxx(map_ptr) call: remember that map_ptr */ -if (meta->map_ptr) { +if (meta->map.ptr) {/* Use map_uid (which is unique id of inner map) to reject: * inner_map1 = bpf_map_lookup_elem(outer_map, key1) * inner_map2 = bpf_map_lookup_elem(outer_map, key2)
@@ -9830,23 +9831,23 @@ skip_type_check:* * Comparing map_ptr is enough to distinguish normal and outer maps. */ -if (meta->map_ptr != reg->map_ptr || - meta->map_uid != reg->map_uid) { +if (meta->map.ptr != reg->map_ptr || + meta->map.uid != reg->map_uid) {verbose (env,"timer pointer in R1 map_uid=%d doesn't match map pointer in R2 map_uid=%d\n" , - meta->map_uid, reg->map_uid); + meta->map.uid, reg->map_uid);return -EINVAL ; } } - meta->map_ptr = reg->map_ptr; - meta->map_uid = reg->map_uid; + meta->map.ptr = reg->map_ptr; + meta->map.uid = reg->map_uid;break ;case ARG_PTR_TO_MAP_KEY :/* bpf_map_xxx(..., map_ptr, ..., key) call: * check that [key, key + map->key_size) are within * stack limits and initialized */ -if (!meta->map_ptr) { +if (!meta->map.ptr) {/* in function declaration map_ptr must come before * map_key, so that it's verified and known before * we have to check map_key here. Otherwise it means
@@ -9855,11 +9856,11 @@ skip_type_check:verifier_bug (env,"invalid map_ptr to access map->key" );return -EFAULT ; } - key_size = meta->map_ptr->key_size; + key_size = meta->map.ptr->key_size; err =check_helper_mem_access (env, regno, key_size,BPF_READ , false,NULL );if (err)return err; -if (can_elide_value_nullness (meta->map_ptr->map_type)) { +if (can_elide_value_nullness (meta->map.ptr->map_type)) { err =get_constant_map_key (env, reg, key_size, &meta->const_map_key);if (err <0 ) { meta->const_map_key =-1 ;
@@ -9877,13 +9878,13 @@ skip_type_check:/* bpf_map_xxx(..., map_ptr, ..., value) call: * check [value, value + map->value_size) validity */ -if (!meta->map_ptr) { +if (!meta->map.ptr) {/* kernel subsystem misconfigured verifier */ verifier_bug (env,"invalid map_ptr to access map->value" );return -EFAULT ; } meta->raw_mode = arg_type &MEM_UNINIT ; - err =check_helper_mem_access (env, regno, meta->map_ptr->value_size, + err =check_helper_mem_access (env, regno, meta->map.ptr->value_size, arg_type &MEM_WRITE ?BPF_WRITE :BPF_READ , false, meta);break ;
@@ -11201,7 +11202,7 @@ record_func_map(struct bpf_verifier_env int func_id, int insn_idx) {struct bpf_insn_aux_data *aux = &env->insn_aux_data[insn_idx]; -struct bpf_map *map = meta->map_ptr; +struct bpf_map *map = meta->map.ptr; if (func_id != BPF_FUNC_tail_call && func_id != BPF_FUNC_map_lookup_elem &&
@@ -11234,11 +11235,11 @@ record_func_map(struct bpf_verifier_env }if (!aux->map_ptr_state.map_ptr) -bpf_map_ptr_store (aux, meta->map_ptr, - !meta->map_ptr->bypass_spec_v1, false); -else if (aux->map_ptr_state.map_ptr != meta->map_ptr) -bpf_map_ptr_store (aux, meta->map_ptr, - !meta->map_ptr->bypass_spec_v1, true); +bpf_map_ptr_store (aux, meta->map.ptr, + !meta->map.ptr->bypass_spec_v1, false); +else if (aux->map_ptr_state.map_ptr != meta->map.ptr) +bpf_map_ptr_store (aux, meta->map.ptr, + !meta->map.ptr->bypass_spec_v1, true);return 0 ; }
@@ -11248,7 +11249,7 @@ record_func_key(struct bpf_verifier_env {struct bpf_insn_aux_data *aux = &env->insn_aux_data[insn_idx];struct bpf_reg_state *reg; -struct bpf_map *map = meta->map_ptr; +struct bpf_map *map = meta->map.ptr;u64 val, max;int err;
@@ -11814,22 +11815,22 @@ static int check_helper_call(struct bpf_* can check 'value_size' boundary of memory access * to map element returned from bpf_map_lookup_elem() */ -if (meta.map_ptr ==NULL ) { +if (meta.map.ptr ==NULL ) {verifier_bug (env,"unexpected null map_ptr" );return -EFAULT ; }if (func_id == BPF_FUNC_map_lookup_elem && -can_elide_value_nullness (meta.map_ptr->map_type) && +can_elide_value_nullness (meta.map.ptr->map_type) && meta.const_map_key >=0 && - meta.const_map_key < meta.map_ptr->max_entries) + meta.const_map_key < meta.map.ptr->max_entries) ret_flag &= ~PTR_MAYBE_NULL ; - regs[BPF_REG_0 ].map_ptr = meta.map_ptr; - regs[BPF_REG_0 ].map_uid = meta.map_uid; + regs[BPF_REG_0 ].map_ptr = meta.map.ptr; + regs[BPF_REG_0 ].map_uid = meta.map.uid; regs[BPF_REG_0 ].type =PTR_TO_MAP_VALUE | ret_flag;if (!type_may_be_null (ret_flag) && -btf_record_has_field (meta.map_ptr->record,BPF_SPIN_LOCK |BPF_RES_SPIN_LOCK )) { +btf_record_has_field (meta.map.ptr->record,BPF_SPIN_LOCK |BPF_RES_SPIN_LOCK )) { regs[BPF_REG_0 ].id = ++env->id_gen; }break ;
@@ -11932,7 +11933,7 @@ static int check_helper_call(struct bpf_if (type_may_be_null (regs[BPF_REG_0 ].type)) regs[BPF_REG_0 ].id = ++env->id_gen; -if (helper_multiple_ref_obj_use (func_id, meta.map_ptr)) { +if (helper_multiple_ref_obj_use (func_id, meta.map.ptr)) {verifier_bug (env,"func %s#%d sets ref_obj_id more than once" ,func_id_name (func_id), func_id);return -EFAULT ;
@@ -11944,7 +11945,7 @@ static int check_helper_call(struct bpf_if (is_ptr_cast_function (func_id) ||is_dynptr_ref_function (func_id)) {/* For release_reference() */ regs[BPF_REG_0 ].ref_obj_id = meta.ref_obj_id; - }else if (is_acquire_function (func_id, meta.map_ptr)) { + }else if (is_acquire_function (func_id, meta.map.ptr)) {int id =acquire_reference (env, insn_idx);if (id <0 )
@@ -11959,7 +11960,7 @@ static int check_helper_call(struct bpf_if (err)return err; - err =check_map_func_compatibility (env, meta.map_ptr, func_id); + err =check_map_func_compatibility (env, meta.map.ptr, func_id);if (err)return err;
Greg Kroah-Hartman
maintainerPATCH 1567/1611 bpf: Keep dynamic inner array lookups nullable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuoqi Gui <[email protected]>
[ Upstream commit 53040a81ae57cdca8af8ac36fe4e661730cf7c6b ]
An ARRAY_OF_MAPS can use an array created with BPF_F_INNER_MAP as its inner map template. A concrete inner array with a different max_entries value can then replace the template.
After a successful outer map lookup, the verifier represents the resulting map pointer using the inner map template. Const-key lookup nullness elision consequently uses the template max_entries even though the runtime helper uses the concrete inner map max_entries.
Do not elide lookup result nullness for maps marked with BPF_F_INNER_MAP, because the template max_entries does not prove that the key is in bounds for the concrete runtime map.
--- kernel/bpf/verifier.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/bpf/verifier.c +9 -6
@@ -9710,7 +9710,7 @@ static int get_constant_map_key(struct breturn 0 ; } -static bool can_elide_value_nullness (enum bpf_map_type type); +static bool can_elide_value_nullness (const struct bpf_map *map); static int check_func_arg(struct bpf_verifier_env *env, u32 arg, struct bpf_call_arg_meta *meta,
@@ -9860,7 +9860,7 @@ skip_type_check: err =check_helper_mem_access (env, regno, key_size,BPF_READ , false,NULL );if (err)return err; -if (can_elide_value_nullness (meta->map.ptr->map_type)) { +if (can_elide_value_nullness (meta->map.ptr)) { err =get_constant_map_key (env, reg, key_size, &meta->const_map_key);if (err <0 ) { meta->const_map_key =-1 ;
@@ -11433,13 +11433,16 @@ static void update_loop_inline_state(str state->callback_subprogno == subprogno); } -/* Returns whether or not the given map type can potentially elide +/* Returns whether or not the given map can potentially elide * lookup return value nullness check. This is possible if the key * is statically known. */ -static bool can_elide_value_nullness (enum bpf_map_type type) +static bool can_elide_value_nullness (const struct bpf_map *map) { -switch (type) { +if (map->map_flags &BPF_F_INNER_MAP ) +return false; + +switch (map->map_type) {case BPF_MAP_TYPE_ARRAY :case BPF_MAP_TYPE_PERCPU_ARRAY :return true;
@@ -11821,7 +11824,7 @@ static int check_helper_call(struct bpf_ }if (func_id == BPF_FUNC_map_lookup_elem && -can_elide_value_nullness (meta.map.ptr->map_type) && +can_elide_value_nullness (meta.map.ptr) && meta.const_map_key >=0 && meta.const_map_key < meta.map.ptr->max_entries) ret_flag &= ~PTR_MAYBE_NULL ;
Greg Kroah-Hartman
maintainerPATCH 1568/1611 bpf: Consistently use bpf_rcu_lock_held() everywhere
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrii Nakryiko <[email protected]>
[ Upstream commit 48a97ffc6c826640907d13b199e29008f4fe2c15 ]
We have many places which open-code what's now is bpf_rcu_lock_held() macro, so replace all those places with a clean and short macro invocation. For that, move bpf_rcu_lock_held() macro into include/linux/bpf.h.
Stable-dep-of: 2f884d371faf ("bpf: Allow LPM map access from sleepable BPF programs")
--- include/linux/bpf.h | 3 +++ include/linux/bpf_local_storage.h | 3 --- kernel/bpf/hashtab.c | 21 +++++++-------------- kernel/bpf/helpers.c | 12 ++++-------- 4 files changed, 14 insertions(+), 25 deletions(-)
include/linux/bpf.h +3 -0
@@ -2375,6 +2375,9 @@ bpf_prog_run_array_uprobe(const struct bbool bpf_jit_bypass_spec_v1 (void );bool bpf_jit_bypass_spec_v4 (void ); +#define bpf_rcu_lock_held () \ + (rcu_read_lock_held() || rcu_read_lock_trace_held() || rcu_read_lock_bh_held()) +#ifdef CONFIG_BPF_SYSCALL DECLARE_PER_CPU (int, bpf_prog_active);extern struct mutex bpf_stats_enabled_mutex;
include/linux/bpf_local_storage.h +0 -3
@@ -18,9 +18,6 @@#define BPF_LOCAL_STORAGE_CACHE_SIZE 16 -#define bpf_rcu_lock_held () \ - (rcu_read_lock_held() || rcu_read_lock_trace_held() || \ - rcu_read_lock_bh_held())struct bpf_local_storage_map_bucket {struct hlist_head list;raw_spinlock_t lock;
kernel/bpf/hashtab.c +7 -14
@@ -669,8 +669,7 @@ static void *__htab_map_lookup_elem(strustruct htab_elem *l;u32 hash, key_size; -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ()); key_size = map->key_size;
@@ -1104,8 +1103,7 @@ static long htab_map_update_elem(struct/* unknown flags */ return -EINVAL ; -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ()); key_size = map->key_size;
@@ -1212,8 +1210,7 @@ static long htab_lru_map_update_elem(str/* unknown flags */ return -EINVAL ; -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ()); key_size = map->key_size;
@@ -1281,8 +1278,7 @@ static long htab_map_update_elem_in_plac/* unknown flags */ return -EINVAL ; -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ()); key_size = map->key_size;
@@ -1344,8 +1340,7 @@ static long __htab_lru_percpu_map_update/* unknown flags */ return -EINVAL ; -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ()); key_size = map->key_size;
@@ -1422,8 +1417,7 @@ static long htab_map_delete_elem(structu32 hash, key_size;int ret; -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ()); key_size = map->key_size;
@@ -1458,8 +1452,7 @@ static long htab_lru_map_delete_elem(stru32 hash, key_size;int ret; -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ()); key_size = map->key_size;
kernel/bpf/helpers.c +4 -8
@@ -42,8 +42,7 @@*/ BPF_CALL_2(bpf_map_lookup_elem, struct bpf_map *, map, void *, key) { -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ());return (unsigned long ) map->ops->map_lookup_elem (map, key); }
@@ -59,8 +58,7 @@ const struct bpf_func_proto bpf_map_look BPF_CALL_4(bpf_map_update_elem, struct bpf_map *, map, void *, key, void *, value, u64, flags) { -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ());return map->ops->map_update_elem (map, key, value, flags); }
@@ -77,8 +75,7 @@ const struct bpf_func_proto bpf_map_upda BPF_CALL_2(bpf_map_delete_elem, struct bpf_map *, map, void *, key) { -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ());return map->ops->map_delete_elem (map, key); }
@@ -134,8 +131,7 @@ const struct bpf_func_proto bpf_map_peek BPF_CALL_3(bpf_map_lookup_percpu_elem, struct bpf_map *, map, void *, key, u32, cpu) { -WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () && - !rcu_read_lock_bh_held ()); +WARN_ON_ONCE (!bpf_rcu_lock_held ());return (unsigned long ) map->ops->map_lookup_percpu_elem (map, key, cpu); }
Greg Kroah-Hartman
maintainerPATCH 1569/1611 bpf: Allow LPM map access from sleepable BPF programs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Poenaru <[email protected]>
[ Upstream commit 2f884d371fafea137afea504d49ee4a7c8d7985b ]
trie_lookup_elem() annotates its rcu_dereference_check() walks with only rcu_read_lock_bh_held(). Because rcu_dereference_check(p, c) resolves to "c || rcu_read_lock_held()", this passes for XDP/NAPI and classic RCU readers but fails for sleepable BPF programs, which enter via __bpf_prog_enter_sleepable() and hold only rcu_read_lock_trace().
trie_update_elem() and trie_delete_elem() have the same problem in a different form: they walk the trie with plain rcu_dereference(), which asserts rcu_read_lock_held() unconditionally. Both are reachable from sleepable BPF programs via the bpf_map_update_elem / bpf_map_delete_elem helpers, and from the syscall path under classic rcu_read_lock(). In the writer paths the trie is actually protected by trie->lock (an rqspinlock taken across the walk); we never relied on the RCU read-side lock to keep nodes alive there.
A sleepable LSM hook that ends up touching an LPM trie therefore triggers lockdep on debug kernels:
=============================
WARNING: suspicious RCU usage
7.1.0-... Tainted: G E
-----------------------------
kernel/bpf/lpm_trie.c:249 suspicious rcu_dereference_check() usage! 1 lock held by net_tests/540:
#0: (rcu_tasks_trace_srcu_struct){....}-{0:0},
at: __bpf_prog_enter_sleepable+0x26/0x280 Call Trace: dump_stack_lvl lockdep_rcu_suspicious trie_lookup_elem bpf_prog_..._enforce_security_socket_connect bpf_trampoline_... security_socket_connect __sys_connect do_syscall_64
This is lockdep-only -- no UAF, since Tasks Trace RCU does serialize against the trie's reclaim path -- but it spams the console once per distinct callsite on every debug kernel running a sleepable BPF LSM that touches an LPM trie, which is increasingly common.
For the lookup path, switch the rcu_dereference_check() annotation from rcu_read_lock_bh_held() to bpf_rcu_lock_held(), which accepts all three contexts (classic, BH, Tasks Trace). Other map types already follow this convention.
For trie_update_elem() and trie_delete_elem(), annotate the walks as rcu_dereference_protected(*p, 1) -- matching trie_free() in the same file -- since trie->lock is held across the walk. rqspinlock has no lockdep_map, so the predicate degenerates to '1' rather than lockdep_is_held(&trie->lock); the protection is real but not machine-verifiable. trie_get_next_key() also uses bare rcu_dereference() but is reachable only from the BPF syscall, which holds classic rcu_read_lock() before dispatching, so it is left untouched.
--- kernel/bpf/lpm_trie.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/bpf/lpm_trie.c +4 -4
@@ -246,7 +246,7 @@ static void *trie_lookup_elem(struct bpf/* Start walking the trie from the root node ... */ -for (node =rcu_dereference_check (trie->root,rcu_read_lock_bh_held ()); +for (node =rcu_dereference_check (trie->root,bpf_rcu_lock_held ()); node;) {unsigned int next_bit;size_t matchlen;
@@ -280,7 +280,7 @@ static void *trie_lookup_elem(struct bpf*/ next_bit =extract_bit (key->data, node->prefixlen); node =rcu_dereference_check (node->child[next_bit], -rcu_read_lock_bh_held ()); +bpf_rcu_lock_held ()); }if (!found)
@@ -359,7 +359,7 @@ static long trie_update_elem(struct bpf_*/ slot = &trie->root; -while ((node =rcu_dereference (*slot))) { +while ((node =rcu_dereference_protected (*slot,1 ))) { matchlen =longest_prefix_match (trie, node, key); if (node->prefixlen != matchlen ||
@@ -482,7 +482,7 @@ static long trie_delete_elem(struct bpf_ trim = &trie->root; trim2 = trim; parent =NULL ; -while ((node =rcu_dereference (*trim))) { +while ((node =rcu_dereference_protected (*trim,1 ))) { matchlen =longest_prefix_match (trie, node, key); if (node->prefixlen != matchlen ||
Greg Kroah-Hartman
maintainerPATCH 1570/1611 xfs: add a xfs_groups_to_rfsbs helper
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 0ec73eb3f12350799c4b3fb764225f6e38b42d1e ]
Plus a rtgroup wrapper and use that to avoid overflows when converting zone/rtg counts to block counts.
Stable-dep-of: 44cccefe6574 ("xfs: only log freed extents for the current RTG in zoned growfs")
--- fs/xfs/libxfs/xfs_group.h | 9 +++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 8 ++++++++ fs/xfs/xfs_zone_gc.c | 3 +-- fs/xfs/xfs_zone_space_resv.c | 8 +++----- 4 files changed, 21 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_group.h +9 -0
@@ -98,6 +98,15 @@ xfs_group_max_blocks(return xg->xg_mount->m_groups[xg->xg_type].blocks; } +static inline xfs_rfsblock_t +xfs_groups_to_rfsbs ( +struct xfs_mount *mp, +uint32_t nr_groups, +enum xfs_group_type type) +{ +return (xfs_rfsblock_t )mp->m_groups[type].blocks * nr_groups; +} +static inline xfs_fsblock_t xfs_group_start_fsb (struct xfs_group *xg)
fs/xfs/libxfs/xfs_rtgroup.h +8 -0
@@ -371,4 +371,12 @@ static inline int xfs_initialize_rtgroup# define xfs_rtgroup_get_geometry (rtg, rgeo) (-EOPNOTSUPP)#endif /* CONFIG_XFS_RT */ +static inline xfs_rfsblock_t +xfs_rtgs_to_rfsbs ( +struct xfs_mount *mp, +uint32_t nr_groups) +{ +return xfs_groups_to_rfsbs (mp, nr_groups,XG_TYPE_RTG ); +} +#endif /* __LIBXFS_RTGROUP_H */
fs/xfs/xfs_zone_gc.c +1 -2
@@ -181,8 +181,7 @@ xfs_zoned_need_gc( available =xfs_estimate_freecounter (mp,XC_FREE_RTAVAILABLE );if (available < - mp->m_groups[XG_TYPE_RTG ].blocks * - (mp->m_max_open_zones -XFS_OPEN_GC_ZONES )) +xfs_rtgs_to_rfsbs (mp, mp->m_max_open_zones -XFS_OPEN_GC_ZONES ))return true; free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS );
fs/xfs/xfs_zone_space_resv.c +3 -5
@@ -54,12 +54,10 @@ xfs_zoned_default_resblks( {switch (ctr) {case XC_FREE_RTEXTENTS : -return (uint64_t )XFS_RESERVED_ZONES * - mp->m_groups[XG_TYPE_RTG ].blocks + - mp->m_sb.sb_rtreserved; +return xfs_rtgs_to_rfsbs (mp,XFS_RESERVED_ZONES ) + + mp->m_sb.sb_rtreserved;case XC_FREE_RTAVAILABLE : -return (uint64_t )XFS_GC_ZONES * - mp->m_groups[XG_TYPE_RTG ].blocks; +return xfs_rtgs_to_rfsbs (mp,XFS_GC_ZONES );default :ASSERT (0 );return 0 ;
Greg Kroah-Hartman
maintainerPATCH 1571/1611 xfs: only log freed extents for the current RTG in zoned growfs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 44cccefe65749821d9a13523c8b763bf1262ef73 ]
Otherwise a power fail or crash during growfs could lead to an elevated sb_rblocks counter.
Note that the step function is much simpler compared to the classic RT allocator as zoned RT sections must be aligned to real time group boundaries.
--- fs/xfs/xfs_rtalloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_rtalloc.c +4 -4
@@ -887,8 +887,7 @@ xfs_growfs_rt_sb_fields(static int xfs_growfs_rt_zoned ( -struct xfs_rtgroup *rtg, -xfs_rfsblock_t nrblocks) +struct xfs_rtgroup *rtg) {struct xfs_mount *mp =rtg_mount (rtg);struct xfs_mount *nmp;
@@ -900,7 +899,8 @@ xfs_growfs_rt_zoned(* Calculate new sb and mount fields for this round. Also ensure the * rtg_extents value is uptodate as the rtbitmap code relies on it. */ - nmp =xfs_growfs_rt_alloc_fake_mount (mp, nrblocks, + nmp =xfs_growfs_rt_alloc_fake_mount (mp, +xfs_rtgs_to_rfsbs (mp,rtg_rgno (rtg) +1 ), mp->m_sb.sb_rextsize);if (!nmp)return -ENOMEM ;
@@ -1189,7 +1189,7 @@ xfs_growfs_rtg( }if (xfs_has_zoned (mp)) { - error =xfs_growfs_rt_zoned (rtg, nrblocks); + error =xfs_growfs_rt_zoned (rtg); goto out_rele; }
Greg Kroah-Hartman
maintainerPATCH 1572/1611 xfs: use bio_reuse in the zone GC code
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 0506d32f7c52e41f6e8db7c337e0ce6374c6ffbb ]
Replace our somewhat fragile code to reuse the bio, which caused a regression in the past with the block layer bio_reuse helper.
[ sashal: open-coded the bio_reuse logic at the call site as 6.18 lacks
commit 7ca44303f9f6 ("block: add a bio_reuse helper") ]
Stable-dep-of: ae3692c7f440 ("xfs: add newly added RTGs to the free pool in growfs")
--- fs/xfs/xfs_zone_gc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/xfs/xfs_zone_gc.c +5 -5
@@ -812,9 +812,8 @@ xfs_zone_gc_write_chunk( {struct xfs_zone_gc_data *data = chunk->data;struct xfs_mount *mp = chunk->ip->i_mount; -phys_addr_t bvec_paddr = -bvec_phys (bio_first_bvec_all (&chunk->bio));struct xfs_gc_bio *split_chunk; +unsigned short vcnt, i;if (chunk->bio.bi_status)xfs_force_shutdown (mp,SHUTDOWN_META_IO_ERROR );
@@ -826,10 +825,11 @@ xfs_zone_gc_write_chunk(WRITE_ONCE (chunk->state,XFS_GC_BIO_NEW );list_move_tail (&chunk->entry, &data->writing); + vcnt = chunk->bio.bi_vcnt;bio_reset (&chunk->bio, mp->m_rtdev_targp->bt_bdev,REQ_OP_WRITE ); -bio_add_folio_nofail (&chunk->bio, chunk->scratch->folio, chunk->len, -offset_in_folio (chunk->scratch->folio, bvec_paddr)); - +for (i =0 ; i < vcnt; i++) + chunk->bio.bi_iter.bi_size += chunk->bio.bi_io_vec[i].bv_len; + chunk->bio.bi_vcnt = vcnt;while ((split_chunk =xfs_zone_gc_split_write (data, chunk)))xfs_zone_gc_submit_write (data, split_chunk);xfs_zone_gc_submit_write (data, chunk);
Greg Kroah-Hartman
maintainerPATCH 1573/1611 usb: dwc3: Support USB3340x ULPI PHY high-speed negotiation.
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ingo Rohloff <[email protected]>
[ Upstream commit a28de63356575612954d4e5d5f48a2488f50e16d ]
The Microchip USB3340x ULPI PHY requires a delay when switching to the high-speed transmitter. See:
http://ww1.microchip.com/downloads/en/DeviceDoc/80000645A.pdf
Module 2 "Device Enumeration Failure with Link IP Systems"
For details on the behavior and fix, refer to the AMD (formerly Xilinx) forum post: "USB stuck in full speed mode with USB3340 ULPI PHY, ZynqMP."
This patch uses the USB PHY Vendor-ID and Product-ID to detect the USB3340 PHY and then applies the necessary fix if this PHY is found.
Stable-dep-of: e0f844d9d742 ("usb: dwc3: fix dwc3_readl() and dwc3_writel() calls in dwc3_ulpi_setup()")
--- drivers/usb/dwc3/core.c | 20 ++++++++++++++++++++ drivers/usb/dwc3/core.h | 4 ++++ drivers/usb/dwc3/ulpi.c | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+)
drivers/usb/dwc3/core.c +20 -0
@@ -781,6 +781,24 @@ static int dwc3_hs_phy_setup(struct dwc3return 0 ; } +static void dwc3_ulpi_setup (struct dwc3 *dwc) +{ +int index; +u32 reg; + +/* Don't do anything if there is no ULPI PHY */ +if (!dwc->ulpi) +return ; + +if (dwc->enable_usb2_transceiver_delay) { +for (index =0 ; index < dwc->num_usb2_ports; index++) { + reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (index)); + reg |=DWC3_GUSB2PHYCFG_XCVRDLY ; +dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (index), reg); + } + } +} +/** * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core * @dwc: Pointer to our controller context structure
@@ -1355,6 +1373,8 @@ static int dwc3_core_init(struct dwc3 *d dwc->ulpi_ready = true; } +dwc3_ulpi_setup (dwc); +if (!dwc->phys_ready) { ret =dwc3_core_get_phy (dwc);if (ret)
drivers/usb/dwc3/core.h +4 -0
@@ -302,6 +302,7 @@#define DWC3_GUSB2PHYCFG_SUSPHY BIT(6)#define DWC3_GUSB2PHYCFG_ULPI_UTMI BIT(4)#define DWC3_GUSB2PHYCFG_ENBLSLPM BIT(8) +#define DWC3_GUSB2PHYCFG_XCVRDLY BIT(9)#define DWC3_GUSB2PHYCFG_PHYIF (n) (n << 3)#define DWC3_GUSB2PHYCFG_PHYIF_MASK DWC3_GUSB2PHYCFG_PHYIF(1)#define DWC3_GUSB2PHYCFG_USBTRDTIM (n) (n << 10)
@@ -1161,6 +1162,8 @@ struct dwc3_glue_ops {* 3 - Reserved * @dis_metastability_quirk: set to disable metastability quirk. * @dis_split_quirk: set to disable split boundary. +* @enable_usb2_transceiver_delay: Set to insert a delay before the +* assertion of the TxValid signal during a HS Chirp. * @sys_wakeup: set if the device may do system wakeup. * @wakeup_configured: set if the device is configured for remote wakeup. * @suspended: set to track suspend event due to U3/L2.
@@ -1403,6 +1406,7 @@ struct dwc3 { unsigned dis_metastability_quirk:1; unsigned dis_split_quirk:1; + unsigned enable_usb2_transceiver_delay:1; unsigned async_callbacks:1; unsigned sys_wakeup:1; unsigned wakeup_configured:1;
drivers/usb/dwc3/ulpi.c +25 -0
@@ -10,10 +10,13 @@#include <linux/delay.h> #include <linux/time64.h> #include <linux/ulpi/regs.h> +#include <linux/ulpi/driver.h> #include "core.h" #include "io.h" +#define USB_VENDOR_MICROCHIP 0x0424 +#define DWC3_ULPI_ADDR (a) \ ((a >= ULPI_EXT_VENDOR_SPECIFIC) ? \ DWC3_GUSB2PHYACC_ADDR(ULPI_ACCESS_EXTENDED) | \
@@ -83,6 +86,26 @@ static const struct ulpi_ops dwc3_ulpi_o .write = dwc3_ulpi_write, }; +static void dwc3_ulpi_detect_config (struct dwc3 *dwc) +{ +struct ulpi *ulpi = dwc->ulpi; + +switch (ulpi->id.vendor) { +case USB_VENDOR_MICROCHIP : +switch (ulpi->id.product) { +case 0x0009 : +/* Microchip USB3340 ULPI PHY */ + dwc->enable_usb2_transceiver_delay = true; +break ; +default : +break ; + } +break ; +default : +break ; + } +} +int dwc3_ulpi_init (struct dwc3 *dwc) {/* Register the interface */
@@ -92,6 +115,8 @@ int dwc3_ulpi_init(struct dwc3 *dwc)return PTR_ERR (dwc->ulpi); } +dwc3_ulpi_detect_config (dwc); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1574/1611 usb: dwc3: fix dwc3_readl() and dwc3_writel() calls in dwc3_ulpi_setup()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ben Dooks <[email protected]>
[ Upstream commit e0f844d9d74200d311c6438a0f04270834ba5365 ]
The dwc3_ulpi_setup() calls the register read and write calls with dwc3->regs when both these calls take the dwc3 structure directly.
Chnage these two calls to fix the following sparse warning, and possibly a nasty bug in the dwc3_ulpi_setup() code:
drivers/usb/dwc3/core.c:796:45: warning: incorrect type in argument 1 (different address spaces)drivers/usb/dwc3/core.c:796:45: expected struct dwc3 *dwcdrivers/usb/dwc3/core.c:796:45: got void [noderef] __iomem *regsdrivers/usb/dwc3/core.c:798:40: warning: incorrect type in argument 1 (different address spaces)drivers/usb/dwc3/core.c:798:40: expected struct dwc3 *dwcdrivers/usb/dwc3/core.c:798:40: got void [noderef] __iomem *regs
--- drivers/usb/dwc3/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/core.c +2 -2
@@ -792,9 +792,9 @@ static void dwc3_ulpi_setup(struct dwc3if (dwc->enable_usb2_transceiver_delay) {for (index =0 ; index < dwc->num_usb2_ports; index++) { - reg =dwc3_readl (dwc->regs,DWC3_GUSB2PHYCFG (index)); + reg =dwc3_readl (dwc,DWC3_GUSB2PHYCFG (index)); reg |=DWC3_GUSB2PHYCFG_XCVRDLY ; -dwc3_writel (dwc->regs,DWC3_GUSB2PHYCFG (index), reg); +dwc3_writel (dwc,DWC3_GUSB2PHYCFG (index), reg); } } }
Greg Kroah-Hartman
maintainerPATCH 1575/1611 usb: atm: ueagle-atm: use dev_dbg() for device found message
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mauricio Faria de Oliveira <[email protected]>
[ Upstream commit 05c5075c3115010f97434c53d353d9a0d4b0e64e ]
Convert dev_info() to dev_dbg().
Per 'Documentation/process/coding-style.rst':
13) Printing kernel messages
... When drivers are working properly they are quiet, so prefer to use dev_dbg/pr_debug unless something is wrong.
While in there, correct the verb form and add 'with' for clarity.
Stable-dep-of: e2674dfbed8a ("usb: atm: ueagle-atm: wait for pre-firmware load in .disconnect()")
--- drivers/usb/atm/ueagle-atm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/atm/ueagle-atm.c +1 -1
@@ -2589,7 +2589,7 @@ static int uea_probe(struct usb_interfacint ret;uea_enters (usb); - uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n", + uea_dbg(usb, "ADSL device found with vid (%#X) pid (%#X) Rev (%#X): %s\n", le16_to_cpu(usb->descriptor.idVendor), le16_to_cpu(usb->descriptor.idProduct), le16_to_cpu(usb->descriptor.bcdDevice),
Greg Kroah-Hartman
maintainerPATCH 1576/1611 usb: atm: ueagle-atm: remove function entry/exit debug messages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mauricio Faria de Oliveira <[email protected]>
[ Upstream commit 1414b2242c2e9d670c4d8b83480f13db57627ba9 ]
Remove the driver-internal function entry/exit debug messages in favor of existing kernel-level function tracing mechanisms.
Stable-dep-of: e2674dfbed8a ("usb: atm: ueagle-atm: wait for pre-firmware load in .disconnect()")
--- drivers/usb/atm/ueagle-atm.c | 56 ++++--------------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-)
drivers/usb/atm/ueagle-atm.c +6 -50
@@ -50,12 +50,6 @@ "[ueagle-atm vdbg] " format, ##args); \ } while (0) -#define uea_enters (usb_dev) \ - uea_vdbg(usb_dev, "entering %s\n" , __func__) - -#define uea_leaves (usb_dev) \ - uea_vdbg(usb_dev, "leaving %s\n" , __func__) - #define uea_err(usb_dev, format, args...) \ dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
@@ -605,7 +599,6 @@ static void uea_upload_pre_firmware(consu32 crc =0 ;int ret, size; -uea_enters (usb);if (!fw_entry) {uea_err (usb,"firmware is not available\n" ); goto err;
@@ -669,7 +662,6 @@ err_fw_corrupted:uea_err (usb,"firmware is corrupted\n" ); err:release_firmware (fw_entry); -uea_leaves (usb); }/*
@@ -680,7 +672,6 @@ static int uea_load_firmware(struct usb_int ret;char *fw_name =EAGLE_FIRMWARE ; -uea_enters (usb);uea_info (usb,"pre-firmware device, uploading firmware\n" );switch (ver) {
@@ -709,7 +700,6 @@ static int uea_load_firmware(struct usb_else uea_info (usb,"loading firmware %s\n" , fw_name); -uea_leaves (usb);return ret; }
@@ -1136,7 +1126,6 @@ static int uea_cmv_e1(struct uea_softc *struct cmv_e1 cmv;int ret; -uea_enters (INS_TO_USBDEV (sc)); uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, " "offset : 0x%04x, data : 0x%08x\n", E1_FUNCTION_TYPE(function),
@@ -1163,9 +1152,8 @@ static int uea_cmv_e1(struct uea_softc * sizeof(cmv), &cmv);if (ret <0 )return ret; - ret =wait_cmv_ack (sc); -uea_leaves (INS_TO_USBDEV (sc)); -return ret; + +return wait_cmv_ack (sc); } static int uea_cmv_e4(struct uea_softc *sc,
@@ -1174,7 +1162,6 @@ static int uea_cmv_e4(struct uea_softc *struct cmv_e4 cmv;int ret; -uea_enters (INS_TO_USBDEV (sc));memset (&cmv,0 ,sizeof (cmv)); uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
@@ -1198,9 +1185,8 @@ static int uea_cmv_e4(struct uea_softc * sizeof(cmv), &cmv);if (ret <0 )return ret; - ret =wait_cmv_ack (sc); -uea_leaves (INS_TO_USBDEV (sc)); -return ret; + +return wait_cmv_ack (sc); } static inline int uea_read_cmv_e1(struct uea_softc *sc,
@@ -1294,7 +1280,6 @@ static int uea_stat_e1(struct uea_softcu32 data;int ret; -uea_enters (INS_TO_USBDEV (sc)); data = sc->stats.phy.state; ret =uea_read_cmv_e1 (sc,E1_SA_STAT ,0 , &sc->stats.phy.state);
@@ -1437,7 +1422,6 @@ static int uea_stat_e4(struct uea_softcu32 tmp_arr[2 ];int ret; -uea_enters (INS_TO_USBDEV (sc)); data = sc->stats.phy.state;/* XXX only need to be done before operationnal... */
@@ -1804,7 +1788,6 @@ static int uea_start_reset(struct uea_sou16 zero =0 ;/* ;-) */ int ret; -uea_enters (INS_TO_USBDEV (sc));uea_info (INS_TO_USBDEV (sc),"(re)booting started\n" );/* mask interrupt */
@@ -1872,7 +1855,6 @@ static int uea_start_reset(struct uea_soreturn ret; sc->reset =0 ; -uea_leaves (INS_TO_USBDEV (sc));return ret; }
@@ -1888,7 +1870,6 @@ static int uea_kthread(void *data)int ret = -EAGAIN ;set_freezable (); -uea_enters (INS_TO_USBDEV (sc));while (!kthread_should_stop ()) {if (ret <0 || sc->reset) ret =uea_start_reset (sc);
@@ -1897,7 +1878,7 @@ static int uea_kthread(void *data)if (ret != -EAGAIN )uea_wait (sc,0 ,msecs_to_jiffies (1000 )); } -uea_leaves (INS_TO_USBDEV (sc)); +return ret; }
@@ -1910,8 +1891,6 @@ static int load_XILINX_firmware(struct uu8 value;char *fw_name =FPGA930_FIRMWARE ; -uea_enters (INS_TO_USBDEV (sc)); - ret =request_firmware (&fw_entry, fw_name, &sc->usb_dev->dev);if (ret) { uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
@@ -1955,7 +1934,6 @@ static int load_XILINX_firmware(struct u err1:release_firmware (fw_entry); err0: -uea_leaves (INS_TO_USBDEV (sc));return ret; }
@@ -1965,7 +1943,6 @@ static void uea_dispatch_cmv_e1(struct ustruct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;struct cmv_e1 *cmv = &intr->u.e1.s2.cmv; -uea_enters (INS_TO_USBDEV (sc));if (le16_to_cpu (cmv->wPreamble) !=E1_PREAMBLE ) goto bad1;
@@ -1989,7 +1966,6 @@ static void uea_dispatch_cmv_e1(struct uif (cmv->bFunction ==E1_MAKEFUNCTION (E1_ADSLDIRECTIVE ,E1_MODEMREADY )) {wake_up_cmv_ack (sc); -uea_leaves (INS_TO_USBDEV (sc));return ; }
@@ -2003,7 +1979,6 @@ static void uea_dispatch_cmv_e1(struct u sc->data = sc->data <<16 | sc->data >>16 ;wake_up_cmv_ack (sc); -uea_leaves (INS_TO_USBDEV (sc));return ; bad2:
@@ -2011,14 +1986,12 @@ bad2:"Function : %d, Subfunction : %d\n" ,E1_FUNCTION_TYPE (cmv->bFunction), E1_FUNCTION_SUBTYPE(cmv->bFunction)); -uea_leaves (INS_TO_USBDEV (sc));return ; bad1:uea_err (INS_TO_USBDEV (sc),"invalid cmv received, " "wPreamble %d, bDirection %d\n" ,le16_to_cpu (cmv->wPreamble), cmv->bDirection); -uea_leaves (INS_TO_USBDEV (sc)); }/* The modem send us an ack. First with check if it right */
@@ -2027,7 +2000,6 @@ static void uea_dispatch_cmv_e4(struct ustruct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;struct cmv_e4 *cmv = &intr->u.e4.s2.cmv; -uea_enters (INS_TO_USBDEV (sc)); uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n", be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction), be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
@@ -2039,7 +2011,6 @@ static void uea_dispatch_cmv_e4(struct uif (be16_to_cpu (cmv->wFunction) ==E4_MAKEFUNCTION (E4_ADSLDIRECTIVE ,E4_MODEMREADY ,1 )) {wake_up_cmv_ack (sc); -uea_leaves (INS_TO_USBDEV (sc));return ; }
@@ -2052,7 +2023,6 @@ static void uea_dispatch_cmv_e4(struct u sc->data =be32_to_cpu (cmv->dwData[0 ]); sc->data1 =be32_to_cpu (cmv->dwData[1 ]);wake_up_cmv_ack (sc); -uea_leaves (INS_TO_USBDEV (sc));return ; bad2:
@@ -2060,7 +2030,6 @@ bad2:"Function : %d, Subfunction : %d\n" ,E4_FUNCTION_TYPE (cmv->wFunction), E4_FUNCTION_SUBTYPE(cmv->wFunction)); -uea_leaves (INS_TO_USBDEV (sc));return ; }
@@ -2088,8 +2057,6 @@ static void uea_intr(struct urb *urb)struct intr_pkt *intr = urb->transfer_buffer;int status = urb->status; -uea_enters (INS_TO_USBDEV (sc)); -if (unlikely (status <0 )) {uea_err (INS_TO_USBDEV (sc),"uea_intr() failed with %d\n" , status);
@@ -2129,8 +2096,6 @@ static int uea_boot(struct uea_softc *scint ret = -ENOMEM ;int size; -uea_enters (INS_TO_USBDEV (sc)); -if (UEA_CHIP_VERSION (sc) ==EAGLE_IV ) { size =E4_INTR_PKT_SIZE ; sc->dispatch_cmv = uea_dispatch_cmv_e4;
@@ -2187,7 +2152,6 @@ static int uea_boot(struct uea_softc *sc goto err2; } -uea_leaves (INS_TO_USBDEV (sc));return 0 ; err2:
@@ -2197,7 +2161,6 @@ err1: sc->urb_int =NULL ;kfree (intr); err0: -uea_leaves (INS_TO_USBDEV (sc));return ret; }
@@ -2207,7 +2170,7 @@ err0:static void uea_stop (struct uea_softc *sc) {int ret; -uea_enters (INS_TO_USBDEV (sc)); + ret =kthread_stop (sc->kthread);uea_dbg (INS_TO_USBDEV (sc),"kthread finish with status %d\n" , ret);
@@ -2221,7 +2184,6 @@ static void uea_stop(struct uea_softc *sflush_work (&sc->task);release_firmware (sc->dsp_firm); -uea_leaves (INS_TO_USBDEV (sc)); }/* syfs interface */
@@ -2494,8 +2456,6 @@ static int uea_bind(struct usbatm_data *int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;unsigned int alt; -uea_enters (usb); -/* interface 0 is for firmware/monitoring */ if (ifnum !=UEA_INTR_IFACE_NO )return -ENODEV ;
@@ -2588,7 +2548,6 @@ static int uea_probe(struct usb_interfacstruct usb_device *usb =interface_to_usbdev (intf);int ret; -uea_enters (usb); uea_dbg(usb, "ADSL device found with vid (%#X) pid (%#X) Rev (%#X): %s\n", le16_to_cpu(usb->descriptor.idVendor), le16_to_cpu(usb->descriptor.idProduct),
@@ -2619,7 +2578,6 @@ static void uea_disconnect(struct usb_in {struct usb_device *usb =interface_to_usbdev (intf);int ifnum = intf->altsetting->desc.bInterfaceNumber; -uea_enters (usb);/* ADI930 has 2 interfaces and eagle 3 interfaces. * Pre-firmware device has one interface
@@ -2630,8 +2588,6 @@ static void uea_disconnect(struct usb_inmutex_unlock (&uea_mutex);uea_info (usb,"ADSL device removed\n" ); } - -uea_leaves (usb); }/*
Greg Kroah-Hartman
maintainerPATCH 1577/1611 usb: atm: ueagle-atm: wait for pre-firmware load in .disconnect()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mauricio Faria de Oliveira <[email protected]>
[ Upstream commit e2674dfbed8a30d57e2bc872c4bfa6c3eec918bf ]
ueagle-atm uses the asynchronous request_firmware_nowait() in .probe(), but does not wait for its completion, not even in .disconnect(); so, if the device is unplugged meanwhile, its teardown runs concurrently with that.
Even though this inconsistency is worth addressing on its own, it has also triggered several bug reports in syzbot over the years (some auto-closed) where the firmware sysfs fallback mechanism (CONFIG_FW_LOADER_USER_HELPER) creates a firmware subdirectory in the device directory during its removal, which might hit unexpected conditions in kernfs, apparently, depending at which point the add and remove operations raced. (See links.)
The pattern is:
usb ?-?: Direct firmware load for ueagle-atm/eagle?.fw failed with error -2 usb ?-?: Falling back to sysfs fallback for: ueagle-atm/eagle?.fw <ERROR>
Call trace: ... kernfs_create_dir_ns sysfs_create_dir_ns create_dir kobject_add_internal kobject_add_varg kobject_add class_dir_create_and_add get_device_parent device_add fw_load_sysfs_fallback fw_load_from_user_helper firmware_fallback_sysfs _request_firmware request_firmware_work_func ...
(Some variations are observed, after fw_load_sysfs_fallback(), e.g., [1].)
While the kernfs side is being looked at, the ueagle-atm side can be fixed by waiting for the pre-firmware load in the .disconnect() handler.
This change has a similar approach to previous work by Andrey Tsygunka [2] (wait_for_completion() in .disconnect()), but it is relatively different in design/implementation; using the Originally-by tag for credit assignment.
This has been tested with:
- synthetic reproducer to check the error path;
- USB gadget (virtual device) to check the firmware upload path;
- QEMU device emulator to check the device ID re-enumeration path; (The latter two were written by Claude; no other code/text in this commit.)
Links (year first reported):
2025 https://syzbot.org/bug?extid=ce1e5a1b4e086b43e56d
2025 https://syzbot.org/bug?extid=9af8471255ac36e34fd4
2024 https://syzbot.org/bug?extid=306212936b13e520679d
2023 https://syzkaller.appspot.com/bug?extid=457452d30bcdda75ead2
2022 https://syzbot.org/bug?extid=782984d6f1701b526edb
2021 https://syzbot.org/bug?id=f3f221579f4ef7e9691281f3c6f56c05f83e8490
2021 https://syzbot.org/bug?id=84d86f0d71394829df6fc53daf6642c045983881
2021 https://syzbot.org/bug?id=3302dc1c0e2b9c94f2e8edb404eabc9267bc6f90
[1] https://syzkaller.appspot.com/bug?extid=457452d30bcdda75ead2
[2] https://lore.kernel.org/lkml/[email protected]/
--- drivers/usb/atm/ueagle-atm.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)
drivers/usb/atm/ueagle-atm.c +31 -5
@@ -593,7 +593,9 @@ static int uea_send_modem_cmd(struct usbstatic void uea_upload_pre_firmware (const struct firmware *fw_entry,void *context) { -struct usb_device *usb = context; +struct usb_interface *intf = context; +struct usb_device *usb =interface_to_usbdev (intf); +struct completion *fw_done =usb_get_intfdata (intf);const u8 *pfw;u8 value;u32 crc =0 ;
@@ -662,15 +664,17 @@ err_fw_corrupted:uea_err (usb,"firmware is corrupted\n" ); err:release_firmware (fw_entry); +complete (fw_done); }/* * uea_load_firmware - Load usb firmware for pre-firmware devices. */ -static int uea_load_firmware (struct usb_device *usb,unsigned int ver) +static int uea_load_firmware (struct usb_interface *intf,unsigned int ver) {int ret;char *fw_name =EAGLE_FIRMWARE ; +struct usb_device *usb =interface_to_usbdev (intf);uea_info (usb,"pre-firmware device, uploading firmware\n" );
@@ -693,7 +697,7 @@ static int uea_load_firmware(struct usb_ } ret =request_firmware_nowait (THIS_MODULE ,1 , fw_name, &usb->dev, -GFP_KERNEL , usb, +GFP_KERNEL , intf, uea_upload_pre_firmware);if (ret)uea_err (usb,"firmware %s is not available\n" , fw_name);
@@ -2556,8 +2560,23 @@ static int uea_probe(struct usb_interfacusb_reset_device (usb); -if (UEA_IS_PREFIRM (id)) -return uea_load_firmware (usb,UEA_CHIP_VERSION (id)); +if (UEA_IS_PREFIRM (id)) { +struct completion *fw_done; + +/* Wait for the firmware load to be done, in .disconnect() */ + fw_done =kzalloc_obj (*fw_done); +if (!fw_done) +return -ENOMEM ; + +init_completion (fw_done); +usb_set_intfdata (intf, fw_done); + + ret =uea_load_firmware (intf,UEA_CHIP_VERSION (id)); +if (ret) +kfree (fw_done); + +return ret; + } ret =usbatm_usb_probe (intf, id, &uea_usbatm_driver);if (ret ==0 ) {
@@ -2587,6 +2606,13 @@ static void uea_disconnect(struct usb_inusbatm_usb_disconnect (intf);mutex_unlock (&uea_mutex);uea_info (usb,"ADSL device removed\n" ); + }else if (usb->config->desc.bNumInterfaces ==1 ) { +struct completion *fw_done =usb_get_intfdata (intf); + +uea_dbg (usb,"pre-firmware device, waiting firmware upload\n" ); +wait_for_completion (fw_done); +uea_dbg (usb,"pre-firmware device, finished waiting\n" ); +kfree (fw_done); } }
Greg Kroah-Hartman
maintainerPATCH 1578/1611 new helper: simple_remove_by_name()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 4051a9115ad24bb9a691774730ca9c1dd56de665 ]
simple_recursive_removal(), but instead of victim dentry it takes parent + name.
Used to be open-coded in fs/fuse/control.c, but there's no need to expose the guts of that thing there and there are other potential users, so let's lift it into libfs...
Stable-dep-of: 3137b243c939 ("usb: gadget: f_fs: initialize reset_work at allocation time")
--- fs/fuse/control.c | 7 +------ fs/libfs.c | 13 +++++++++++++ include/linux/fs.h | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-)
fs/fuse/control.c +1 -6
@@ -290,18 +290,13 @@ static void remove_one(struct dentry *de*/ void fuse_ctl_remove_conn (struct fuse_conn *fc) { -struct dentry *dentry;char name[32 ];if (!fuse_control_sb || fc->no_control)return ;sprintf (name,"%u" , fc->dev); - dentry =lookup_noperm_positive_unlocked (&QSTR (name), fuse_control_sb->s_root); -if (!IS_ERR (dentry)) { -simple_recursive_removal (dentry, remove_one); -dput (dentry);// paired with lookup_noperm_positive_unlocked() - } +simple_remove_by_name (fuse_control_sb->s_root, name, remove_one); }static int fuse_ctl_fill_super (struct super_block *sb,struct fs_context *fsc)
fs/libfs.c +13 -0
@@ -647,6 +647,19 @@ void simple_recursive_removal(struct den }EXPORT_SYMBOL (simple_recursive_removal); +void simple_remove_by_name (struct dentry *parent,const char *name, +void (*callback)(struct dentry *)) +{ +struct dentry *dentry; + + dentry =lookup_noperm_positive_unlocked (&QSTR (name), parent); +if (!IS_ERR (dentry)) { +simple_recursive_removal (dentry, callback); +dput (dentry);// paired with lookup_noperm_positive_unlocked() + } +} +EXPORT_SYMBOL (simple_remove_by_name); +/* caller holds parent directory with I_MUTEX_PARENT */ void locked_recursive_removal (struct dentry *dentry,void (*callback)(struct dentry *))
include/linux/fs.h +2 -0
@@ -3655,6 +3655,8 @@ extern int simple_rename(struct mnt_idma unsigned int);extern void simple_recursive_removal (struct dentry *,void (*callback)(struct dentry *)); +extern void simple_remove_by_name (struct dentry *,const char *, +void (*callback)(struct dentry *));extern void locked_recursive_removal (struct dentry *,void (*callback)(struct dentry *));extern int noop_fsync (struct file *,loff_t ,loff_t ,int );
Greg Kroah-Hartman
maintainerPATCH 1579/1611 functionfs: dont abuse ffs_data_closed() on fs shutdown
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit fcb8985143540cbcb8e91c0ea8b7fb5d37c88177 ]
ffs_data_closed() has a seriously confusing logics in it: in addition to the normal "decrement a counter and do some work if it hits zero" there's "... and if it has somehow become negative, do that" bit.
It's not a race, despite smelling rather fishy. What really happens is that in addition to "call that on close of files there, to match the increments of counter on opens" there's one call in ->kill_sb(). Counter starts at 0 and never goes negative over the lifetime of filesystem (or we have much worse problems everywhere - ->release() call of some file somehow unpaired with successful ->open() of the same). At the filesystem shutdown it will be 0 or, again, we have much worse problems - filesystem instance destroyed with files on it still open. In other words, at that call and at that call alone the decrement would go from 0 to -1, hitting that chunk (and not hitting the "if it hits 0" part).
So that check is a weirdly spelled "called from ffs_kill_sb()". Just expand the call in the latter and kill the misplaced chunk in ffs_data_closed().
Stable-dep-of: 3137b243c939 ("usb: gadget: f_fs: initialize reset_work at allocation time")
--- drivers/usb/gadget/function/f_fs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/usb/gadget/function/f_fs.c +8 -8
@@ -2086,12 +2086,18 @@ static int ffs_fs_init_fs_context(structreturn 0 ; } +static void ffs_data_reset (struct ffs_data *ffs); +static void ffs_fs_kill_sb (struct super_block *sb) {kill_litter_super (sb); -if (sb->s_fs_info) -ffs_data_closed (sb->s_fs_info); +if (sb->s_fs_info) { +struct ffs_data *ffs = sb->s_fs_info; + ffs->state =FFS_CLOSING ; +ffs_data_reset (ffs); +ffs_data_put (ffs); + } }static struct file_system_type ffs_fs_type = {
@@ -2129,7 +2135,6 @@ static void functionfs_cleanup(void)/* ffs_data and ffs_function construction and destruction code **************/ static void ffs_data_clear (struct ffs_data *ffs); -static void ffs_data_reset (struct ffs_data *ffs);static void ffs_data_get (struct ffs_data *ffs) {
@@ -2186,11 +2191,6 @@ static void ffs_data_closed(struct ffs_dffs_data_reset (ffs); } } -if (atomic_read (&ffs->opened) <0 ) { - ffs->state =FFS_CLOSING ; -ffs_data_reset (ffs); - } -ffs_data_put (ffs); }
Greg Kroah-Hartman
maintainerPATCH 1580/1611 functionfs: dont bother with ffs->ref in ffs_data_{opened,closed}()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit fe47466282a69499ae17a22f064e827badb77078 ]
A reference is held by the superblock (it's dropped in ffs_kill_sb()) and filesystem will not get to ->kill_sb() while there are any opened files, TYVM...
Stable-dep-of: 3137b243c939 ("usb: gadget: f_fs: initialize reset_work at allocation time")
--- drivers/usb/gadget/function/f_fs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/usb/gadget/function/f_fs.c +3 -5
@@ -2143,7 +2143,6 @@ static void ffs_data_get(struct ffs_datastatic void ffs_data_opened (struct ffs_data *ffs) { -refcount_inc (&ffs->ref);if (atomic_add_return (1 , &ffs->opened) ==1 && ffs->state ==FFS_DEACTIVATED ) { ffs->state =FFS_CLOSING ;
@@ -2168,11 +2167,11 @@ static void ffs_data_put(struct ffs_datastatic void ffs_data_closed (struct ffs_data *ffs) { -struct ffs_epfile *epfiles; -unsigned long flags; -if (atomic_dec_and_test (&ffs->opened)) {if (ffs->no_disconnect) { +struct ffs_epfile *epfiles; +unsigned long flags; + ffs->state =FFS_DEACTIVATED ;spin_lock_irqsave (&ffs->eps_lock, flags); epfiles = ffs->epfiles;
@@ -2191,7 +2190,6 @@ static void ffs_data_closed(struct ffs_dffs_data_reset (ffs); } } -ffs_data_put (ffs); }static struct ffs_data *ffs_data_new (const char *dev_name)
Greg Kroah-Hartman
maintainerPATCH 1581/1611 functionfs: switch to simple_remove_by_name()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit c7747fafaba0dcdad3d7da240e961927b4865f98 ]
No need to return dentry from ffs_sb_create_file() or keep it around afterwards.
To avoid subtle issues with getting to ffs from epfiles in ffs_epfiles_destroy(), pass the superblock as explicit argument. Callers have it anyway.
Stable-dep-of: 3137b243c939 ("usb: gadget: f_fs: initialize reset_work at allocation time")
--- drivers/usb/gadget/function/f_fs.c | 51 +++++++++++++++---------------------- 1 file changed, 22 insertions(+), 29 deletions(-)
drivers/usb/gadget/function/f_fs.c +22 -29
@@ -162,8 +162,6 @@ struct ffs_epfile {struct ffs_data *ffs;struct ffs_ep *ep;/* P: ffs->eps_lock */ -struct dentry *dentry; -/* * Buffer for holding data from partial reads which may happen since * we’re rounding user read requests to a multiple of a max packet size.
@@ -273,11 +271,11 @@ struct ffs_desc_helper { };static int __must_check ffs_epfiles_create (struct ffs_data *ffs); -static void ffs_epfiles_destroy (struct ffs_epfile *epfiles,unsigned count); +static void ffs_epfiles_destroy (struct super_block *sb, +struct ffs_epfile *epfiles,unsigned count); -static struct dentry * -ffs_sb_create_file (struct super_block *sb,const char *name,void *data, -const struct file_operations *fops); +static int ffs_sb_create_file (struct super_block *sb,const char *name, +void *data,const struct file_operations *fops);/* Devices management *******************************************************/
@@ -1881,9 +1879,8 @@ ffs_sb_make_inode(struct super_block *sb }/* Create "regular" file */ -static struct dentry *ffs_sb_create_file (struct super_block *sb, -const char *name,void *data, -const struct file_operations *fops) +static int ffs_sb_create_file (struct super_block *sb,const char *name, +void *data,const struct file_operations *fops) {struct ffs_data *ffs = sb->s_fs_info;struct dentry *dentry;
@@ -1891,16 +1888,16 @@ static struct dentry *ffs_sb_create_file dentry =d_alloc_name (sb->s_root, name);if (!dentry) -return NULL ; +return -ENOMEM ; inode =ffs_sb_make_inode (sb, data, fops,NULL , &ffs->file_perms);if (!inode) {dput (dentry); -return NULL ; +return -ENOMEM ; }d_add (dentry, inode); -return dentry; +return 0 ; }/* Super block */
@@ -1943,10 +1940,7 @@ static int ffs_sb_fill(struct super_blocreturn -ENOMEM ;/* EP0 file */ -if (!ffs_sb_create_file (sb,"ep0" , ffs, &ffs_ep0_operations)) -return -ENOMEM ; - -return 0 ; +return ffs_sb_create_file (sb,"ep0" , ffs, &ffs_ep0_operations); }enum {
@@ -2180,7 +2174,7 @@ static void ffs_data_closed(struct ffs_d flags);if (epfiles) -ffs_epfiles_destroy (epfiles, +ffs_epfiles_destroy (ffs->sb, epfiles, ffs->eps_count);if (ffs->setup_state ==FFS_SETUP_PENDING )
@@ -2239,7 +2233,7 @@ static void ffs_data_clear(struct ffs_da* copy of epfile will save us from use-after-free. */ if (epfiles) { -ffs_epfiles_destroy (epfiles, ffs->eps_count); +ffs_epfiles_destroy (ffs->sb, epfiles, ffs->eps_count); ffs->epfiles =NULL ; }
@@ -2336,6 +2330,7 @@ static int ffs_epfiles_create(struct ffs {struct ffs_epfile *epfile, *epfiles;unsigned i, count; +int err; count = ffs->eps_count; epfiles =kcalloc (count,sizeof (*epfiles),GFP_KERNEL );
@@ -2353,12 +2348,11 @@ static int ffs_epfiles_create(struct ffselse sprintf (epfile->name,"ep%u" , i); epfile->in = (ffs->eps_addrmap[i] &USB_ENDPOINT_DIR_MASK ) ?1 :0 ; - epfile->dentry =ffs_sb_create_file (ffs->sb, epfile->name, - epfile, - &ffs_epfile_operations); -if (!epfile->dentry) { -ffs_epfiles_destroy (epfiles, i -1 ); -return -ENOMEM ; + err =ffs_sb_create_file (ffs->sb, epfile->name, + epfile, &ffs_epfile_operations); +if (err) { +ffs_epfiles_destroy (ffs->sb, epfiles, i -1 ); +return err; } }
@@ -2366,16 +2360,15 @@ static int ffs_epfiles_create(struct ffsreturn 0 ; } -static void ffs_epfiles_destroy (struct ffs_epfile *epfiles,unsigned count) +static void ffs_epfiles_destroy (struct super_block *sb, +struct ffs_epfile *epfiles,unsigned count) {struct ffs_epfile *epfile = epfiles; +struct dentry *root = sb->s_root;for (; count; --count, ++epfile) {BUG_ON (mutex_is_locked (&epfile->mutex)); -if (epfile->dentry) { -simple_recursive_removal (epfile->dentry,NULL ); - epfile->dentry =NULL ; - } +simple_remove_by_name (root, epfile->name,NULL ); }kfree (epfiles);
Greg Kroah-Hartman
maintainerPATCH 1582/1611 functionfs: use spinlock for FFS_DEACTIVATED/FFS_CLOSING transitions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 2005aabe94eaab8608879d98afb901bc99bc3a31 ]
When all files are closed, functionfs needs ffs_data_reset() to be done before any further opens are allowed.
During that time we have ffs->state set to FFS_CLOSING; that makes ->open() fail with -EBUSY. Once ffs_data_reset() is done, it switches state (to FFS_READ_DESCRIPTORS) indicating that opening that thing is allowed again. There's a couple of additional twists:
* mounting with -o no_disconnect delays ffs_data_reset()
from doing that at the final ->release() to the first subsequent open(). That's indicated by ffs->state set to FFS_DEACTIVATED; if open() sees that, it immediately switches to FFS_CLOSING and proceeds with doing ffs_data_reset() before returning to userland.
* a couple of usb callbacks need to force the delayed
transition; unfortunately, they are done in locking environment that does not allow blocking and ffs_data_reset() can block. As the result, if these callbacks see FFS_DEACTIVATED, they change state to FFS_CLOSING and use schedule_work() to get ffs_data_reset() executed asynchronously.
Unfortunately, the locking is rather insufficient. A fix attempted in e5bf5ee26663 ("functionfs: fix the open/removal races") had closed a bunch of UAF, but it didn't do anything to the callbacks, lacked barriers in transition from FFS_CLOSING to FFS_READ_DESCRIPTORS _and_ it had been too heavy-handed in open()/open() serialization - I've used ffs->mutex for that, and it's being held over actual IO on ep0, complete with copy_from_user(), etc.
Even more unfortunately, the userland side is apparently racy enough to have the resulting timing changes (no failures, just a delayed return of open(2)) disrupt the things quite badly. Userland bugs or not, it's a clear regression that needs to be dealt with.
Solution is to use a spinlock for serializing these state checks and transitions - unlike ffs->mutex it can be taken in these callbacks and it doesn't disrupt the timings in open().
We could introduce a new spinlock, but it's easier to use the one that is already there (ffs->eps_lock) instead - the locking environment is safe for it in all affected places.
Since now it is held over all places that alter or check the open count (ffs->opened), there's no need to keep that atomic_t - int would serve just fine and it's simpler that way.
Stable-dep-of: 3137b243c939 ("usb: gadget: f_fs: initialize reset_work at allocation time")
--- drivers/usb/gadget/function/f_fs.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/usb/gadget/function/f_fs.c +8 -0
@@ -3736,6 +3736,7 @@ static int ffs_func_set_alt(struct usb_f {struct ffs_function *func =ffs_func_from_usb (f);struct ffs_data *ffs = func->ffs; +unsigned long flags;int ret =0 , intf;if (alt >MAX_ALT_SETTINGS )
@@ -3748,12 +3749,15 @@ static int ffs_func_set_alt(struct usb_fif (ffs->func)ffs_func_eps_disable (ffs->func); +spin_lock_irqsave (&ffs->eps_lock, flags);if (ffs->state ==FFS_DEACTIVATED ) { ffs->state =FFS_CLOSING ; +spin_unlock_irqrestore (&ffs->eps_lock, flags);INIT_WORK (&ffs->reset_work, ffs_reset_work);schedule_work (&ffs->reset_work);return -ENODEV ; } +spin_unlock_irqrestore (&ffs->eps_lock, flags);if (ffs->state !=FFS_ACTIVE )return -ENODEV ;
@@ -3771,16 +3775,20 @@ static void ffs_func_disable(struct usb_ {struct ffs_function *func =ffs_func_from_usb (f);struct ffs_data *ffs = func->ffs; +unsigned long flags;if (ffs->func)ffs_func_eps_disable (ffs->func); +spin_lock_irqsave (&ffs->eps_lock, flags);if (ffs->state ==FFS_DEACTIVATED ) { ffs->state =FFS_CLOSING ; +spin_unlock_irqrestore (&ffs->eps_lock, flags);INIT_WORK (&ffs->reset_work, ffs_reset_work);schedule_work (&ffs->reset_work);return ; } +spin_unlock_irqrestore (&ffs->eps_lock, flags);if (ffs->state ==FFS_ACTIVE ) { ffs->func =NULL ;
Greg Kroah-Hartman
maintainerPATCH 1583/1611 usb: gadget: f_fs: initialize reset_work at allocation time
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyler Baker <[email protected]>
[ Upstream commit 3137b243c93982fe3460335e12f9247739766e10 ]
ffs_fs_kill_sb() unconditionally calls cancel_work_sync() on ffs->reset_work when a functionfs instance is unmounted:
ffs_data_reset(ffs); cancel_work_sync(&ffs->reset_work);
However ffs->reset_work is only ever initialized via INIT_WORK() in ffs_func_set_alt() and ffs_func_disable(), and only on the FFS_DEACTIVATED path. That state is reached solely by ffs_data_closed() when the instance is mounted with the "no_disconnect" option, so for the common case (no "no_disconnect", or mounted and unmounted without ever being deactivated) reset_work is never initialized.
ffs_data_new() allocates the ffs_data with kzalloc_obj() and does not initialize reset_work, and ffs_data_reset()/ffs_data_clear() do not touch it either, so reset_work.func is left NULL. cancel_work_sync() on such a work then trips the WARN_ON(!work->func) guard in __flush_work():
WARNING: kernel/workqueue.c:4301 at __flush_work+0x330/0x360, CPU#3: umount Call trace: __flush_work cancel_work_sync ffs_fs_kill_sb [usb_f_fs] deactivate_locked_super deactivate_super cleanup_mnt __cleanup_mnt task_work_run exit_to_user_mode_loop el0_svc
On older kernels cancel_work_sync() on a zero-initialized work struct was a silent no-op, which hid the missing initialization.
Initialize reset_work once in ffs_data_new() so it is always valid for the lifetime of the ffs_data, and drop the now-redundant INIT_WORK() calls from the two deactivation paths.
--- drivers/usb/gadget/function/f_fs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/f_fs.c +2 -2
@@ -289,6 +289,7 @@ static int ffs_acquire_dev(const char *dstatic void ffs_release_dev (struct ffs_dev *ffs_dev);static int ffs_ready (struct ffs_data *ffs);static void ffs_closed (struct ffs_data *ffs); +static void ffs_reset_work (struct work_struct *work);/* Misc helper functions ****************************************************/
@@ -2206,6 +2207,7 @@ static struct ffs_data *ffs_data_new(coninit_waitqueue_head (&ffs->ev.waitq);init_waitqueue_head (&ffs->wait);init_completion (&ffs->ep0req_completion); +INIT_WORK (&ffs->reset_work, ffs_reset_work);/* XXX REVISIT need to update it in some places, or do we? */ ffs->ev.can_stall =1 ;
@@ -3753,7 +3755,6 @@ static int ffs_func_set_alt(struct usb_fif (ffs->state ==FFS_DEACTIVATED ) { ffs->state =FFS_CLOSING ;spin_unlock_irqrestore (&ffs->eps_lock, flags); -INIT_WORK (&ffs->reset_work, ffs_reset_work);schedule_work (&ffs->reset_work);return -ENODEV ; }
@@ -3784,7 +3785,6 @@ static void ffs_func_disable(struct usb_if (ffs->state ==FFS_DEACTIVATED ) { ffs->state =FFS_CLOSING ;spin_unlock_irqrestore (&ffs->eps_lock, flags); -INIT_WORK (&ffs->reset_work, ffs_reset_work);schedule_work (&ffs->reset_work);return ; }
Greg Kroah-Hartman
maintainerPATCH 1584/1611 usb: gadget: f_fs: Tie read_buffer lifetime to ffs_epfile
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Neill Kapron <[email protected]>
[ Upstream commit 8bdcf96eb135aebacac319667f87db034fb38406 ]
Currently, ffs_epfile_release unconditionally frees the endpoint's read_buffer when a file descriptor is closed. If userspace explicitly opens the endpoint multiple times and closes one, the read_buffer is destroyed. This can lead to silent data loss if other file descriptors are still actively reading from the endpoint.
By tying the lifetime of the read_buffer to the ffs_epfile structure itself (which is destroyed when the functionfs instance is torn down in ffs_epfiles_destroy), we eliminate the brittle dependency on open/release calls while correctly matching the conceptual lifetime of unread data on the hardware endpoint.
--- drivers/usb/gadget/function/f_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_fs.c +1 -1
@@ -1353,7 +1353,6 @@ ffs_epfile_release(struct inode *inode,mutex_unlock (&epfile->dmabufs_mutex); -__ffs_epfile_read_buffer_free (epfile);ffs_data_closed (epfile->ffs);return 0 ;
@@ -2370,6 +2369,7 @@ static void ffs_epfiles_destroy(struct sfor (; count; --count, ++epfile) {BUG_ON (mutex_is_locked (&epfile->mutex)); +__ffs_epfile_read_buffer_free (epfile);simple_remove_by_name (root, epfile->name,NULL ); }
Greg Kroah-Hartman
maintainerPATCH 1585/1611 crypto: atmel-sha204a - fail on hwrng registration error in probe path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 49e05bb00f2e8168695f7af4d694c39e1423e8a2 ]
Commit 13909a0c8897 ("crypto: atmel-sha204a - provide the otp content") overwrote the hwrng registration return value when creating the sysfs group, which allowed atmel_sha204a_probe() to succeed even if devm_hwrng_register() failed.
Return immediately when devm_hwrng_register() fails, and report both hwrng and sysfs registration errors with dev_err(). Adjust the sysfs error log message for consistency.
--- drivers/crypto/atmel-sha204a.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/crypto/atmel-sha204a.c +5 -3
@@ -183,8 +183,10 @@ static int atmel_sha204a_probe(struct i2 i2c_priv->hwrng.quality = *quality; ret =devm_hwrng_register (&client->dev, &i2c_priv->hwrng); -if (ret) -dev_warn (&client->dev,"failed to register RNG (%d)\n" , ret); +if (ret) { +dev_err (&client->dev,"failed to register RNG (%d)\n" , ret); +return ret; + }/* otp read out */ if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C ))
@@ -192,7 +194,7 @@ static int atmel_sha204a_probe(struct i2 ret =sysfs_create_group (&client->dev.kobj, &atmel_sha204a_groups);if (ret) { -dev_err (&client->dev,"failed to register sysfs entry\n" ); +dev_err (&client->dev,"failed to create sysfs group (%d)\n" , ret);return ret; }
Greg Kroah-Hartman
maintainerPATCH 1586/1611 btrfs: concentrate the error handling of submit_one_sector()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 44820d80026e0b509007d41c83d42f1213ee8589 ]
Currently submit_one_sector() has only one failure path from btrfs_get_extent().
However the error handling is split into two parts, one inside submit_one_sector(), which clears the dirty flag and finishes the writeback for the fs block.
The other part is to submit any remaining bio inside bio_ctrl and mark the ordered extent finished for the fs block.
There is no special reason that we must split the error handling, let's just concentrate all the error handling into submit_one_sector().
Stable-dep-of: 66ff4d366e7e ("btrfs: fix false IO failure after falling back to buffered write")
--- fs/btrfs/extent_io.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
fs/btrfs/extent_io.c +15 -14
@@ -1599,7 +1599,7 @@ out:/* * Return 0 if we have submitted or queued the sector for submission. -* Return <0 for critical errors, and the sector will have its dirty flag cleared. +* Return <0 for critical errors, and the involved sector will be cleaned up. * * Caller should make sure filepos < i_size and handle filepos >= i_size case. */
@@ -1624,6 +1624,13 @@ static int submit_one_sector(struct btrf em =btrfs_get_extent (inode,NULL , filepos, sectorsize);if (IS_ERR (em)) {/* +* bio_ctrl may contain a bio crossing several folios. +* Submit it immediately so that the bio has a chance +* to finish normally, other than marked as error. +*/ +submit_one_bio (bio_ctrl); + +/* * When submission failed, we should still clear the folio dirty. * Or the folio will be written back again but without any * ordered extent.
@@ -1631,6 +1638,13 @@ static int submit_one_sector(struct btrfbtrfs_folio_clear_dirty (fs_info, folio, filepos, sectorsize);btrfs_folio_set_writeback (fs_info, folio, filepos, sectorsize);btrfs_folio_clear_writeback (fs_info, folio, filepos, sectorsize); + +/* +* Since there is no bio submitted to finish the ordered +* extent, we have to manually finish this sector. +*/ +btrfs_mark_ordered_io_finished (inode, folio, filepos, + fs_info->sectorsize, false);return PTR_ERR (em); }
@@ -1756,19 +1770,6 @@ static noinline_for_stack int extent_wri } ret =submit_one_sector (inode, folio, cur, bio_ctrl, i_size);if (unlikely (ret <0 )) { -/* -* bio_ctrl may contain a bio crossing several folios. -* Submit it immediately so that the bio has a chance -* to finish normally, other than marked as error. -*/ -submit_one_bio (bio_ctrl); -/* -* Failed to grab the extent map which should be very rare. -* Since there is no bio submitted to finish the ordered -* extent, we have to manually finish this sector. -*/ -btrfs_mark_ordered_io_finished (inode, folio, cur, - fs_info->sectorsize, false);if (!found_error) found_error = ret;continue ;
Greg Kroah-Hartman
maintainerPATCH 1587/1611 btrfs: replace for_each_set_bit() with for_each_set_bitmap()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit e6698b34fab33867ef3faeeea6feb165f31aae24 ]
Inside extent_io.c, there are several simple call sites doing things like:
for_each_set_bit(bit, bitmap, bitmap_size) {
/* handle one fs block */
}The workload includes:
- set_bit()
Inside extent_writepage_io().
This can be replaced with a bitmap_set().
- btrfs_folio_set_lock()
- btrfs_mark_ordered_io_finished()
Inside writepage_delalloc().
Instead of calling it multiple times, we can pass a range into the function with one call.
Stable-dep-of: 66ff4d366e7e ("btrfs: fix false IO failure after falling back to buffered write")
--- fs/btrfs/extent_io.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
fs/btrfs/extent_io.c +16 -10
@@ -1427,8 +1427,9 @@ static noinline_for_stack int writepage_u64 delalloc_start = page_start;u64 delalloc_end = page_end;u64 delalloc_to_write =0 ; +unsigned int start_bit; +unsigned int end_bit;int ret =0 ; -int bit;/* Save the dirty bitmap as our submission bitmap will be a subset of it. */ if (btrfs_is_subpage (fs_info, folio)) {
@@ -1438,10 +1439,12 @@ static noinline_for_stack int writepage_ bio_ctrl->submit_bitmap =1 ; } -for_each_set_bit (bit, &bio_ctrl->submit_bitmap, blocks_per_folio) { -u64 start = page_start + (bit << fs_info->sectorsize_bits); +for_each_set_bitrange (start_bit, end_bit, &bio_ctrl->submit_bitmap, + blocks_per_folio) { +u64 start = page_start + (start_bit << fs_info->sectorsize_bits); +u32 len = (end_bit - start_bit) << fs_info->sectorsize_bits; -btrfs_folio_set_lock (fs_info, folio, start, fs_info->sectorsize); +btrfs_folio_set_lock (fs_info, folio, start, len); }/* Lock all (subpage) delalloc ranges inside the folio first. */
@@ -1558,10 +1561,13 @@ static noinline_for_stack int writepage_ fs_info->sectorsize_bits, blocks_per_folio); -for_each_set_bit (bit, &bio_ctrl->submit_bitmap, bitmap_size) -btrfs_mark_ordered_io_finished (inode, folio, - page_start + (bit << fs_info->sectorsize_bits), - fs_info->sectorsize, false); +for_each_set_bitrange (start_bit, end_bit, &bio_ctrl->submit_bitmap, + bitmap_size) { +u64 start = page_start + (start_bit << fs_info->sectorsize_bits); +u32 len = (end_bit - start_bit) << fs_info->sectorsize_bits; + +btrfs_mark_ordered_io_finished (inode, folio, start, len, false); + }return ret; } out:
@@ -1727,8 +1733,8 @@ static noinline_for_stack int extent_wrireturn ret; } -for (cur = start; cur < end; cur += fs_info->sectorsize) -set_bit ((cur - folio_start) >> fs_info->sectorsize_bits, &range_bitmap); +bitmap_set (&range_bitmap, (start -folio_pos (folio)) >> fs_info->sectorsize_bits, + len >> fs_info->sectorsize_bits);bitmap_and (&bio_ctrl->submit_bitmap, &bio_ctrl->submit_bitmap, &range_bitmap, blocks_per_folio);
Greg Kroah-Hartman
maintainerPATCH 1588/1611 btrfs: remove folio parameter from ordered io related functions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit a11d6912fdd9e57aff889ec97256b1d6b4e5bf06 ]
Both functions btrfs_finish_ordered_extent() and btrfs_mark_ordered_io_finished() are accepting an optional folio parameter.
That @folio is passed into can_finish_ordered_extent(), which later will test and clear the ordered flag for the involved range.
However I do not think there is any other call site that can clear ordered flags of an page cache folio and can affect can_finish_ordered_extent().
There are limited *_clear_ordered() callers out of can_finish_ordered_extent() function:
- btrfs_migrate_folio()
This is completely unrelated, it's just migrating the ordered flag to the new folio.
- btrfs_cleanup_ordered_extents()
We manually clean the ordered flags of all involved folios, then call btrfs_mark_ordered_io_finished() without a @folio parameter. So it doesn't need and didn't pass a @folio parameter in the first place.
- btrfs_writepage_fixup_worker()
This function is going to be removed soon, and we should not hit that function anymore.
- btrfs_invalidate_folio()
This is the real call site we need to bother with.
If we already have a bio running, btrfs_finish_ordered_extent() in end_bbio_data_write() will be executed first, as btrfs_invalidate_folio() will wait for the writeback to finish.
Thus if there is a running bio, it will not see the range has ordered flags, and just skip to the next range.
If there is no bio running, meaning the ordered extent is created but the folio is not yet submitted.
In that case btrfs_invalidate_folio() will manually clear the folio ordered range, but then manually finish the ordered extent with btrfs_dec_test_ordered_pending() without bothering the folio ordered flags.
Meaning if the OE range with folio ordered flags will be finished manually without the need to call can_finish_ordered_extent().
This means all can_finish_ordered_extent() call sites should get a range that has folio ordered flag set, thus the old "return false" branch should never be triggered.
Now we can:
- Remove the @folio parameter from involved functions
* btrfs_mark_ordered_io_finished()
* btrfs_finish_ordered_extent()
For call sites passing a @folio into those functions, let them manually clear the ordered flag of involved folios.
- Move btrfs_finish_ordered_extent() out of the loop in end_bbio_data_write()
We only need to call btrfs_finish_ordered_extent() once per bbio, not per folio.
- Add an ASSERT() to make sure all folio ranges have ordered flags It's only for end_bbio_data_write().
And we already have enough safe nets to catch over-accounting of ordered extents.
Stable-dep-of: 66ff4d366e7e ("btrfs: fix false IO failure after falling back to buffered write")
--- fs/btrfs/compression.c | 2 +- fs/btrfs/direct-io.c | 9 ++++----- fs/btrfs/extent_io.c | 23 ++++++++++++++--------- fs/btrfs/inode.c | 10 ++++++---- fs/btrfs/ordered-data.c | 29 +++++------------------------ fs/btrfs/ordered-data.h | 6 ++---- 6 files changed, 32 insertions(+), 47 deletions(-)
fs/btrfs/compression.c +1 -1
@@ -324,7 +324,7 @@ static void btrfs_finish_compressed_writstruct compressed_bio *cb = container_of(work, struct compressed_bio, write_end_work); -btrfs_finish_ordered_extent (cb->bbio.ordered,NULL , cb->start, cb->len, +btrfs_finish_ordered_extent (cb->bbio.ordered, cb->start, cb->len, cb->bbio.bio.bi_status ==BLK_STS_OK );if (cb->writeback)
fs/btrfs/direct-io.c +4 -5
@@ -625,7 +625,7 @@ static int btrfs_dio_iomap_end(struct in pos += submitted; length -= submitted;if (write) -btrfs_finish_ordered_extent (dio_data->ordered,NULL , +btrfs_finish_ordered_extent (dio_data->ordered, pos, length, false);else btrfs_unlock_dio_extent(&BTRFS_I(inode)->io_tree, pos,
@@ -657,9 +657,8 @@ static void btrfs_dio_end_io(struct btrf }if (btrfs_op (bio) ==BTRFS_MAP_WRITE ) { -btrfs_finish_ordered_extent (bbio->ordered,NULL , - dip->file_offset, dip->bytes, - !bio->bi_status); +btrfs_finish_ordered_extent (bbio->ordered, dip->file_offset, + dip->bytes, !bio->bi_status); }else {btrfs_unlock_dio_extent (&inode->io_tree, dip->file_offset, dip->file_offset + dip->bytes -1 ,NULL );
@@ -735,7 +734,7 @@ static void btrfs_dio_submit_io(const st ret =btrfs_extract_ordered_extent (bbio, dio_data->ordered);if (ret) { -btrfs_finish_ordered_extent (dio_data->ordered,NULL , +btrfs_finish_ordered_extent (dio_data->ordered, file_offset, dip->bytes, !ret); bio->bi_status =errno_to_blk_status (ret);
fs/btrfs/extent_io.c +14 -9
@@ -523,6 +523,7 @@ static void end_bbio_data_write(struct bint error =blk_status_to_errno (bio->bi_status);struct folio_iter fi;const u32 sectorsize = fs_info->sectorsize; +u32 bio_size =0 ;ASSERT (!bio_flagged (bio,BIO_CLONED ));bio_for_each_folio_all (fi, bio) {
@@ -530,6 +531,7 @@ static void end_bbio_data_write(struct bu64 start =folio_pos (folio) + fi.offset;u32 len = fi.length; + bio_size += len;/* Our read/write should always be sector aligned. */ if (!IS_ALIGNED (fi.offset, sectorsize)) btrfs_err(fs_info,
@@ -540,13 +542,15 @@ static void end_bbio_data_write(struct b"incomplete page write with offset %zu and length %zu" , fi.offset, fi.length); -btrfs_finish_ordered_extent (bbio->ordered, folio, start, len, - !error);if (error)mapping_set_error (folio->mapping, error); + +ASSERT (btrfs_folio_test_ordered (fs_info, folio, start, len)); +btrfs_folio_clear_ordered (fs_info, folio, start, len);btrfs_folio_clear_writeback (fs_info, folio, start, len); } +btrfs_finish_ordered_extent (bbio->ordered, bbio->file_offset, bio_size, !error);bio_put (bio); }
@@ -1566,7 +1570,8 @@ static noinline_for_stack int writepage_u64 start = page_start + (start_bit << fs_info->sectorsize_bits);u32 len = (end_bit - start_bit) << fs_info->sectorsize_bits; -btrfs_mark_ordered_io_finished (inode, folio, start, len, false); +btrfs_folio_clear_ordered (fs_info, folio, start, len); +btrfs_mark_ordered_io_finished (inode, start, len, false); }return ret; }
@@ -1642,6 +1647,7 @@ static int submit_one_sector(struct btrf* ordered extent. */ btrfs_folio_clear_dirty (fs_info, folio, filepos, sectorsize); +btrfs_folio_clear_ordered (fs_info, folio, filepos, sectorsize);btrfs_folio_set_writeback (fs_info, folio, filepos, sectorsize);btrfs_folio_clear_writeback (fs_info, folio, filepos, sectorsize);
@@ -1649,8 +1655,8 @@ static int submit_one_sector(struct btrf* Since there is no bio submitted to finish the ordered * extent, we have to manually finish this sector. */ -btrfs_mark_ordered_io_finished (inode, folio, filepos, - fs_info->sectorsize, false); +btrfs_mark_ordered_io_finished (inode, filepos, fs_info->sectorsize, + false);return PTR_ERR (em); }
@@ -1761,8 +1767,8 @@ static noinline_for_stack int extent_wrispin_unlock_irqrestore (&inode->ordered_tree_lock, flags);btrfs_put_ordered_extent (ordered); -btrfs_mark_ordered_io_finished (inode, folio, cur, - fs_info->sectorsize, true); +btrfs_folio_clear_ordered (fs_info, folio, cur, fs_info->sectorsize); +btrfs_mark_ordered_io_finished (inode, cur, fs_info->sectorsize, true);/* * This range is beyond i_size, thus we don't need to * bother writing back.
@@ -2640,8 +2646,7 @@ void extent_write_locked_range(struct inif (IS_ERR (folio)) { cur_end =min (round_down (cur,PAGE_SIZE ) +PAGE_SIZE -1 , end); cur_len = cur_end +1 - cur; -btrfs_mark_ordered_io_finished (BTRFS_I (inode),NULL , - cur, cur_len, false); +btrfs_mark_ordered_io_finished (BTRFS_I (inode), cur, cur_len, false);mapping_set_error (mapping,PTR_ERR (folio)); cur = cur_end;continue ;
fs/btrfs/inode.c +6 -4
@@ -424,7 +424,7 @@ static inline void btrfs_cleanup_orderedfolio_put (folio); } -return btrfs_mark_ordered_io_finished (inode,NULL , offset, bytes, false); +return btrfs_mark_ordered_io_finished (inode, offset, bytes, false); }static int btrfs_dirty_inode (struct btrfs_inode *inode);
@@ -2864,7 +2864,9 @@ out_page:* to reflect the errors and clean the page. */ mapping_set_error (folio->mapping, ret); -btrfs_mark_ordered_io_finished (inode, folio, page_start, +btrfs_folio_clear_ordered (fs_info, folio, page_start, +folio_size (folio)); +btrfs_mark_ordered_io_finished (inode, page_start,folio_size (folio), !ret);folio_clear_dirty_for_io (folio); }
@@ -7679,11 +7681,11 @@ static void btrfs_invalidate_folio(strucEXTENT_LOCKED |EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, &cached_state); -spin_lock_irq (&inode->ordered_tree_lock); +spin_lock (&inode->ordered_tree_lock);set_bit (BTRFS_ORDERED_TRUNCATED , &ordered->flags); ordered->truncated_len =min (ordered->truncated_len, cur - ordered->file_offset); -spin_unlock_irq (&inode->ordered_tree_lock); +spin_unlock (&inode->ordered_tree_lock);/* * If the ordered extent has finished, we're safe to delete all
fs/btrfs/ordered-data.c +5 -24
@@ -348,30 +348,13 @@ static void finish_ordered_fn(struct btr }static bool can_finish_ordered_extent (struct btrfs_ordered_extent *ordered, -struct folio *folio,u64 file_offset, -u64 len,bool uptodate) +u64 file_offset,u64 len,bool uptodate) {struct btrfs_inode *inode = ordered->inode;struct btrfs_fs_info *fs_info = inode->root->fs_info;lockdep_assert_held (&inode->ordered_tree_lock); -if (folio) { -ASSERT (folio->mapping); -ASSERT (folio_pos (folio) <= file_offset); -ASSERT (file_offset + len <=folio_end (folio)); - -/* -* Ordered flag indicates whether we still have -* pending io unfinished for the ordered extent. -* -* If it's not set, we need to skip to next range. -*/ -if (!btrfs_folio_test_ordered (fs_info, folio, file_offset, len)) -return false; -btrfs_folio_clear_ordered (fs_info, folio, file_offset, len); - } -/* Now we're fine to update the accounting. */ if (WARN_ON_ONCE (len > ordered->bytes_left)) { btrfs_crit(fs_info,
@@ -413,8 +396,7 @@ static void btrfs_queue_ordered_fn(struc }void btrfs_finish_ordered_extent (struct btrfs_ordered_extent *ordered, -struct folio *folio,u64 file_offset,u64 len, -bool uptodate) +u64 file_offset,u64 len,bool uptodate) {struct btrfs_inode *inode = ordered->inode;unsigned long flags;
@@ -423,7 +405,7 @@ void btrfs_finish_ordered_extent(structtrace_btrfs_finish_ordered_extent (inode, file_offset, len, uptodate);spin_lock_irqsave (&inode->ordered_tree_lock, flags); - ret =can_finish_ordered_extent (ordered, folio, file_offset, len, + ret =can_finish_ordered_extent (ordered, file_offset, len, uptodate);spin_unlock_irqrestore (&inode->ordered_tree_lock, flags);
@@ -476,8 +458,7 @@ void btrfs_finish_ordered_extent(struct* extent(s) covering it. */ void btrfs_mark_ordered_io_finished (struct btrfs_inode *inode, -struct folio *folio,u64 file_offset, -u64 num_bytes,bool uptodate) +u64 file_offset,u64 num_bytes,bool uptodate) {struct rb_node *node;struct btrfs_ordered_extent *entry =NULL ;
@@ -540,7 +521,7 @@ void btrfs_mark_ordered_io_finished(struASSERT (end +1 - cur <U32_MAX ); len = end +1 - cur; -if (can_finish_ordered_extent (entry, folio, cur, len, uptodate)) { +if (can_finish_ordered_extent (entry, cur, len, uptodate)) {spin_unlock_irqrestore (&inode->ordered_tree_lock, flags);btrfs_queue_ordered_fn (entry);spin_lock_irqsave (&inode->ordered_tree_lock, flags);
fs/btrfs/ordered-data.h +2 -4
@@ -164,11 +164,9 @@ void btrfs_put_ordered_extent(struct btrvoid btrfs_remove_ordered_extent (struct btrfs_inode *btrfs_inode,struct btrfs_ordered_extent *entry);void btrfs_finish_ordered_extent (struct btrfs_ordered_extent *ordered, -struct folio *folio,u64 file_offset,u64 len, -bool uptodate); +u64 file_offset,u64 len,bool uptodate);void btrfs_mark_ordered_io_finished (struct btrfs_inode *inode, -struct folio *folio,u64 file_offset, -u64 num_bytes,bool uptodate); +u64 file_offset,u64 num_bytes,bool uptodate);bool btrfs_dec_test_ordered_pending (struct btrfs_inode *inode,struct btrfs_ordered_extent **cached,u64 file_offset,u64 io_size);
Greg Kroah-Hartman
maintainerPATCH 1589/1611 crypto: qat - fix restarting state leak on allocation failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahsan Atta <[email protected]>
[ Upstream commit 7d3ed20f7e46b3e991936fedd7a28f3ff4aec8d2 ]
In adf_dev_aer_schedule_reset(), ADF_STATUS_RESTARTING is set before allocating reset_data. If the allocation fails, the function returns -ENOMEM without queuing reset work, so nothing ever clears the bit. This leaves the device permanently stuck in the restarting state, causing all subsequent reset attempts to be silently skipped.
Fix this by using test_and_set_bit() to atomically claim the RESTARTING state, preventing duplicate reset scheduling races under concurrent fatal error reporting. If the subsequent allocation fails, clear the bit to restore clean state so future reset attempts can proceed.
--- drivers/crypto/intel/qat/qat_common/adf_aer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_aer.c +4 -3
@@ -207,13 +207,14 @@ static int adf_dev_aer_schedule_reset(ststruct adf_reset_dev_data *reset_data;if (!adf_dev_started (accel_dev) || -test_bit (ADF_STATUS_RESTARTING , &accel_dev->status)) +test_and_set_bit (ADF_STATUS_RESTARTING , &accel_dev->status))return 0 ; -set_bit (ADF_STATUS_RESTARTING , &accel_dev->status); reset_data =kzalloc (sizeof (*reset_data),GFP_KERNEL ); -if (!reset_data) +if (!reset_data) { +clear_bit (ADF_STATUS_RESTARTING , &accel_dev->status);return -ENOMEM ; + } reset_data->accel_dev = accel_dev;init_completion (&reset_data->compl); reset_data->mode = mode;
Greg Kroah-Hartman
maintainerPATCH 1590/1611 btrfs: fix false IO failure after falling back to buffered write
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 66ff4d366e7eb4d31813d2acabf3af512ce03aa5 ]
[BUG]
The test case generic/362 will fail with "nodatasum" mount option (*):
MOUNT_OPTIONS -- -o nodatasum /dev/mapper/test-scratch1 /mnt/scratch
# generic/362 0s ... - output mismatch (see /home/adam/xfstests/results//generic/362.out.bad) # --- tests/generic/362.out 2024-08-24 15:31:37.200000000 +0930 # +++ /home/adam/xfstests/results//generic/362.out.bad 2026-05-27 10:21:17.574771567 +0930 # @@ -1,2 +1,3 @@ # QA output created by 362 # +First write failed: Input/output error # Silence is golden # ...
*: If the test case has been executed before with default data checksum, the failure will not reproduce. Need the following fix to make it reliably reproducible:
https://lore.kernel.org/linux-btrfs/[email protected]/
[CAUSE]
Inside __iomap_dio_rw(), the -EFAULT/-ENOTBLK error is not directly returned. Thus we never got an error pointer from __iomap_dio_rw().
The call chain looks like this:
btrfs_direct_write()
|- btrfs_dio_write()
|- __iomap_dio_rw()
| |- iomap_iter()
| | |- btrfs_dio_iomap_begin()
| | Now an ordered extent is allocated for the 4K write.
| |
| |- iomi.status = iomap_dio_iter()
| | Where iomap_dio_iter() returned -EFAULT.
| |
| |- ret = iomap_iter()
| | |- btrfs_dio_iomap_end()
| | | |- btrfs_finish_ordered_extent(uptodate = false)
| | | | |- can_finish_ordered_extent()
| | | | |- btrfs_mark_ordered_extent_error()
| | | | |- mapping_set_error()
| | | | Now the address space is marked error.
| | | | return -ENOTBLK
| | |- return -ENOTBLK
| |- if (ret == -ENOTBLK) { ret = 0; }
| Now the return value is reset to 0.
| Thus no error pointer will be returned.
|
|- ret = iomap_dio_complete()
| Since no byte is submitted, @ret is 0.
|
|- Fallback to buffered IO
| And the buffered write finished without error
|
|- filemap_fdatawait_range() |- filemap_check_errors()
The previous error is recorded, thus an error is returned
However the buffered write is properly submitted and finished, the error is from the btrfs_finish_ordered_extent() call with @uptodate = false.
[FIX]
When a short dio write happened, any range that is submitted will have btrfs_extract_ordered_extent() to be called, thus the submitted range will always have an OE just covering the submitted range.
The remaining OE range is never submitted, thus they should be treated as truncated, not an error. So that we can properly reclaim and not insert an unnecessary file extent item, without marking the mapping as error.
Extract a helper, btrfs_mark_ordered_extent_truncated(), and utilize that helper to mark the direct IO ordered extent as truncated, so it won't cause failure for the later buffered fallback.
[REASON FOR NO FIXES TAG]
The bug itself is pretty old, at commit f85781fb505e ("btrfs: switch to iomap for direct IO") we're already passing @uptodate=false finishing the OE.
But at that time OE with IOERR won't call mapping_set_error(), so it's not exposed.
Later commit d61bec08b904 ("btrfs: mark ordered extent and inode with error if we fail to finish") finally exposed the bug, but that commit is doing a correct job, not the root cause.
Anyway the bug is very old, dating back to 5.1x days, thus only CC to stable.
--- fs/btrfs/direct-io.c | 17 ++++++++++++++--- fs/btrfs/inode.c | 6 +----- fs/btrfs/ordered-data.c | 12 ++++++++++++ fs/btrfs/ordered-data.h | 2 ++ 4 files changed, 29 insertions(+), 8 deletions(-)
fs/btrfs/direct-io.c +14 -3
@@ -624,12 +624,23 @@ static int btrfs_dio_iomap_end(struct inif (submitted < length) { pos += submitted; length -= submitted; -if (write) +if (write) { +/* +* We have a short write, if there is any range +* that is submitted properly, that part will have +* its own OE split from the original one. +* +* So for the OE at dio_data->ordered, it's the part +* that is not submitted, and should be marked +* as fully truncated. +*/ +btrfs_mark_ordered_extent_truncated (dio_data->ordered,0 );btrfs_finish_ordered_extent (dio_data->ordered, - pos, length, false); -else + pos, length, true); + }else {btrfs_unlock_dio_extent (&BTRFS_I (inode)->io_tree, pos, pos + length -1 ,NULL ); + } ret = -ENOTBLK ; }if (write) {
fs/btrfs/inode.c +1 -5
@@ -7681,11 +7681,7 @@ static void btrfs_invalidate_folio(strucEXTENT_LOCKED |EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, &cached_state); -spin_lock (&inode->ordered_tree_lock); -set_bit (BTRFS_ORDERED_TRUNCATED , &ordered->flags); - ordered->truncated_len =min (ordered->truncated_len, - cur - ordered->file_offset); -spin_unlock (&inode->ordered_tree_lock); +btrfs_mark_ordered_extent_truncated (ordered, cur - ordered->file_offset);/* * If the ordered extent has finished, we're safe to delete all
fs/btrfs/ordered-data.c +12 -0
@@ -339,6 +339,18 @@ void btrfs_mark_ordered_extent_error(strmapping_set_error (ordered->inode->vfs_inode.i_mapping, -EIO ); } +void btrfs_mark_ordered_extent_truncated (struct btrfs_ordered_extent *ordered, +u64 truncate_len) +{ +struct btrfs_inode *inode = ordered->inode; + +ASSERT (truncate_len <= ordered->num_bytes); +spin_lock (&inode->ordered_tree_lock); +set_bit (BTRFS_ORDERED_TRUNCATED , &ordered->flags); + ordered->truncated_len =min (ordered->truncated_len, truncate_len); +spin_unlock (&inode->ordered_tree_lock); +} +static void finish_ordered_fn (struct btrfs_work *work) {struct btrfs_ordered_extent *ordered_extent;
fs/btrfs/ordered-data.h +2 -0
@@ -220,6 +220,8 @@ bool btrfs_try_lock_ordered_range(structstruct btrfs_ordered_extent *btrfs_split_ordered_extent (struct btrfs_ordered_extent *ordered,u64 len);void btrfs_mark_ordered_extent_error (struct btrfs_ordered_extent *ordered); +void btrfs_mark_ordered_extent_truncated (struct btrfs_ordered_extent *ordered, +u64 truncate_len);int __init ordered_data_init (void );void __cold ordered_data_exit (void );
Greg Kroah-Hartman
maintainerPATCH 1591/1611 btrfs: fix incorrect buffered IO fallback for append direct writes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit ff66fe6662330226b3f486014c375538d91c44aa ]
[BUG]
With the previous bug of short direct writes fixed, test case generic/362 (*) still fails with the following error with nodatasum mount option:
# generic/362 0s ... - output mismatch (see /home/adam/xfstests/results//generic/362.out.bad) # - output mismatch (see /home/adam/xfstests/results//generic/362.out.bad) # --- tests/generic/362.out 2024-08-24 15:31:37.200000000 +0930 # +++ /home/adam/xfstests/results//generic/362.out.bad 2026-05-27 10:13:09.072485767 +0930 # @@ -1,2 +1,3 @@ # QA output created by 362 # +Wrong file size after first write, got 8192 expected 4096 # Silence is golden # ...
*: If the test case has been executed before with default data checksum, the failure will not reproduce. Need the following fix to make it reliably reproducible:
https://lore.kernel.org/linux-btrfs/[email protected]/
[CAUSE]
Inside btrfs_dio_iomap_begin() for a direct write, we increase the isize if it's beyond the current isize.
But if the direct io finished short, we do not revert the isize to the previous value nor to the short write end.
Then if we need to fall back to buffered writes, and the write has IOCB_APPEND flag, then the buffered write will be positioned at the incorrect isize.
The call chain looks like this:
btrfs_direct_write(pos=0, length=4K)
|- __iomap_dio_rw()
| |- iomap_iter()
| | |- btrfs_dio_iomap_begin()
| | |- btrfs_get_blocks_direct_write()
| | |- i_size_write()
| | Which updates the isize to the write end (4K).
| |
| |- iomap_dio_iter()
| | Failed with -EFAULT on the first page.
| |
| |- iomap_iter()
| | |- btrfs_dio_iomap_end()
| | Detects a short write, return -ENOTBLK
| |- if (ret == -ENOTBLK) { ret = 0;}
| Which resets the return value.
|
|- ret = iomap_dio_complet()
| Which returns 0.
|
|- btrfs_buffered_write(iocb, from); |- generic_write_checks()
|- iocb->ki_pos = i_size_read()
Which is still the new size (4K), other than the original isize 0.
[FIX]
Introduce the following btrfs_dio_data members:
- old_isize
- updated_isize
If the direct write has enlarged the isize.
Then if we got a short write, and btrfs_dio_data::updated_isize is set, revert to the correct isize based on old_isize and current file position.
And here we call i_size_write() without holding an extent lock, which is a very special case that we're safe to do:
- Only a single writer can be enlarging isize Enlarging isize will take the exclusive inode lock.
- Buffered readers need to wait for the OE we're holding Buffered readers will lock extent and wait for OE of the folio range. Sometimes we can skip the OE wait, but since all page cache is invalidated, the OE wait can not be skipped.
But I do not think this is the most elegant solution, nor covers all cases. E.g. if the bio is submitted but IO failed, we are unable to do the revert.
I believe the more elegant one would be extend the EXTENT_DIO_LOCKED lifespan for direct writes, so that we can update the isize when a write beyond EOF finished successfully.
However that change is too huge for a small bug fix. So only implement the minimal partial fix for now.
[REASON FOR NO FIXES TAG]
The bug is again very old, before commit f85781fb505e ("btrfs: switch to iomap for direct IO") we are already increasing isize without a proper rollback for short writes.
Thus only a CC to stable.
--- fs/btrfs/direct-io.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
fs/btrfs/direct-io.c +42 -1
@@ -15,10 +15,12 @@struct btrfs_dio_data {ssize_t submitted; +loff_t old_isize;struct extent_changeset *data_reserved;struct btrfs_ordered_extent *ordered;bool data_space_reserved;bool nocow_done; +bool updated_isize; };struct btrfs_dio_private {
@@ -228,6 +230,7 @@ static int btrfs_get_blocks_direct_writebool space_reserved = false;u64 len = *lenp;u64 prev_len; +loff_t old_isize;int ret =0 ;/*
@@ -341,8 +344,14 @@ static int btrfs_get_blocks_direct_write* Need to update the i_size under the extent lock so buffered * readers will get the updated i_size when we unlock. */ -if (start + len >i_size_read (inode)) + old_isize =i_size_read (inode); +if (start + len > old_isize) { +if (!dio_data->updated_isize) { + dio_data->old_isize = old_isize; + dio_data->updated_isize = true; + }i_size_write (inode, start + len); + } out:if (ret && space_reserved) {btrfs_delalloc_release_extents (BTRFS_I (inode), len);
@@ -626,6 +635,38 @@ static int btrfs_dio_iomap_end(struct in length -= submitted;if (write) {/* +* Got a short write and have updated the isize, need to +* revert the isize change. +* +* Normally we need to update isize with extent lock hold, +* but we're safe due to the following factors: +* +* - Only a single writer can be enlarging isize +* Enlarging isize will take the exclusive inode lock. +* +* - Buffered readers need to wait for the OE we're holding +* Buffered readers will lock extent and wait for OE +* of the folio range, and since page cache is invalidated +* the OE wait can not be skipped. +* +* So here we are safe to revert the isize before +* finishing the OE, and no reader of the remaining range +* can see the enlarged size. +* +* TODO: Extend the DIO_LOCKED lifespan for direct writes, +* and only enlarge isize after a successful write. +*/ +if (dio_data->updated_isize) { +u64 new_isize; + +if (submitted ==0 ) + new_isize = dio_data->old_isize; +else + new_isize =max (dio_data->old_isize, pos); +i_size_write (inode, new_isize); + dio_data->updated_isize = false; + } +/* * We have a short write, if there is any range * that is submitted properly, that part will have * its own OE split from the original one.
Greg Kroah-Hartman
maintainerPATCH 1592/1611 KVM: arm64: Ensure level is always initialized when relaxing perms
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Upton <[email protected]>
commit 100baf0184896f859290a684f864b8200d8ac872 upstream.
stage2_update_leaf_attrs() returns early before writing to @level if the table walker returned an error. At the same time, kvm_pgtable_stage2_relax_perms() uses the level as a TLBI TTL hint when the error was EAGAIN, indicating the vCPU raced with a table update and the TLB entry it hit is now stale.
Fall back to an unknown TTL if none was provided by the walk.
--- arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp/pgtable.c +1 -1
@@ -1291,7 +1291,7 @@ int kvm_pgtable_stage2_relax_perms(struc enum kvm_pgtable_prot prot, enum kvm_pgtable_walk_flags flags) { int ret; -s8 level; +s8 level =TLBI_TTL_UNKNOWN ;kvm_pte_t set =0 , clr =0 ;if (prot &KVM_PTE_LEAF_ATTR_HI_SW )
Greg Kroah-Hartman
maintainerPATCH 1593/1611 KVM: arm64: Fix propagation of TLBI level in kvm_pgtable_stage2_relax_perms()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit 8d187d4b33c262c0f3e44842553521151d8629e8 upstream.
Assigning the invalidation level (an s8 value) with TLBI_TTL_UNKNOWN (a 32bit signed value) is not ideal, to say the least. Instead of this, only pass TLBI_TTL_UNKNOWN to __kvm_tlb_flush_vmid_ipa_nsh() when we know for sure that we don't have a provided level.
--- arch/arm64/kvm/hyp/pgtable.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/pgtable.c +3 -2
@@ -1291,7 +1291,7 @@ int kvm_pgtable_stage2_relax_perms(struc enum kvm_pgtable_prot prot, enum kvm_pgtable_walk_flags flags) { int ret; -s8 level =TLBI_TTL_UNKNOWN ; +s8 level;kvm_pte_t set =0 , clr =0 ;if (prot &KVM_PTE_LEAF_ATTR_HI_SW )
@@ -1308,7 +1308,8 @@ int kvm_pgtable_stage2_relax_perms(struc ret =stage2_update_leaf_attrs (pgt, addr,1 , set, clr,NULL , &level, flags);if (!ret || ret == -EAGAIN ) -kvm_call_hyp (__kvm_tlb_flush_vmid_ipa_nsh, pgt->mmu, addr, level); +kvm_call_hyp (__kvm_tlb_flush_vmid_ipa_nsh, pgt->mmu, addr, + (ret == -EAGAIN ) ?TLBI_TTL_UNKNOWN : level);return ret; }
Greg Kroah-Hartman
maintainerPATCH 1594/1611 mm/damon/core: always put unsuccessfully committed target pids
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit 6a66c557a2ab2609575bafd15e093669c05f9711 upstream.
damon_commit_target() puts and gets the destination and the source target pids. It puts the destination target pid because it will be overwritten by the source target pid. It gets the source pid because the caller is supposed to eventually put the pids. In more detail, the caller will call damon_destroy_ctx() after damon_commit_ctx() to destroy the entire source context. And in this case, [f]vaddr operation set's cleanup_target() callback will put the pids.
The commit operation is made at the context level. The operation can fail in multiple places including in the middle and after the targets commit operations. For any such failures, immediately the error is returned to the damon_commit_ctx() caller. If some or all of the source target pids were committed to the destination during the unsuccessful context commit attempt, those pids should be put twice.
The source context will do the put operations using the above explained routine. However, let's suppose the destination context was not originally using [f]vaddr operation set and the commit failed before the ops of the source context is committed. The destination does not have the cleanup_target() ops callback, so it cannot put the pids via the damon_destroy_ctx().
As a result, the pids are leaked. The issue in the real world would be not very common. The commit feature is for changing parameters of running DAMON context while inheriting internal status like the monitoring results. The monitoring results of a physical address range ain't have things that are beneficial to be inherited to a virtual address ranges monitoring. So the problem-causing DAMON control would be not very common in the real world. That said, it is a supported feature. And damon_commit_target() failure due to memory allocation is relatively realistic [1] if there are a huge number of target regions.
Fix by putting the pids in the commit operation in case of the failures.
The issue was discovered [2] by Sashiko.
--- mm/damon/core.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-)
mm/damon/core.c +43 -6
@@ -1173,10 +1173,36 @@ static int damon_commit_target(return 0 ; } +/* +* damon_revert_target_commits() - revert unsuccessful target commits. +* @dst: Commit destination context +* @failed: Commit failed destination target +* @src: Commit source context +* +* Revert target states that changed by damon_commit_target(), and cannot be +* cleaned up by the destination context's ops.cleanup_target(). +*/ +static void damon_revert_target_commits (struct damon_ctx *dst, +struct damon_target *failed,struct damon_ctx *src) +{ +struct damon_target *target; + +if (!damon_target_has_pid (src)) +return ; +if (dst->ops.cleanup_target) +return ; +damon_for_each_target (target, dst) { +if (target == failed) +return ; +put_pid (target->pid); + } +} +static int damon_commit_targets (struct damon_ctx *dst,struct damon_ctx *src) {struct damon_target *dst_target, *next, *src_target, *new_target; +struct damon_target *failed;int i =0 , j =0 , err;damon_for_each_target_safe (dst_target, next, dst) {
@@ -1186,8 +1212,10 @@ static int damon_commit_targets( dst_target,damon_target_has_pid (dst), src_target,damon_target_has_pid (src), src->min_sz_region); -if (err) -return err; +if (err) { + failed = dst_target; + goto out; + } }else {struct damos *s;
@@ -1201,22 +1229,29 @@ static int damon_commit_targets( } } + failed =NULL ;damon_for_each_target_safe (src_target, next, src) {if (j++ < i)continue ; new_target =damon_new_target (); -if (!new_target) -return -ENOMEM ; +if (!new_target) { + err = -ENOMEM ; + goto out; + } err =damon_commit_target (new_target, false, src_target,damon_target_has_pid (src), src->min_sz_region);if (err) {damon_destroy_target (new_target,NULL ); -return err; + goto out; }damon_add_target (dst, new_target); }return 0 ; + +out: +damon_revert_target_commits (dst, failed, src); +return err; }/**
@@ -1255,8 +1290,10 @@ int damon_commit_ctx(struct damon_ctx *d*/ if (!damon_attrs_equals (&dst->attrs, &src->attrs)) { err =damon_set_attrs (dst, &src->attrs); -if (err) +if (err) { +damon_revert_target_commits (dst,NULL , src);return err; + } } dst->ops = src->ops; dst->addr_unit = src->addr_unit;
Greg Kroah-Hartman
maintainerPATCH 1595/1611 mm/damon/core: trace esz at first setup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit 7e6cc35f5283eab81a14231a64ecd640b690c48c upstream.
DAMON traces effective size quota from the second update, only if a change has been made by the update. Tracing only changed updates was an intentional decision to avoid unnecessary same value tracing. Always skipping the first value is just an unintended mistake.
The mistake makes the tracepoint based investigation incomplete, because the first effective size quota is never traced. It is not a big issue when the 'consist' quota tuner is used, because it keeps changing the quota in the usual setup.
However, when the 'temporal' tuner is used, the quota value is not changed before the goal achievement status is completely changed. For example, if the DAMOS scheme is started with an under-achieved goal, the quota is set to the maximum value, and kept the same value until the goal is achieved. Because DAMON skips the first value, the user cannot know what effective quota the current scheme is using. Only after the goal is achieved, the effective quota is changed to zero, and traced.
Unconditionally trace the initial quota value to fix this problem.
Note that the 'temporal' quota tuner was introduced by commit af738a6a00c1 ("mm/damon/core: introduce DAMOS_QUOTA_GOAL_TUNER_TEMPORAL"), which was added to 7.1-rc1. But even with the 'consist' quota tuner, the tracing is unintentionally incomplete. Hence this commit marks the introduction of the trace event as the broken commit.
--- mm/damon/core.c | 2 ++ 1 file changed, 2 insertions(+)
mm/damon/core.c +2 -0
@@ -2237,6 +2237,8 @@ static void damos_adjust_quota(struct daif (!quota->total_charged_sz && !quota->charged_from) { quota->charged_from = jiffies;damos_set_effective_quota (quota, c); +if (trace_damos_esz_enabled ()) +damos_trace_esz (c, s, quota); }/* New charge window starts */
Greg Kroah-Hartman
maintainerPATCH 1596/1611 samples/damon/mtier: fail early if address range parameters are invalid
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zenghui Yu <[email protected]>
commit 7746d72c64054976887928d64d2caf25c5a6dcc0 upstream.
The comment on top of struct damon_region clearly says that
For any use case, @ar should be non-zero positive size.
which is now verified in damon_verify_new_region() if the kernel is built with DAMON_DEBUG_SANITY.
The WARN_ONCE() can be triggered if the mtier sample module is enabled before node{0,1}_{start,end}_addr have been properly initialized, which is obviously not good.
------------[ cut here ]------------ start 0 >= end 0 WARNING: mm/damon/core.c:217 at damon_new_region+0xf4/0x118, CPU#59: bash/341468 Call trace: damon_new_region+0xf4/0x118 (P) damon_set_regions+0xfc/0x3c0 damon_sample_mtier_build_ctx+0xe8/0x3a8 damon_sample_mtier_start+0x1c/0x90 damon_sample_mtier_enable_store+0x98/0xb0 param_attr_store+0xb4/0x128 module_attr_store+0x2c/0x50 sysfs_kf_write+0x58/0x90 kernfs_fop_write_iter+0x16c/0x238 vfs_write+0x2c0/0x370 ksys_write+0x74/0x118 __arm64_sys_write+0x24/0x38 invoke_syscall+0xa8/0x118 el0_svc_common.constprop.0+0x48/0xf0 do_el0_svc+0x24/0x38 el0_svc+0x54/0x370 el0t_64_sync_handler+0xa0/0xe8 el0t_64_sync+0x1ac/0x1b0 ---[ end trace 0000000000000000 ]---
Note that the same issue can happen if detect_node_addresses is true, and node 0 or 1 is memoryless. Fix it together by checking the validity of parameters right before damon_new_region() and fail early if they're invalid.
--- samples/damon/mtier.c | 2 ++ 1 file changed, 2 insertions(+)
samples/damon/mtier.c +2 -0
@@ -120,6 +120,8 @@ static struct damon_ctx *damon_sample_mt addr.end = promote ? node1_end_addr : node0_end_addr; } +if (addr.start >= addr.end) + goto free_out; region =damon_new_region (addr.start, addr.end);if (!region) goto free_out;
Greg Kroah-Hartman
maintainerPATCH 1597/1611 KVM: arm64: Deduplicate ASID retrieval code
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit 54e367cb94d6bef941bbc1132d9959dc73bd4b6f upstream.
We currently have three versions of the ASID retrieval code, one in the S1 walker, and two in the VNCR handling (although the last two are limited to the EL2&0 translation regime).
Make this code common, and take this opportunity to also simplify the code a bit while switching over to the TTBRx_EL1_ASID macro.
--- arch/arm64/include/asm/kvm_nested.h | 2 + arch/arm64/kvm/at.c | 27 +--------------- arch/arm64/kvm/nested.c | 60 ++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 54 deletions(-)
arch/arm64/include/asm/kvm_nested.h +2 -0
@@ -371,6 +371,8 @@ int kvm_vcpu_allocate_vncr_tlb(struct kvint kvm_handle_vncr_abort (struct kvm_vcpu *vcpu);void kvm_handle_s1e2_tlbi (struct kvm_vcpu *vcpu,u32 inst,u64 val); +u16 get_asid_by_regime (struct kvm_vcpu *vcpu,enum trans_regime regime); +#define vncr_fixmap (c) \ ({ \ u32 __c = (c); \
arch/arm64/kvm/at.c +2 -25
@@ -483,31 +483,8 @@ static int walk_s1(struct kvm_vcpu *vcpu wr->pa |= va &GENMASK_ULL (va_bottom -1 ,0 ); wr->nG = (wi->regime !=TR_EL2 ) && (desc &PTE_NG ); -if (wr->nG) { -u64 asid_ttbr, tcr; - -switch (wi->regime) { -case TR_EL10 : - tcr =vcpu_read_sys_reg (vcpu,TCR_EL1 ); - asid_ttbr = ((tcr &TCR_A1 ) ? -vcpu_read_sys_reg (vcpu,TTBR1_EL1 ) : -vcpu_read_sys_reg (vcpu,TTBR0_EL1 )); -break ; -case TR_EL20 : - tcr =vcpu_read_sys_reg (vcpu,TCR_EL2 ); - asid_ttbr = ((tcr &TCR_A1 ) ? -vcpu_read_sys_reg (vcpu,TTBR1_EL2 ) : -vcpu_read_sys_reg (vcpu,TTBR0_EL2 )); -break ; -default : -BUG (); - } - - wr->asid =FIELD_GET (TTBR_ASID_MASK , asid_ttbr); -if (!kvm_has_feat_enum (vcpu->kvm,ID_AA64MMFR0_EL1 ,ASIDBITS ,16 ) || - !(tcr &TCR_ASID16 )) - wr->asid &=GENMASK (7 ,0 ); - } +if (wr->nG) + wr->asid =get_asid_by_regime (vcpu, wi->regime);return 0 ;
arch/arm64/kvm/nested.c +31 -29
78 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 1598/1611 KVM: arm64: nv: Re-translate VNCR before injecting abort
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Upton <[email protected]>
commit bb645aa0a4caeaf7f9cd32e9a948594d434c1a8f upstream.
KVM faults in the VNCR page with FOLL_WRITE whenever the guest aborts for a write, similar to how a regular stage-2 mapping is handled. It is entirely possible that the guest reads from the VNCR before writing to it, in which case the PFN could only be read-only.
Invalidate the VNCR TLB and re-fetch the translation upon taking a VNCR abort, allowing the host mapping to be faulted in for write the second time around. Interestingly enough, this also satisfies the ordering requirements of FEAT_ETS2/3 between descriptor updates and MMU faults.
--- arch/arm64/kvm/nested.c | 115 ++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 71 deletions(-)
arch/arm64/kvm/nested.c +44 -71
@@ -1329,88 +1329,61 @@ static void handle_vncr_perm(struct kvm_kvm_inject_nested_sync (vcpu, esr); } -static bool kvm_vncr_tlb_lookup (struct kvm_vcpu *vcpu) -{ -struct vncr_tlb *vt = vcpu->arch.vncr_tlb; - -lockdep_assert_held_read (&vcpu->kvm->mmu_lock); - -if (!vt->valid) -return false; - -if (read_vncr_el2 (vcpu) != vt->gva) -return false; - -if (vt->wr.nG) -return get_asid_by_regime (vcpu,TR_EL20 ) == vt->wr.asid; - -return true; -} -int kvm_handle_vncr_abort (struct kvm_vcpu *vcpu) {struct vncr_tlb *vt = vcpu->arch.vncr_tlb;u64 esr =kvm_vcpu_get_esr (vcpu); +bool is_gmem = false; +bool perm; +int ret;WARN_ON_ONCE (!(esr & ESR_ELx_VNCR));if (kvm_vcpu_abt_issea (vcpu))return kvm_handle_guest_sea (vcpu); -if (esr_fsc_is_permission_fault (esr)) { -handle_vncr_perm (vcpu); - }else if (esr_fsc_is_translation_fault (esr)) { -bool valid, is_gmem = false; -int ret; - -scoped_guard (read_lock, &vcpu->kvm->mmu_lock) - valid = kvm_vncr_tlb_lookup(vcpu); - -if (!valid) - ret =kvm_translate_vncr (vcpu, &is_gmem); -else - ret = -EPERM ; - -switch (ret) { -case -EAGAIN : -/* Let's try again... */ -break ; -case -ENOMEM : -/* -* For guest_memfd, this indicates that it failed to -* create a folio to back the memory. Inform userspace. -*/ -if (is_gmem) -return 0 ; -/* Otherwise, let's try again... */ -break ; -case -EFAULT : -case -EIO : -case -EHWPOISON : -if (is_gmem) -return 0 ; - fallthrough; -case -EINVAL : -case -ENOENT : -case -EACCES : -/* -* Translation failed, inject the corresponding -* exception back to EL2. -*/ - esr &= ~ESR_ELx_FSC; - esr |=FIELD_PREP (ESR_ELx_FSC, vt->wr.fst); - -kvm_inject_nested_sync (vcpu, esr); -break ; -case -EPERM : -/* Hack to deal with POE until we get kernel support */ -handle_vncr_perm (vcpu); -break ; -case 0 : -break ; - } - }else { +if (!esr_fsc_is_translation_fault (esr) && !esr_fsc_is_permission_fault (esr)) {WARN_ONCE (1 ,"Unhandled VNCR abort, ESR=%llx\n" , esr); +return 1 ; + } + + ret =kvm_translate_vncr (vcpu, &is_gmem); +switch (ret) { +case -EAGAIN : +/* Let's try again... */ +return 1 ; +case -ENOMEM : +/* +* For guest_memfd, this indicates that it failed to +* create a folio to back the memory. Inform userspace. +*/ +if (is_gmem) +return 0 ; +/* Otherwise, let's try again... */ +break ; +case -EFAULT : +case -EIO : +case -EHWPOISON : +if (is_gmem) +return 0 ; + fallthrough; +case -EINVAL : +case -ENOENT : +case -EACCES : +/* +* Translation failed, inject the corresponding +* exception back to EL2. +*/ + esr &= ~ESR_ELx_FSC; + esr |=FIELD_PREP (ESR_ELx_FSC, vt->wr.fst); + +kvm_inject_nested_sync (vcpu, esr); +break ; +case 0 : + perm =kvm_is_write_fault (vcpu) ? vt->wr.pw && vt->hpa_writable : vt->wr.pr; +if (!perm) +handle_vncr_perm (vcpu); +break ; }return 1 ;
Greg Kroah-Hartman
maintainerPATCH 1599/1611 iommufd: Propagate allocation failure in iommufd_veventq_deliver_fetch()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
[ Upstream commit 489e63dd120bad52eba63f5506c214750cd5bc75 ]
When the kzalloc_obj() fails in iommufd_veventq_deliver_fetch(), it returns NULL, falsely advertising to userspace that the queue is empty.
Propagate the -ENOMEM properly to the caller.
--- drivers/iommu/iommufd/eventq.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/eventq.c +9 -1
@@ -272,8 +272,10 @@ iommufd_veventq_deliver_fetch(struct iom/* Make a copy of the lost_events_header for copy_to_user */ if (next == &veventq->lost_events_header) { vevent =kzalloc (sizeof (*vevent),GFP_ATOMIC ); -if (!vevent) +if (!vevent) { + vevent =ERR_PTR (-ENOMEM ); goto out_unlock; + } }list_del (&next->node);if (vevent)
@@ -323,6 +325,12 @@ static ssize_t iommufd_veventq_fops_readreturn -EINVAL ;while ((cur =iommufd_veventq_deliver_fetch (veventq))) { +if (IS_ERR (cur)) { +if (done ==0 ) + rc =PTR_ERR (cur); +break ; + } +/* Validate the remaining bytes against the header size */ if (done >= count ||sizeof (*hdr) > count - done) {iommufd_veventq_deliver_restore (veventq, cur);
Greg Kroah-Hartman
maintainerPATCH 1600/1611 iommufd: Move vevent memory allocation outside spinlock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
[ Upstream commit 47443565d10c51366c9382dbc8597cd6c460b8a2 ]
The veventq memory allocation happens inside the spinlock. Given its depth is decided by the user space, this leaves a vulnerability, where userspace can allocate large queues to exhaust atomic memory reserves.
Move the allocation outside the spinlock and use GFP_NOWAIT, which can fail fast under memory pressure without dipping into the GFP_ATOMIC reserves or direct-reclaiming from the threaded IRQ handler. On allocation failure, queue the lost_events_header (so userspace learns of the drop) and return -ENOMEM so the caller learns of the kernel-side memory pressure.
This is intentionally distinct from the queue-overflow path, which also queues the lost_events_header but returns 0: a full queue is an expected userspace-pacing condition rather than a kernel error.
A subsequent change will cap the upper bound of the veventq_depth.
--- drivers/iommu/iommufd/driver.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/iommu/iommufd/driver.c +8 -5
@@ -149,15 +149,18 @@ int iommufd_viommu_report_event(struct i goto out_unlock_veventqs; } -spin_lock (&veventq->common.lock); -if (veventq->num_events == veventq->depth) { +/* Pre-allocate to avoid GFP_ATOMIC; use GFP_NOWAIT to avoid sleeping */ + vevent =kzalloc_flex (*vevent, event_data, data_len,GFP_NOWAIT ); +if (!vevent) { +spin_lock (&veventq->common.lock); vevent = &veventq->lost_events_header; + rc = -ENOMEM ; goto out_set_header; } - vevent =kzalloc (struct_size (vevent, event_data, data_len),GFP_ATOMIC ); -if (!vevent) { - rc = -ENOMEM ; +spin_lock (&veventq->common.lock); +if (veventq->num_events == veventq->depth) { +kfree (vevent); vevent = &veventq->lost_events_header; goto out_set_header; }
Greg Kroah-Hartman
maintainerPATCH 1601/1611 bpf: Reject BPF_MAP_TYPE_INODE_STORAGE creation if BPF LSM is uninitialized
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Bobrowski <[email protected]>
[ Upstream commit a6f0643e4f63cfaa0d5d4a69de4f132eac4b8fe4 ]
When CONFIG_BPF_LSM=y is set, BPF inode storage maps (BPF_MAP_TYPE_INODE_STORAGE) are compiled into the kernel. However, if the BPF LSM is not explicitly enabled at boot time (e.g. omitted from the "lsm=" boot parameter), lsm_prepare() is never executed for the BPF LSM.
Consequently, the BPF inode security blob offset (bpf_lsm_blob_sizes.lbs_inode) is never initialized and remains at its default compiled size of 8 bytes instead of being updated to a valid offset past the reserved struct rcu_head (typically 16 bytes or more).
When a privileged user creates and updates a BPF_MAP_TYPE_INODE_STORAGE map, bpf_inode() evaluates inode->i_security + 8. This erroneously aliases the struct rcu_head.func callback pointer at the beginning of the inode->i_security blob. During subsequent map element cleanup or inode destruction, writing NULL to owner_storage clears the queued RCU callback pointer. When rcu_do_batch() later executes the queued callback, it attempts an instruction fetch at address 0x0, triggering an immediate kernel panic.
Fix this by introducing a global bpf_lsm_initialized boolean flag marked with __ro_after_init. Set this flag to true inside bpf_lsm_init() when the LSM framework successfully registers the BPF LSM. Gate map allocation in inode_storage_map_alloc() on this flag, returning -EOPNOTSUPP if the BPF LSM is in turn uninitialized.
This fail-fast approach prevents userspace from allocating inode storage maps when the supporting BPF LSM infrastructure is absent, avoiding zombie map states.
--- include/linux/bpf_lsm.h | 4 ++++ kernel/bpf/bpf_inode_storage.c | 9 +++++++++ security/bpf/hooks.c | 3 +++ 3 files changed, 16 insertions(+)
include/linux/bpf_lsm.h +4 -0
@@ -14,6 +14,8 @@#ifdef CONFIG_BPF_LSM +extern bool bpf_lsm_initialized__ro_after_init ; +#define LSM_HOOK (RET ,DEFAULT ,NAME , ...) \ RET bpf_lsm_##NAME(__VA_ARGS__);#include <linux/lsm_hook_defs.h>
@@ -56,6 +58,8 @@ bool bpf_lsm_hook_returns_errno(u32 btf_#else /* !CONFIG_BPF_LSM */ +#define bpf_lsm_initialized false +static inline bool bpf_lsm_is_sleepable_hook (u32 btf_id) {return false;
kernel/bpf/bpf_inode_storage.c +9 -0
@@ -181,6 +181,15 @@ static int notsupp_get_next_key(struct bstatic struct bpf_map *inode_storage_map_alloc (union bpf_attr *attr) { +/* +* Do not allow allocation of BPF_MAP_TYPE_INODE_STORAGE if the BPF LSM +* was not initialized by the LSM framework at boot. Without proper +* initialization, the BPF inode security blob offset remains unprepared, +* causing bpf_inode() to calculate an invalid memory offset and corrupt +* inode->i_security. +*/ +if (!bpf_lsm_initialized) +return ERR_PTR (-EOPNOTSUPP );return bpf_local_storage_map_alloc (attr, &inode_cache, false); }
security/bpf/hooks.c +3 -0
@@ -7,6 +7,8 @@#include <linux/bpf_lsm.h> #include <uapi/linux/lsm.h> +bool bpf_lsm_initialized__ro_after_init ; +static struct security_hook_list bpf_lsm_hooks[]__ro_after_init = { #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ LSM_HOOK_INIT(NAME, bpf_lsm_##NAME),
@@ -24,6 +26,7 @@ static int __init bpf_lsm_init(void) {security_add_hooks (bpf_lsm_hooks,ARRAY_SIZE (bpf_lsm_hooks), &bpf_lsmid); + bpf_lsm_initialized = true;pr_info ("LSM support for eBPF active\n" );return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1602/1611 pinctrl: airoha: fix pinctrl function mismatch issue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chukun Pan <[email protected]>
commit f2bd5a0f59d052d16749bccf637690e51947a5d6 upstream.
The blamed commit made the following changes:
-#define PINCTRL_FUNC_DESC(id)...
- .desc = PINCTRL_PINFUNCTION(#id, ...
+#define PINCTRL_FUNC_DESC(id, table)...
+ .desc = PINCTRL_PINFUNCTION(#id, ...
- PINCTRL_FUNC_DESC(pon)...
+ PINCTRL_FUNC_DESC("pon", pon)...
It's clear that the id of funcs doesn't match the definition. Remove redundant #string from the definition to fix this issue:
pinctrl-airoha ...: invalid function mdio in map table
--- drivers/pinctrl/mediatek/pinctrl-airoha.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/mediatek/pinctrl-airoha.c +1 -1
@@ -35,7 +35,7 @@#define PINCTRL_FUNC_DESC (id, table) \ { \ - .desc = PINCTRL_PINFUNCTION(#id, table##_groups, \ + .desc = PINCTRL_PINFUNCTION(id, table##_groups, \ ARRAY_SIZE(table##_groups)),\ .groups = table##_func_group, \ .group_size = ARRAY_SIZE(table##_func_group), \
Greg Kroah-Hartman
maintainerPATCH 1603/1611 perf symbol: Fix ENOENT case for filename__read_build_id
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
commit 5c5f6fe32df2edb4f72bdca62ec2b9f20b7c5ba4 upstream.
Some callers of filename__read_build_id assume the error value must be -1, fix by making them handle all < 0 values.
If is_regular_file fails in filename__read_build_id then it could be the file is missing (ENOENT) and it would be wrong to return -EWOULDBLOCK in that case. Fix the logic so -EWOULDBLOCK is only reported if other errors with stat haven't occurred.
--- tools/perf/builtin-buildid-cache.c | 6 ++++-- tools/perf/util/libbfd.c | 4 +++- tools/perf/util/symbol-elf.c | 4 +++- tools/perf/util/symbol-minimal.c | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-)
tools/perf/builtin-buildid-cache.c +4 -2
@@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(s {char filename[PATH_MAX ];struct build_id bid = { .size =0 , }; +int err;if (!dso__build_id_filename (dso, filename,sizeof (filename), false))return true; -if (filename__read_build_id (filename, &bid) ==-1 ) { -if (errno ==ENOENT ) + err =filename__read_build_id (filename, &bid); +if (err <0 ) { +if (err == -ENOENT )return false; pr_warning("Problems with %s file, consider removing it from the cache\n",
tools/perf/util/libbfd.c +3 -1
@@ -426,8 +426,10 @@ int libbfd__read_build_id(const char *fiif (!filename)return -EFAULT ; + + errno =0 ;if (!is_regular_file (filename)) -return -EWOULDBLOCK ; +return errno ==0 ? -EWOULDBLOCK : -errno; fd =open (filename,O_RDONLY );if (fd <0 )
tools/perf/util/symbol-elf.c +3 -1
@@ -916,8 +916,10 @@ int filename__read_build_id(const char *if (!filename)return -EFAULT ; + + errno =0 ;if (!is_regular_file (filename)) -return -EWOULDBLOCK ; +return errno ==0 ? -EWOULDBLOCK : -errno; err =kmod_path__parse (&m, filename);if (err)
tools/perf/util/symbol-minimal.c +3 -1
@@ -113,8 +113,10 @@ int filename__read_build_id(const char *if (!filename)return -EFAULT ; + + errno =0 ;if (!is_regular_file (filename)) -return -EWOULDBLOCK ; +return errno ==0 ? -EWOULDBLOCK : -errno; fd =open (filename,O_RDONLY );if (fd <0 )
Greg Kroah-Hartman
maintainerPATCH 1604/1611 PCI: Fix BAR resize rollback path overwriting ret
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilpo Järvinen <[email protected]>
commit 08d9eae76b85263173f8c833800e3cc409ee1be4 upstream.
The commit 337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path") added BAR rollback to pci_do_resource_release_and_resize() in case of resize failure.
On the rollback, pci_claim_resource() is called, which can fail and the code is prepared for that possibility. pci_claim_resource()'s return value, however, overwrites the original value of ret so pci_do_resource_release_and_resize() will return an incorrect value in the end (as pci_claim_resource() normally succeeds, in practice ret will be 0).
Fix the issue by directly calling pci_claim_resource() inside the if ().
--- drivers/pci/setup-bus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pci/setup-bus.c +1 -2
@@ -2504,8 +2504,7 @@ restore:restore_dev_resource (dev_res); - ret =pci_claim_resource (dev, i); -if (ret) +if (pci_claim_resource (dev, i))continue ;if (i <PCI_BRIDGE_RESOURCES ) {
Greg Kroah-Hartman
maintainerPATCH 1605/1611 PCI: Fix Resizable BAR restore order
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilpo Järvinen <[email protected]>
commit 5528fd38f230c906fcebb202cc94fbb8ed8f122a upstream.
The commit 337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path") changed BAR resize to layer rebar code and resource setup/restore code cleanly. Unfortunately, it did not consider how the value of the BAR Size field impacts the read-only bits in the Base Address Register (PCIe7 spec, sec. 7.8.6.3). That is, it very much matters in which order the BAR Size and Base Address Register are restored.
Post-337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path") during BAR resize rollback, pci_do_resource_release_and_resize() attempts to restore the old address to the BAR that was resized, but it can fail to setup the address correctly if the address has low bits set that collide with the bits that are still read-only. As a result, kernel's resource and BAR will be out-of-sync.
Fix this by restoring BAR Size before rolling back the resource changes and restoring the BAR.
--- drivers/pci/rebar.c | 18 +----------------- drivers/pci/setup-bus.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 19 deletions(-)
drivers/pci/rebar.c +1 -17
@@ -215,7 +215,6 @@ int pci_resize_resource(struct pci_dev * int exclude_bars) {struct pci_host_bridge *host; -int old, ret;u32 sizes;/* Check if we must preserve the firmware's resource assignment */
@@ -233,21 +232,6 @@ int pci_resize_resource(struct pci_dev *if (!(sizes &BIT (size)))return -EINVAL ; - old =pci_rebar_get_current_size (dev, resno); -if (old <0 ) -return old; - - ret =pci_rebar_set_size (dev, resno, size); -if (ret) -return ret; - - ret =pci_do_resource_release_and_resize (dev, resno, size, exclude_bars); -if (ret) - goto error_resize; -return 0 ; - -error_resize: -pci_rebar_set_size (dev, resno, old); -return ret; +return pci_do_resource_release_and_resize (dev, resno, size, exclude_bars); }EXPORT_SYMBOL (pci_resize_resource);
drivers/pci/setup-bus.c +18 -2
@@ -2452,12 +2452,20 @@ int pci_do_resource_release_and_resize(sstruct resource *b_win, *r;LIST_HEAD (saved);unsigned int i; -int ret =0 ; +int old, ret; b_win =pbus_select_window (bus, res);if (!b_win)return -EINVAL ; + old =pci_rebar_get_current_size (pdev, resno); +if (old <0 ) +return old; + + ret =pci_rebar_set_size (pdev, resno, size); +if (ret) +return ret; +pci_dev_for_each_resource (pdev, r, i) {if (i >=PCI_BRIDGE_RESOURCES )break ;
@@ -2490,7 +2498,15 @@ out:return ret; restore: -/* Revert to the old configuration */ +/* +* Revert to the old configuration. +* +* BAR Size must be restored first because it affects the read-only +* bits in BAR (the old address might not be restorable otherwise +* due to low address bits). +*/ +pci_rebar_set_size (pdev, resno, old); +list_for_each_entry (dev_res, &saved, list) {struct resource *res = dev_res->res;struct pci_dev *dev = dev_res->dev;
Greg Kroah-Hartman
maintainerPATCH 1606/1611 perf inject: With --convert-callchain ignore the dummy event for dwarf stacks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
commit e786a04b4a5461dd7e2829422314a5a6d5a664d9 upstream.
On hybrid systems there is generally >1 event and a dummy event.
The perf inject --convert-callchain option is failing to convert perf.data files on such systems reporting "--convert-callchain requires DWARF call graph."
The failing event is the dummy event that doesn't need to be set up for samples.
As such ignore this event when checking the evsels.
--- tools/perf/builtin-inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-inject.c +1 -1
@@ -2862,7 +2862,7 @@ int cmd_inject(int argc, const char **ar }evlist__for_each_entry (inject.session->evlist, evsel) { -if (!evsel__has_dwarf_callchain (evsel)) { +if (!evsel__has_dwarf_callchain (evsel) && !evsel__is_dummy_event (evsel)) {pr_err ("--convert-callchain requires DWARF call graph.\n" ); goto out_delete; }
Greg Kroah-Hartman
maintainerPATCH 1607/1611 seqlock: fix scoped_seqlock_read kernel-doc
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Randy Dunlap <[email protected]>
commit f88a31308db6a856229150039b0f56d59696ed31 upstream.
Eliminate all kernel-doc warnings in seqlock.h:
- correct the macro to have "()" immediately following the macro name
- don't include the macro parameters in the short description (first line)
- make the parameter names in the comments match the actual macro parameter names.
- use "::" for the Example
WARNING: include/linux/seqlock.h:1341 This comment starts with '/**', but isn't a kernel-doc comment. * scoped_seqlock_read (lock, ss_state) - execute the read side critical
Documentation/locking/seqlock:242: include/linux/seqlock.h:1351: WARNING:
Definition list ends without a blank line; unexpected unindent. [docutils]
Warning: include/linux/seqlock.h:1357 function parameter '_seqlock' not described in 'scoped_seqlock_read'
Warning: include/linux/seqlock.h:1357 function parameter '_target' not described in 'scoped_seqlock_read'
--- include/linux/seqlock.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
include/linux/seqlock.h +7 -8
@@ -1300,15 +1300,14 @@ __scoped_seqlock_next(struct ss_tmp *sst __scoped_seqlock_next(&_s, _seqlock, _target))/** -* scoped_seqlock_read (lock, ss_state) - execute the read side critical -* section without manual sequence -* counter handling or calls to other -* helpers -* @lock: pointer to seqlock_t protecting the data -* @ss_state: one of {ss_lock, ss_lock_irqsave, ss_lockless} indicating -* the type of critical read section +* scoped_seqlock_read() - execute the read-side critical section +* without manual sequence counter handling +* or calls to other helpers +* @_seqlock: pointer to seqlock_t protecting the data +* @_target: an enum ss_state: one of {ss_lock, ss_lock_irqsave, ss_lockless} +* indicating the type of critical read section * -* Example: +* Example:: * * scoped_seqlock_read (&lock, ss_lock) { * // read-side critical section
Greg Kroah-Hartman
maintainerPATCH 1608/1611 perf callchain: Handle multiple address spaces
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Richter <[email protected]>
commit ae15db3e9b639491007cc1e9e99638e4b6091781 upstream.
perf test 'perf inject to convert DWARF callchains to regular ones' fails on s390. It was introduced with commit 92ea788d2af4e65a ("perf
inject: Add --convert-callchain option")
The failure comes the difference in output. Without the inject script to convert DWARF the callchains is:
# perf record -F 999 --call-graph dwarf -- perf test -w noploop
# perf report -i perf.data --stdio --no-children -q \
--percent-limit=1 > /tmp/111
# cat /tmp/111
99.30% perf-noploop perf [.] noploop
|
---noploop
run_workload (inlined)
cmd_test
run_builtin (inlined)
handle_internal_command
run_argv (inlined)
main
__libc_start_call_main
__libc_start_main_impl (inlined)
_start
#With the inject script step the output is:
# perf inject -i perf.data --convert-callchain -o /tmp/perf-inject-1.out
# perf report -i /tmp/perf-inject-1.out --stdio --no-children -q \
--percent-limit=1 > /tmp/222
# cat /tmp/222
99.40% perf-noploop perf [.] noploop
|
---noploop
run_workload (inlined)
cmd_test
run_builtin (inlined)
handle_internal_command
run_argv (inlined)
main
_start
# diff /tmp/111 /tmp/222
1c1
< 99.30% perf-noploop perf [.] noploop
---Quoted 1 line
99.40% perf-noploop perf [.] noploop
10,11d9
< __libc_start_call_main
< __libc_start_main_impl (inlined)
#
The difference are the symbols __libc_start_call_main and __libc_start_main_impl.
On x86_64, kernel and user space share a single virtual address space, with the kernel mapped to the upper end of memory. The instruction pointer value alone is sufficient to distinguish between user space and kernel space addresses.
This is not true for s390, which uses separate address spaces for user and kernel.
The same virtual address can be valid in both address spaces, so the instruction pointer value alone cannot determine whether an address belongs to the kernel or user space.
Instead, perf must rely on the cpumode metadata derived from the processor status word (PSW) at sample time.
In function perf_event__convert_sample_callchain() the first part copies a kernel callchain and context entries, if any.
It then appends additional entries ignoring the address space architecture. Taking that into account, the symbols at addresses
0x3ff970348cb __libc_start_call_main
0x3ff970349c5 __libc_start_main_impl
(located after the kernel address space on s390) are now included.
Output before:
# perf test 83 83: perf inject to convert DWARF callchains to regular ones : FAILED!
Output after:
# perf test 83 83: perf inject to convert DWARF callchains to regular ones : Ok
Question to Namhyung:
In function perf_event__convert_sample_callchain() just before the for() loop this patch modifies, the kernel callchain is copied, see this comment and the next 5 lines:
/* copy kernel callchain and context entries */
Then why is machine__kernel_ip() needed in the for() loop, when the kernel entries have been copied just before the loop?
Note: This patch was tested on x86_64 virtual machine and succeeded.
--- tools/perf/arch/common.c | 4 +++- tools/perf/builtin-inject.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
tools/perf/arch/common.c +3 -1
@@ -237,5 +237,7 @@ int perf_env__lookup_objdump(struct perf*/ bool perf_env__single_address_space (struct perf_env *env) { -return strcmp (perf_env__arch (env),"sparc" ); +const char *arch =perf_env__arch (env); + +return strcmp (arch,"s390" ) &&strcmp (arch,"sparc" ); }
tools/perf/builtin-inject.c +2 -1
@@ -555,7 +555,8 @@ static int perf_event__convert_sample_ca node = cursor->first;for (k =0 ; k < cursor->nr && i <PERF_MAX_STACK_DEPTH ; k++) { -if (machine__kernel_ip (machine, node->ip)) +if (machine->single_address_space && +machine__kernel_ip (machine, node->ip))/* kernel IPs were added already */ ;else if (node->ms.sym && node->ms.sym->inlined)/* we can't handle inlined callchains */ ;
Greg Kroah-Hartman
maintainerPATCH 1609/1611 ksmbd: fix durable reconnect double-bind race in ksmbd_reopen_durable_fd
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
commit 7ce4fc40018de07f05f3035241122d992610dbfb upstream.
Two concurrent same-user DHnC reconnects can both observe fp->conn == NULL before either sets it. ksmbd_reopen_durable_fd() checks fp->conn to guard against a handle already being reconnected, but the check and the binding assignment are not atomic: both threads pass the guard, both call ksmbd_conn_get() on the same fp, and both eventually reach kfree(fp->owner.name) -- a double-free of the owner.name slab object. The double-bound ksmbd_file also causes a write-UAF on the 344-byte ksmbd_file_cache object when a concurrent smb2_close() spins on fp->f_lock after the object has been freed by the losing reconnect path.
KASAN on 7.1-rc5 (48-thread concurrent reconnect, 3000 cycles):
BUG: KASAN: double-free in ksmbd_reopen_durable_fd+0x268/0x308
BUG: KASAN: slab-use-after-free in _raw_spin_lock+0xac/0x150
Write of size 4 at offset 24 into freed ksmbd_file_cache objectFive double-bind windows observed; 63 total KASAN reports triggered.
Fix: validate and claim fp->conn under write_lock(&global_ft.lock) so the check-and-claim is atomic. ksmbd_lookup_durable_fd() already treats fp->conn != NULL as "in use" and skips such an fp; setting fp->conn before dropping the lock closes the race. ksmbd_conn_get() is a non-sleeping refcount increment, safe under the rwlock. The rollback path on __open_id() failure also clears fp->conn/tcon under the lock so concurrent readers see a consistent state.
--- fs/smb/server/vfs_cache.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/smb/server/vfs_cache.c +9 -3
@@ -1185,19 +1185,19 @@ int ksmbd_reopen_durable_fd(struct ksmbdstruct ksmbd_lock *smb_lock;unsigned int old_f_state; +write_lock (&global_ft.lock);if (!fp->is_durable || fp->conn || fp->tcon) { +write_unlock (&global_ft.lock);pr_err ("Invalid durable fd [%p:%p]\n" , fp->conn, fp->tcon);return -EBADF ; }if (has_file_id (fp->volatile_id)) { +write_unlock (&global_ft.lock);pr_err ("Still in use durable fd: %llu\n" , fp->volatile_id);return -EBADF ; } - old_f_state = fp->f_state; - fp->f_state =FP_NEW ; -/* * Initialize fp's connection binding before publishing fp into the * session's file table. If __open_id() is ordered first, a
@@ -1208,11 +1208,17 @@ int ksmbd_reopen_durable_fd(struct ksmbd*/ fp->conn =ksmbd_conn_get (conn); fp->tcon = work->tcon; +write_unlock (&global_ft.lock); + + old_f_state = fp->f_state; + fp->f_state =FP_NEW ;__open_id (&work->sess->file_table, fp,OPEN_ID_TYPE_VOLATILE_ID );if (!has_file_id (fp->volatile_id)) { +write_lock (&global_ft.lock); fp->conn =NULL ; fp->tcon =NULL ; +write_unlock (&global_ft.lock);ksmbd_conn_put (conn); fp->f_state = old_f_state;return -EBADF ;
Greg Kroah-Hartman
maintainerPATCH 1610/1611 RDMA/bnxt_re: Initialize dpi variable to zero
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvin Xavier <[email protected]>
commit 978b27d6ce538bb832ccd69e45802824e4301c4b upstream.
dpi is initialized only for BNXT_RE_ALLOC_WC_PAGE, but copied for all the cases. So initialize the dpi to 0.
--- drivers/infiniband/hw/bnxt_re/uapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/bnxt_re/uapi.c +1 -1
@@ -76,8 +76,8 @@ static int UVERBS_HANDLER(BNXT_RE_METHODstruct ib_ucontext *ib_uctx;struct bnxt_re_dev *rdev;u64 mmap_offset; +u32 dpi =0 ;u32 length; -u32 dpi;u64 addr;int err;
Greg Kroah-Hartman
maintainerPATCH 1611/1611 RDMA/bnxt_re: Avoid repeated requests to allocate WC pages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvin Xavier <[email protected]>
commit 441baa79043431807115fd030d7d0bb14ed441a0 upstream.
Applications can request multiple WC pages for the same ucontext. As of now, only 1 WC page per ucontext is supported. Add a lock to avoid concurrent access and a check to fail repeated requests. Also, if the mmap entry insert fails for the WC, free the Doorbell page index mapped for the WC page.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 1 drivers/infiniband/hw/bnxt_re/ib_verbs.h | 1 drivers/infiniband/hw/bnxt_re/uapi.c | 33 +++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +1 -0
@@ -4356,6 +4356,7 @@ int bnxt_re_alloc_ucontext(struct ib_uco goto fail; }spin_lock_init (&uctx->sh_lock); +mutex_init (&uctx->wcdpi_lock); resp.comp_mask =BNXT_RE_UCNTX_CMASK_HAVE_CCTX ; chip_met_rev_num = rdev->chip_ctx->chip_num;
drivers/infiniband/hw/bnxt_re/ib_verbs.h +1 -0
@@ -142,6 +142,7 @@ struct bnxt_re_ucontext {struct bnxt_re_dev *rdev;struct bnxt_qplib_dpi dpi;struct bnxt_qplib_dpi wcdpi; +struct mutex wcdpi_lock;/* serialises WC DPI alloc/free */ void *shpg;spinlock_t sh_lock;/* protect shpg */ struct rdma_user_mmap_entry *shpage_mmap;
drivers/infiniband/hw/bnxt_re/uapi.c +27 -6
@@ -98,14 +98,23 @@ static int UVERBS_HANDLER(BNXT_RE_METHODswitch (alloc_type) {case BNXT_RE_ALLOC_WC_PAGE : -if (cctx->modes.db_push) { +if (cctx->modes.db_push) { +mutex_lock (&uctx->wcdpi_lock); +/* already allocated — one WC page per context */ +if (uctx->wcdpi.dbr) { +mutex_unlock (&uctx->wcdpi_lock); +return -EEXIST ; + }if (bnxt_qplib_alloc_dpi (&rdev->qplib_res, &uctx->wcdpi, - uctx,BNXT_QPLIB_DPI_TYPE_WC )) + uctx,BNXT_QPLIB_DPI_TYPE_WC )) { +mutex_unlock (&uctx->wcdpi_lock);return -ENOMEM ; + } length =PAGE_SIZE ; dpi = uctx->wcdpi.dpi; addr = (u64 )uctx->wcdpi.umdbr; mmap_flag =BNXT_RE_MMAP_WC_DB ; +mutex_unlock (&uctx->wcdpi_lock); }else {return -EINVAL ; }
@@ -132,8 +141,15 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD } entry =bnxt_re_mmap_entry_insert (uctx, addr, mmap_flag, &mmap_offset); -if (!entry) +if (!entry) { +if (mmap_flag ==BNXT_RE_MMAP_WC_DB ) { +mutex_lock (&uctx->wcdpi_lock); +bnxt_qplib_dealloc_dpi (&rdev->qplib_res, &uctx->wcdpi); + uctx->wcdpi.dbr =NULL ; +mutex_unlock (&uctx->wcdpi_lock); + }return -ENOMEM ; + } uobj->object = entry;uverbs_finalize_uobj_create (attrs,BNXT_RE_ALLOC_PAGE_HANDLE );
@@ -164,11 +180,16 @@ static int alloc_page_obj_cleanup(structswitch (entry->mmap_flag) {case BNXT_RE_MMAP_WC_DB : -if (uctx && uctx->wcdpi.dbr) { +if (uctx) {struct bnxt_re_dev *rdev = uctx->rdev; -bnxt_qplib_dealloc_dpi (&rdev->qplib_res, &uctx->wcdpi); - uctx->wcdpi.dbr =NULL ; +mutex_lock (&uctx->wcdpi_lock); +if (uctx->wcdpi.dbr) { +bnxt_qplib_dealloc_dpi (&rdev->qplib_res, + &uctx->wcdpi); + uctx->wcdpi.dbr =NULL ; + } +mutex_unlock (&uctx->wcdpi_lock); }break ;case BNXT_RE_MMAP_DBR_BAR :
# Librecast Test Results
020/020 [ OK ] liblcrq
010/010 [ OK ] libmld
120/120 [ OK ] liblibrecast
CPU/kernel: Linux auntie 6.18.40-rc1-g3c61aa5a7357 #1 SMP PREEMPT_DYNAMIC Tue Jul 21 20:39:58 -00 2026 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux
Am 21.07.2026 um 17:01 schrieb Greg Kroah-Hartman:
Quoted 4 lines
This is the start of the stable review cycle for the 6.18.40 release. There are 1611 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Builds, boots and works on my 2-socket Ivy Bridge Xeon E5-2697 v2 server. No dmesg oddities or regressions found.
Beste Grüße,
Peter Schneider
Signature · 8 lines
Climb the mountain not to plant your flag, but to embrace the challenge, enjoy the air and behold the view. Climb it so you can see the world, not so the world can see you. -- David McCullough Jr. OpenPGP: 0xA3828BD796CCE11A8CADE8866E3A92C92C3FF244 Download: https://www.peters-netzplatz.de/download/pschneider1968_pub.asc https://keys.mailvelope.com/pks/lookup?op=get&[email protected] https://keys.mailvelope.com/pks/lookup?op=get&[email protected]
Hi, so surprise here cycle has 1600+ patches :)
by the way, I see the lore maillist webui are fold when i see >999 sub mail:
2026-07-21 15:18 ` [PATCH 6.18 0999/1611] afs: Fix error code in afs_extract_vl_addrs() Greg Kroah-Hartman -> here dissappered. Reply instructions:
Build tested in our x86,arm64,loongarch,riscv config successfully without error.
BRs
Wentao Guan
defconfigs:
https://gist.github.com/opsiff/a840ae9e3d6857f5b7bacb9cdc49f8e9
Log:
Linux version 6.18.40-rc1-g3c61aa5a7357 (guanwentao@uos-PC) (aarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP PREEMPT_DYNAMIC Linux version 6.18.40-rc1-g3c61aa5a7357 (guanwentao@uos-PC) (aarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #2 SMP PREEMPT_DYNAMIC Wed Jul 22 12:14:33 CST 2026 Linux version 6.18.40-rc1-g3c61aa5a7357 (guanwentao@uos-PC) (loongarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP PREEMPT_DYNAMIC Linux version 6.18.40-rc1-g3c61aa5a7357 (guanwentao@uos-PC) (loongarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #3 SMP PREEMPT_DYNAMIC Wed Jul 22 12:32:34 CST 2026 Linux version 6.18.40-rc1+ (guanwentao@uos-PC) (riscv64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP PREEMPT
Linux version 6.18.40-rc1+ (guanwentao@uos-PC) (riscv64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #4 SMP PREEMPT Wed Jul 22 12:50:26 CST 2026 Linux version 6.18.40-rc1-g3c61aa5a7357 (guanwentao@uos-PC) (gcc (Deepin 12.3.0-17deepin15) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP PREEMPT_DYNAMIC
Linux version 6.18.40-rc1-g3c61aa5a7357 (guanwentao@uos-PC) (gcc (Deepin 12.3.0-17deepin15) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #1 SMP PREEMPT_DYNAMIC Wed Jul 22 11:53:08 CST 2026
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.18.40 release. There are 1611 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 23 Jul 2026 15:23:00 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.18.40-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.18.y
and the diffstat can be found below.thanks,
greg k-h
Built and booted successfully on RISC-V RV64 (HiFive Unmatched).
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.18.40 release. There are 1611 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 23 Jul 2026 15:23:00 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.18.40-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.18.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 6.18.40 release. There are 1611 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-6.18.y
Best regards,
Pavel