6.1.141-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 288/325 af_unix: Allocate struct unix_vertex for each inflight AF_UNIX fd.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 1fbfdfaa590248c1d86407f578e40e5c65136330 upstream.
We will replace the garbage collection algorithm for AF_UNIX, where we will consider each inflight AF_UNIX socket as a vertex and its file descriptor as an edge in a directed graph.
This patch introduces a new struct unix_vertex representing a vertex in the graph and adds its pointer to struct unix_sock.
When we send a fd using the SCM_RIGHTS message, we allocate struct scm_fp_list to struct scm_cookie in scm_fp_copy(). Then, we bump each refcount of the inflight fds' struct file and save them in scm_fp_list.fp.
After that, unix_attach_fds() inexplicably clones scm_fp_list of scm_cookie and sets it to skb. (We will remove this part after replacing GC.)
Here, we add a new function call in unix_attach_fds() to preallocate struct unix_vertex per inflight AF_UNIX fd and link each vertex to skb's scm_fp_list.vertices.
When sendmsg() succeeds later, if the socket of the inflight fd is still not inflight yet, we will set the preallocated vertex to struct unix_sock.vertex and link it to a global list unix_unvisited_vertices under spin_lock(&unix_gc_lock).
If the socket is already inflight, we free the preallocated vertex. This is to avoid taking the lock unnecessarily when sendmsg() could fail later.
In the following patch, we will similarly allocate another struct per edge, which will finally be linked to the inflight socket's unix_vertex.edges.
And then, we will count the number of edges as unix_vertex.out_degree.
--- include/net/af_unix.h | 9 +++++++++ include/net/scm.h | 3 +++ net/core/scm.c | 7 +++++++ net/unix/af_unix.c | 6 ++++++ net/unix/garbage.c | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+)
include/net/af_unix.h +9 -0
@@ -22,9 +22,17 @@ extern unsigned int unix_tot_inflight;void unix_inflight (struct user_struct *user,struct file *fp);void unix_notinflight (struct user_struct *user,struct file *fp); +int unix_prepare_fpl (struct scm_fp_list *fpl); +void unix_destroy_fpl (struct scm_fp_list *fpl);void unix_gc (void );void wait_for_unix_gc (struct scm_fp_list *fpl); +struct unix_vertex { +struct list_head edges; +struct list_head entry; +unsigned long out_degree; +}; +struct sock *unix_peer_get (struct sock *sk);#define UNIX_HASH_MOD (256 - 1)
@@ -62,6 +70,7 @@ struct unix_sock {struct path path;struct mutex iolock, bindlock;struct sock *peer; +struct unix_vertex *vertex;struct list_head link;unsigned long inflight;spinlock_t lock;
include/net/scm.h +3 -0
@@ -25,6 +25,9 @@ struct scm_fp_list {short count;short count_unix;short max; +#ifdef CONFIG_UNIX +struct list_head vertices; +#endif struct user_struct *user;struct file *fp[SCM_MAX_FD ]; };
net/core/scm.c +7 -0
@@ -89,6 +89,9 @@ static int scm_fp_copy(struct cmsghdr *c fpl->count_unix =0 ; fpl->max =SCM_MAX_FD ; fpl->user =NULL ; +#if IS_ENABLED (CONFIG_UNIX ) +INIT_LIST_HEAD (&fpl->vertices); +#endif } fpp = &fpl->fp[fpl->count];
@@ -372,8 +375,12 @@ struct scm_fp_list *scm_fp_dup(struct scif (new_fpl) {for (i =0 ; i < fpl->count; i++)get_file (fpl->fp[i]); + new_fpl->max = new_fpl->count; new_fpl->user =get_uid (fpl->user); +#if IS_ENABLED (CONFIG_UNIX ) +INIT_LIST_HEAD (&new_fpl->vertices); +#endif }return new_fpl; }
net/unix/af_unix.c +6 -0
@@ -955,6 +955,7 @@ static struct sock *unix_create1(struct sk->sk_destruct = unix_sock_destructor; u =unix_sk (sk); u->inflight =0 ; + u->vertex =NULL ; u->path.dentry =NULL ; u->path.mnt =NULL ;spin_lock_init (&u->lock);
@@ -1756,6 +1757,9 @@ static int unix_attach_fds(struct scm_cofor (i = scm->fp->count -1 ; i >=0 ; i--)unix_inflight (scm->fp->user, scm->fp->fp[i]); +if (unix_prepare_fpl (UNIXCB (skb).fp)) +return -ENOMEM ; +return 0 ; }
@@ -1766,6 +1770,8 @@ static void unix_detach_fds(struct scm_c scm->fp =UNIXCB (skb).fp;UNIXCB (skb).fp =NULL ; +unix_destroy_fpl (scm->fp); +for (i = scm->fp->count -1 ; i >=0 ; i--)unix_notinflight (scm->fp->user, scm->fp->fp[i]); }
net/unix/garbage.c +38 -0
@@ -101,6 +101,44 @@ struct unix_sock *unix_get_socket(structreturn NULL ; } +static void unix_free_vertices (struct scm_fp_list *fpl) +{ +struct unix_vertex *vertex, *next_vertex; + +list_for_each_entry_safe (vertex, next_vertex, &fpl->vertices, entry) { +list_del (&vertex->entry); +kfree (vertex); + } +} + +int unix_prepare_fpl (struct scm_fp_list *fpl) +{ +struct unix_vertex *vertex; +int i; + +if (!fpl->count_unix) +return 0 ; + +for (i =0 ; i < fpl->count_unix; i++) { + vertex =kmalloc (sizeof (*vertex),GFP_KERNEL ); +if (!vertex) + goto err; + +list_add (&vertex->entry, &fpl->vertices); + } + +return 0 ; + +err: +unix_free_vertices (fpl); +return -ENOMEM ; +} + +void unix_destroy_fpl (struct scm_fp_list *fpl) +{ +unix_free_vertices (fpl); +} +DEFINE_SPINLOCK (unix_gc_lock);unsigned int unix_tot_inflight;static LIST_HEAD (gc_candidates);
Greg Kroah-Hartman
maintainerPATCH 289/325 af_unix: Allocate struct unix_edge for each inflight AF_UNIX fd.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 29b64e354029cfcf1eea4d91b146c7b769305930 upstream.
As with the previous patch, we preallocate to skb's scm_fp_list an array of struct unix_edge in the number of inflight AF_UNIX fds.
There we just preallocate memory and do not use immediately because sendmsg() could fail after this point. The actual use will be in the next patch.
When we queue skb with inflight edges, we will set the inflight socket's unix_sock as unix_edge->predecessor and the receiver's unix_sock as successor, and then we will link the edge to the inflight socket's unix_vertex.edges.
Note that we set NULL to cloned scm_fp_list.edges in scm_fp_dup() so that MSG_PEEK does not change the shape of the directed graph.
--- include/net/af_unix.h | 6 ++++++ include/net/scm.h | 5 +++++ net/core/scm.c | 2 ++ net/unix/garbage.c | 6 ++++++ 4 files changed, 19 insertions(+)
include/net/af_unix.h +6 -0
@@ -33,6 +33,12 @@ struct unix_vertex {unsigned long out_degree; }; +struct unix_edge { +struct unix_sock *predecessor; +struct unix_sock *successor; +struct list_head vertex_entry; +}; +struct sock *unix_peer_get (struct sock *sk);#define UNIX_HASH_MOD (256 - 1)
include/net/scm.h +5 -0
@@ -21,12 +21,17 @@ struct scm_creds {kgid_t gid; }; +#ifdef CONFIG_UNIX +struct unix_edge ; +#endif +struct scm_fp_list {short count;short count_unix;short max;#ifdef CONFIG_UNIX struct list_head vertices; +struct unix_edge *edges;#endif struct user_struct *user;struct file *fp[SCM_MAX_FD ];
net/core/scm.c +2 -0
@@ -90,6 +90,7 @@ static int scm_fp_copy(struct cmsghdr *c fpl->max =SCM_MAX_FD ; fpl->user =NULL ;#if IS_ENABLED (CONFIG_UNIX ) + fpl->edges =NULL ;INIT_LIST_HEAD (&fpl->vertices);#endif }
@@ -379,6 +380,7 @@ struct scm_fp_list *scm_fp_dup(struct sc new_fpl->max = new_fpl->count; new_fpl->user =get_uid (fpl->user);#if IS_ENABLED (CONFIG_UNIX ) + new_fpl->edges =NULL ;INIT_LIST_HEAD (&new_fpl->vertices);#endif }
net/unix/garbage.c +6 -0
@@ -127,6 +127,11 @@ int unix_prepare_fpl(struct scm_fp_listlist_add (&vertex->entry, &fpl->vertices); } + fpl->edges =kvmalloc_array (fpl->count_unix,sizeof (*fpl->edges), +GFP_KERNEL_ACCOUNT ); +if (!fpl->edges) + goto err; +return 0 ; err:
@@ -136,6 +141,7 @@ err:void unix_destroy_fpl (struct scm_fp_list *fpl) { +kvfree (fpl->edges);unix_free_vertices (fpl); }
Greg Kroah-Hartman
maintainerPATCH 290/325 af_unix: Link struct unix_edge when queuing skb.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 42f298c06b30bfe0a8cbee5d38644e618699e26e upstream.
Just before queuing skb with inflight fds, we call scm_stat_add(), which is a good place to set up the preallocated struct unix_vertex and struct unix_edge in UNIXCB(skb).fp.
Then, we call unix_add_edges() and construct the directed graph as follows:
1. Set the inflight socket's unix_sock to unix_edge.predecessor.
2. Set the receiver's unix_sock to unix_edge.successor.
3. Set the preallocated vertex to inflight socket's unix_sock.vertex.
4. Link inflight socket's unix_vertex.entry to unix_unvisited_vertices.
5. Link unix_edge.vertex_entry to the inflight socket's unix_vertex.edges.
Let's say we pass the fd of AF_UNIX socket A to B and the fd of B to C. The graph looks like this:
+-------------------------+
| unix_unvisited_vertices | <-------------------------.
+-------------------------+ |
+ |
| +--------------+ +--------------+ | +--------------+
| | unix_sock A | <---. .---> | unix_sock B | <-|-. .---> | unix_sock C |
| +--------------+ | | +--------------+ | | | +--------------+
| .-+ | vertex | | | .-+ | vertex | | | | | vertex |
| | +--------------+ | | | +--------------+ | | | +--------------+
| | | | | | | |
| | +--------------+ | | | +--------------+ | | |
| '-> | unix_vertex | | | '-> | unix_vertex | | | |
| +--------------+ | | +--------------+ | | |
`---> | entry | +---------> | entry | +-' | |
|--------------| | | |--------------| | |
| edges | <-. | | | edges | <-. | |
+--------------+ | | | +--------------+ | | |
| | | | | |
.----------------------' | | .----------------------' | |
| | | | | |
| +--------------+ | | | +--------------+ | |
| | unix_edge | | | | | unix_edge | | |
| +--------------+ | | | +--------------+ | |
`-> | vertex_entry | | | `-> | vertex_entry | | |
|--------------| | | |--------------| | |
| predecessor | +---' | | predecessor | +---' |
|--------------| | |--------------| |
| successor | +-----' | successor | +-----'
+--------------+ +--------------+Henceforth, we denote such a graph as A -> B (-> C).
Now, we can express all inflight fd graphs that do not contain embryo sockets. We will support the particular case later.
--- include/net/af_unix.h | 2 + include/net/scm.h | 1 net/core/scm.c | 2 + net/unix/af_unix.c | 8 +++- net/unix/garbage.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 100 insertions(+), 3 deletions(-)
include/net/af_unix.h +2 -0
@@ -22,6 +22,8 @@ extern unsigned int unix_tot_inflight;void unix_inflight (struct user_struct *user,struct file *fp);void unix_notinflight (struct user_struct *user,struct file *fp); +void unix_add_edges (struct scm_fp_list *fpl,struct unix_sock *receiver); +void unix_del_edges (struct scm_fp_list *fpl);int unix_prepare_fpl (struct scm_fp_list *fpl);void unix_destroy_fpl (struct scm_fp_list *fpl);void unix_gc (void );
include/net/scm.h +1 -0
@@ -30,6 +30,7 @@ struct scm_fp_list {short count_unix;short max;#ifdef CONFIG_UNIX +bool inflight;struct list_head vertices;struct unix_edge *edges;#endif
net/core/scm.c +2 -0
@@ -90,6 +90,7 @@ static int scm_fp_copy(struct cmsghdr *c fpl->max =SCM_MAX_FD ; fpl->user =NULL ;#if IS_ENABLED (CONFIG_UNIX ) + fpl->inflight = false; fpl->edges =NULL ;INIT_LIST_HEAD (&fpl->vertices);#endif
@@ -380,6 +381,7 @@ struct scm_fp_list *scm_fp_dup(struct sc new_fpl->max = new_fpl->count; new_fpl->user =get_uid (fpl->user);#if IS_ENABLED (CONFIG_UNIX ) + new_fpl->inflight = false; new_fpl->edges =NULL ;INIT_LIST_HEAD (&new_fpl->vertices);#endif
net/unix/af_unix.c +6 -2
@@ -1910,8 +1910,10 @@ static void scm_stat_add(struct sock *skstruct scm_fp_list *fp =UNIXCB (skb).fp;struct unix_sock *u =unix_sk (sk); -if (unlikely (fp && fp->count)) +if (unlikely (fp && fp->count)) {atomic_add (fp->count, &u->scm_stat.nr_fds); +unix_add_edges (fp, u); + } }static void scm_stat_del (struct sock *sk,struct sk_buff *skb)
@@ -1919,8 +1921,10 @@ static void scm_stat_del(struct sock *skstruct scm_fp_list *fp =UNIXCB (skb).fp;struct unix_sock *u =unix_sk (sk); -if (unlikely (fp && fp->count)) +if (unlikely (fp && fp->count)) {atomic_sub (fp->count, &u->scm_stat.nr_fds); +unix_del_edges (fp); + } }/*
net/unix/garbage.c +89 -1
112 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 291/325 af_unix: Bulk update unix_tot_inflight/unix_inflight when queuing skb.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 22c3c0c52d32f41cc38cd936ea0c93f22ced3315 upstream.
Currently, we track the number of inflight sockets in two variables. unix_tot_inflight is the total number of inflight AF_UNIX sockets on the host, and user->unix_inflight is the number of inflight fds per user.
We update them one by one in unix_inflight(), which can be done once in batch. Also, sendmsg() could fail even after unix_inflight(), then we need to acquire unix_gc_lock only to decrement the counters.
Let's bulk update the counters in unix_add_edges() and unix_del_edges(), which is called only for successfully passed fds.
--- net/unix/garbage.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
net/unix/garbage.c +7 -11
@@ -144,6 +144,7 @@ static void unix_free_vertices(struct sc }DEFINE_SPINLOCK (unix_gc_lock); +unsigned int unix_tot_inflight;void unix_add_edges (struct scm_fp_list *fpl,struct unix_sock *receiver) {
@@ -168,7 +169,10 @@ void unix_add_edges(struct scm_fp_list *unix_add_edge (fpl, edge); }while (i < fpl->count_unix); +WRITE_ONCE (unix_tot_inflight, unix_tot_inflight + fpl->count_unix); out: +WRITE_ONCE (fpl->user->unix_inflight, fpl->user->unix_inflight + fpl->count); +spin_unlock (&unix_gc_lock); fpl->inflight = true;
@@ -191,7 +195,10 @@ void unix_del_edges(struct scm_fp_list *unix_del_edge (fpl, edge); }while (i < fpl->count_unix); +WRITE_ONCE (unix_tot_inflight, unix_tot_inflight - fpl->count_unix); out: +WRITE_ONCE (fpl->user->unix_inflight, fpl->user->unix_inflight - fpl->count); +spin_unlock (&unix_gc_lock); fpl->inflight = false;
@@ -234,7 +241,6 @@ void unix_destroy_fpl(struct scm_fp_listunix_free_vertices (fpl); } -unsigned int unix_tot_inflight;static LIST_HEAD (gc_candidates);static LIST_HEAD (gc_inflight_list);
@@ -255,13 +261,8 @@ void unix_inflight(struct user_struct *uWARN_ON_ONCE (list_empty (&u->link)); } u->inflight++; - -/* Paired with READ_ONCE() in wait_for_unix_gc() */ -WRITE_ONCE (unix_tot_inflight, unix_tot_inflight +1 ); } -WRITE_ONCE (user->unix_inflight, user->unix_inflight +1 ); -spin_unlock (&unix_gc_lock); }
@@ -278,13 +279,8 @@ void unix_notinflight(struct user_struct u->inflight--;if (!u->inflight)list_del_init (&u->link); - -/* Paired with READ_ONCE() in wait_for_unix_gc() */ -WRITE_ONCE (unix_tot_inflight, unix_tot_inflight -1 ); } -WRITE_ONCE (user->unix_inflight, user->unix_inflight -1 ); -spin_unlock (&unix_gc_lock); }
Greg Kroah-Hartman
maintainerPATCH 292/325 af_unix: Iterate all vertices by DFS.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 6ba76fd2848e107594ea4f03b737230f74bc23ea upstream.
The new GC will use a depth first search graph algorithm to find cyclic references. The algorithm visits every vertex exactly once.
Here, we implement the DFS part without recursion so that no one can abuse it.
unix_walk_scc() marks every vertex unvisited by initialising index as UNIX_VERTEX_INDEX_UNVISITED and iterates inflight vertices in unix_unvisited_vertices and call __unix_walk_scc() to start DFS from an arbitrary vertex.
__unix_walk_scc() iterates all edges starting from the vertex and explores the neighbour vertices with DFS using edge_stack.
After visiting all neighbours, __unix_walk_scc() moves the visited vertex to unix_visited_vertices so that unix_walk_scc() will not restart DFS from the visited vertex.
--- include/net/af_unix.h | 2 + net/unix/garbage.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
include/net/af_unix.h +2 -0
@@ -33,12 +33,14 @@ struct unix_vertex {struct list_head edges;struct list_head entry;unsigned long out_degree; +unsigned long index; };struct unix_edge {struct unix_sock *predecessor;struct unix_sock *successor;struct list_head vertex_entry; +struct list_head stack_entry; };struct sock *unix_peer_get (struct sock *sk);
net/unix/garbage.c +74 -0
92 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 293/325 af_unix: Detect Strongly Connected Components.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 3484f063172dd88776b062046d721d7c2ae1af7c upstream.
In the new GC, we use a simple graph algorithm, Tarjan's Strongly Connected Components (SCC) algorithm, to find cyclic references.
The algorithm visits every vertex exactly once using depth-first search (DFS).
DFS starts by pushing an input vertex to a stack and assigning it a unique number. Two fields, index and lowlink, are initialised with the number, but lowlink could be updated later during DFS.
If a vertex has an edge to an unvisited inflight vertex, we visit it and do the same processing. So, we will have vertices in the stack in the order they appear and number them consecutively in the same order.
If a vertex has a back-edge to a visited vertex in the stack, we update the predecessor's lowlink with the successor's index.
After iterating edges from the vertex, we check if its index equals its lowlink.
If the lowlink is different from the index, it shows there was a back-edge. Then, we go backtracking and propagate the lowlink to its predecessor and resume the previous edge iteration from the next edge.
If the lowlink is the same as the index, we pop vertices before and including the vertex from the stack. Then, the set of vertices is SCC, possibly forming a cycle. At the same time, we move the vertices to unix_visited_vertices.
When we finish the algorithm, all vertices in each SCC will be linked via unix_vertex.scc_entry.
Let's take an example. We have a graph including five inflight vertices (F is not inflight):
A -> B -> C -> D -> E (-> F)
^ |
`---------'Suppose that we start DFS from C. We will visit C, D, and B first and initialise their index and lowlink. Then, the stack looks like this:
Quoted 1 line
B = (3, 3) (index, lowlink)
D = (2, 2)
C = (1, 1)When checking B's edge to C, we update B's lowlink with C's index and propagate it to D.
B = (3, 1) (index, lowlink)
Quoted 1 line
D = (2, 1)
C = (1, 1)
Next, we visit E, which has no edge to an inflight vertex.
Quoted 1 line
E = (4, 4) (index, lowlink)
B = (3, 1)
D = (2, 1)
C = (1, 1)When we leave from E, its index and lowlink are the same, so we pop E from the stack as single-vertex SCC. Next, we leave from B and D but do nothing because their lowlink are different from their index.
B = (3, 1) (index, lowlink)
D = (2, 1)Quoted 1 line
C = (1, 1)
Then, we leave from C, whose index and lowlink are the same, so we pop B, D and C as SCC.
Last, we do DFS for the rest of vertices, A, which is also a single-vertex SCC.
Finally, each unix_vertex.scc_entry is linked as follows:
A -. B -> C -> D E -. ^ | ^ | ^ | `--' `---------' `--'
We use SCC later to decide whether we can garbage-collect the sockets.
Note that we still cannot detect SCC properly if an edge points to an embryo socket. The following two patches will sort it out.
--- include/net/af_unix.h | 3 +++ net/unix/garbage.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-)
include/net/af_unix.h +3 -0
@@ -32,8 +32,11 @@ void wait_for_unix_gc(struct scm_fp_liststruct unix_vertex {struct list_head edges;struct list_head entry; +struct list_head scc_entry;unsigned long out_degree;unsigned long index; +unsigned long lowlink; +bool on_stack; };struct unix_edge {
net/unix/garbage.c +44 -2
67 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 294/325 af_unix: Save listener for embryo socket.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit aed6ecef55d70de3762ce41c561b7f547dbaf107 upstream.
This is a prep patch for the following change, where we need to fetch the listening socket from the successor embryo socket during GC.
We add a new field to struct unix_sock to save a pointer to a listening socket.
We set it when connect() creates a new socket, and clear it when accept() is called.
--- include/net/af_unix.h | 1 + net/unix/af_unix.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
include/net/af_unix.h +1 -0
@@ -83,6 +83,7 @@ struct unix_sock {struct path path;struct mutex iolock, bindlock;struct sock *peer; +struct sock *listener;struct unix_vertex *vertex;struct list_head link;unsigned long inflight;
net/unix/af_unix.c +4 -1
@@ -954,6 +954,7 @@ static struct sock *unix_create1(struct sk->sk_max_ack_backlog =READ_ONCE (net->unx.sysctl_max_dgram_qlen); sk->sk_destruct = unix_sock_destructor; u =unix_sk (sk); + u->listener =NULL ; u->inflight =0 ; u->vertex =NULL ; u->path.dentry =NULL ;
@@ -1558,6 +1559,7 @@ restart: newsk->sk_type = sk->sk_type;init_peercred (newsk); newu =unix_sk (newsk); + newu->listener = other;RCU_INIT_POINTER (newsk->sk_wq, &newu->peer_wq); otheru =unix_sk (other);
@@ -1651,8 +1653,8 @@ static int unix_accept(struct socket *so bool kern) {struct sock *sk = sock->sk; -struct sock *tsk;struct sk_buff *skb; +struct sock *tsk;int err; err = -EOPNOTSUPP ;
@@ -1677,6 +1679,7 @@ static int unix_accept(struct socket *so } tsk = skb->sk; +unix_sk (tsk)->listener =NULL ;skb_free_datagram (sk, skb);wake_up_interruptible (&unix_sk (sk)->peer_wait);
Greg Kroah-Hartman
maintainerPATCH 295/325 af_unix: Fix up unix_edge.successor for embryo socket.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit dcf70df2048d27c5d186f013f101a4aefd63aa41 upstream.
To garbage collect inflight AF_UNIX sockets, we must define the cyclic reference appropriately. This is a bit tricky if the loop consists of embryo sockets.
Suppose that the fd of AF_UNIX socket A is passed to D and the fd B to C and that C and D are embryo sockets of A and B, respectively. It may appear that there are two separate graphs, A (-> D) and B (-> C), but this is not correct.
A --. .-- B
X
C <-' `-> DNow, D holds A's refcount, and C has B's refcount, so unix_release() will never be called for A and B when we close() them. However, no one can call close() for D and C to free skbs holding refcounts of A and B because C/D is in A/B's receive queue, which should have been purged by unix_release() for A and B.
So, here's another type of cyclic reference. When a fd of an AF_UNIX socket is passed to an embryo socket, the reference is indirectly held by its parent listening socket.
.-> A .-> B | `- sk_receive_queue | `- sk_receive_queue | `- skb | `- skb | `- sk == C | `- sk == D | `- sk_receive_queue | `- sk_receive_queue
| - skb +---------' - skb +-.
| |
`---------------------------------------------------------'
Technically, the graph must be denoted as A <-> B instead of A (-> D) and B (-> C) to find such a cyclic reference without touching each socket's receive queue.
.-> A --. .-- B <-.
| X | == A <-> B
-- C <-' -> D --'
We apply this fixup during GC by fetching the real successor by unix_edge_successor().
When we call accept(), we clear unix_sock.listener under unix_gc_lock not to confuse GC.
--- include/net/af_unix.h | 1 + net/unix/af_unix.c | 2 +- net/unix/garbage.c | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-)
include/net/af_unix.h +1 -0
@@ -24,6 +24,7 @@ void unix_inflight(struct user_struct *uvoid unix_notinflight (struct user_struct *user,struct file *fp);void unix_add_edges (struct scm_fp_list *fpl,struct unix_sock *receiver);void unix_del_edges (struct scm_fp_list *fpl); +void unix_update_edges (struct unix_sock *receiver);int unix_prepare_fpl (struct scm_fp_list *fpl);void unix_destroy_fpl (struct scm_fp_list *fpl);void unix_gc (void );
net/unix/af_unix.c +1 -1
@@ -1679,7 +1679,7 @@ static int unix_accept(struct socket *so } tsk = skb->sk; -unix_sk (tsk)->listener =NULL ; +unix_update_edges (unix_sk (tsk));skb_free_datagram (sk, skb);wake_up_interruptible (&unix_sk (sk)->peer_wait);
net/unix/garbage.c +19 -1
@@ -101,6 +101,17 @@ struct unix_sock *unix_get_socket(structreturn NULL ; } +static struct unix_vertex *unix_edge_successor (struct unix_edge *edge) +{ +/* If an embryo socket has a fd, +* the listener indirectly holds the fd's refcnt. +*/ +if (edge->successor->listener) +return unix_sk (edge->successor->listener)->vertex; + +return edge->successor->vertex; +} +static LIST_HEAD (unix_unvisited_vertices);enum unix_vertex_index {
@@ -209,6 +220,13 @@ out: fpl->inflight = false; } +void unix_update_edges (struct unix_sock *receiver) +{ +spin_lock (&unix_gc_lock); + receiver->listener =NULL ; +spin_unlock (&unix_gc_lock); +} +int unix_prepare_fpl (struct scm_fp_list *fpl) {struct unix_vertex *vertex;
@@ -268,7 +286,7 @@ next_vertex:/* Explore neighbour vertices (receivers of the current vertex's fd). */ list_for_each_entry (edge, &vertex->edges, vertex_entry) { -struct unix_vertex *next_vertex = edge->successor->vertex; +struct unix_vertex *next_vertex =unix_edge_successor (edge);if (!next_vertex)continue ;
Greg Kroah-Hartman
maintainerPATCH 296/325 af_unix: Save O(n) setup of Tarjans algo.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit ba31b4a4e1018f5844c6eb31734976e2184f2f9a upstream.
Before starting Tarjan's algorithm, we need to mark all vertices as unvisited. We can save this O(n) setup by reserving two special indices (0, 1) and using two variables.
The first time we link a vertex to unix_unvisited_vertices, we set unix_vertex_unvisited_index to index.
During DFS, we can see that the index of unvisited vertices is the same as unix_vertex_unvisited_index.
When we finalise SCC later, we set unix_vertex_grouped_index to each vertex's index.
Then, we can know (i) that the vertex is on the stack if the index of a visited vertex is >= 2 and (ii) that it is not on the stack and belongs to a different SCC if the index is unix_vertex_grouped_index.
After the whole algorithm, all indices of vertices are set as unix_vertex_grouped_index.
Next time we start DFS, we know that all unvisited vertices have unix_vertex_grouped_index, and we can use unix_vertex_unvisited_index as the not-on-stack marker.
To use the same variable in __unix_walk_scc(), we can swap unix_vertex_(grouped|unvisited)_index at the end of Tarjan's algorithm.
--- include/net/af_unix.h | 1 - net/unix/garbage.c | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-)
include/net/af_unix.h +0 -1
@@ -37,7 +37,6 @@ struct unix_vertex {unsigned long out_degree;unsigned long index;unsigned long lowlink; -bool on_stack; };struct unix_edge {
net/unix/garbage.c +15 -11
@@ -115,16 +115,20 @@ static struct unix_vertex *unix_edge_sucstatic LIST_HEAD (unix_unvisited_vertices);enum unix_vertex_index { -UNIX_VERTEX_INDEX_UNVISITED , +UNIX_VERTEX_INDEX_MARK1 , +UNIX_VERTEX_INDEX_MARK2 ,UNIX_VERTEX_INDEX_START , }; +static unsigned long unix_vertex_unvisited_index =UNIX_VERTEX_INDEX_MARK1 ; +static void unix_add_edge (struct scm_fp_list *fpl,struct unix_edge *edge) {struct unix_vertex *vertex = edge->predecessor->vertex;if (!vertex) { vertex =list_first_entry (&fpl->vertices,typeof (*vertex), entry); + vertex->index = unix_vertex_unvisited_index; vertex->out_degree =0 ;INIT_LIST_HEAD (&vertex->edges);
@@ -265,6 +269,7 @@ void unix_destroy_fpl(struct scm_fp_list }static LIST_HEAD (unix_visited_vertices); +static unsigned long unix_vertex_grouped_index =UNIX_VERTEX_INDEX_MARK2 ;static void __unix_walk_scc (struct unix_vertex *vertex) {
@@ -274,10 +279,10 @@ static void __unix_walk_scc(struct unix_LIST_HEAD (edge_stack); next_vertex: -/* Push vertex to vertex_stack. +/* Push vertex to vertex_stack and mark it as on-stack +* (index >= UNIX_VERTEX_INDEX_START). * The vertex will be popped when finalising SCC later. */ - vertex->on_stack = true;list_add (&vertex->scc_entry, &vertex_stack); vertex->index = index;
@@ -291,7 +296,7 @@ next_vertex:if (!next_vertex)continue ; -if (next_vertex->index ==UNIX_VERTEX_INDEX_UNVISITED ) { +if (next_vertex->index == unix_vertex_unvisited_index) {/* Iterative deepening depth first search * * 1. Push a forward edge to edge_stack and set
@@ -317,7 +322,7 @@ prev_vertex:* to skip SCC finalisation. */ vertex->lowlink =min (vertex->lowlink, next_vertex->lowlink); - }else if (next_vertex->on_stack) { + }else if (next_vertex->index != unix_vertex_grouped_index) {/* Loop detected by a back/cross edge. * * The successor is on vertex_stack, so two vertices are
@@ -344,7 +349,8 @@ prev_vertex:/* Don't restart DFS from this vertex in unix_walk_scc(). */ list_move_tail (&vertex->entry, &unix_visited_vertices); - vertex->on_stack = false; +/* Mark vertex as off-stack. */ + vertex->index = unix_vertex_grouped_index; }list_del (&scc);
@@ -357,20 +363,18 @@ prev_vertex:static void unix_walk_scc (void ) { -struct unix_vertex *vertex; - -list_for_each_entry (vertex, &unix_unvisited_vertices, entry) - vertex->index =UNIX_VERTEX_INDEX_UNVISITED ; -/* Visit every vertex exactly once. * __unix_walk_scc() moves visited vertices to unix_visited_vertices. */ while (!list_empty (&unix_unvisited_vertices)) { +struct unix_vertex *vertex; + vertex =list_first_entry (&unix_unvisited_vertices,typeof (*vertex), entry);__unix_walk_scc (vertex); }list_replace_init (&unix_visited_vertices, &unix_unvisited_vertices); +swap (unix_vertex_unvisited_index, unix_vertex_grouped_index); }static LIST_HEAD (gc_candidates);
Greg Kroah-Hartman
maintainerPATCH 297/325 af_unix: Skip GC if no cycle exists.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 77e5593aebba823bcbcf2c4b58b07efcd63933b8 upstream.
We do not need to run GC if there is no possible cyclic reference. We use unix_graph_maybe_cyclic to decide if we should run GC.
If a fd of an AF_UNIX socket is passed to an already inflight AF_UNIX socket, they could form a cyclic reference. Then, we set true to unix_graph_maybe_cyclic and later run Tarjan's algorithm to group them into SCC.
Once we run Tarjan's algorithm, we are 100% sure whether cyclic references exist or not. If there is no cycle, we set false to unix_graph_maybe_cyclic and can skip the entire garbage collection next time.
When finalising SCC, we set true to unix_graph_maybe_cyclic if SCC consists of multiple vertices.
Even if SCC is a single vertex, a cycle might exist as self-fd passing. Given the corner case is rare, we detect it by checking all edges of the vertex and set true to unix_graph_maybe_cyclic.
With this change, __unix_gc() is just a spin_lock() dance in the normal usage.
--- net/unix/garbage.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
net/unix/garbage.c +47 -1
@@ -112,6 +112,19 @@ static struct unix_vertex *unix_edge_sucreturn edge->successor->vertex; } +static bool unix_graph_maybe_cyclic; + +static void unix_update_graph (struct unix_vertex *vertex) +{ +/* If the receiver socket is not inflight, no cyclic +* reference could be formed. +*/ +if (!vertex) +return ; + + unix_graph_maybe_cyclic = true; +} +static LIST_HEAD (unix_unvisited_vertices);enum unix_vertex_index {
@@ -138,12 +151,16 @@ static void unix_add_edge(struct scm_fp_ vertex->out_degree++;list_add_tail (&edge->vertex_entry, &vertex->edges); + +unix_update_graph (unix_edge_successor (edge)); }static void unix_del_edge (struct scm_fp_list *fpl,struct unix_edge *edge) {struct unix_vertex *vertex = edge->predecessor->vertex; +unix_update_graph (unix_edge_successor (edge)); +list_del (&edge->vertex_entry); vertex->out_degree--;
@@ -227,6 +244,7 @@ out:void unix_update_edges (struct unix_sock *receiver) {spin_lock (&unix_gc_lock); +unix_update_graph (unix_sk (receiver->listener)->vertex); receiver->listener =NULL ;spin_unlock (&unix_gc_lock); }
@@ -268,6 +286,26 @@ void unix_destroy_fpl(struct scm_fp_listunix_free_vertices (fpl); } +static bool unix_scc_cyclic (struct list_head *scc) +{ +struct unix_vertex *vertex; +struct unix_edge *edge; + +/* SCC containing multiple vertices ? */ +if (!list_is_singular (scc)) +return true; + + vertex =list_first_entry (scc,typeof (*vertex), scc_entry); + +/* Self-reference or a embryo-listener circle ? */ +list_for_each_entry (edge, &vertex->edges, vertex_entry) { +if (unix_edge_successor (edge) == vertex) +return true; + } + +return false; +} +static LIST_HEAD (unix_visited_vertices);static unsigned long unix_vertex_grouped_index =UNIX_VERTEX_INDEX_MARK2 ;
@@ -353,6 +391,9 @@ prev_vertex: vertex->index = unix_vertex_grouped_index; } +if (!unix_graph_maybe_cyclic) + unix_graph_maybe_cyclic =unix_scc_cyclic (&scc); +list_del (&scc); }
@@ -363,6 +404,8 @@ prev_vertex:static void unix_walk_scc (void ) { + unix_graph_maybe_cyclic = false; +/* Visit every vertex exactly once. * __unix_walk_scc() moves visited vertices to unix_visited_vertices. */
@@ -524,6 +567,9 @@ static void __unix_gc(struct work_structspin_lock (&unix_gc_lock); +if (!unix_graph_maybe_cyclic) + goto skip_gc; +unix_walk_scc ();/* First, select candidates for garbage collection. Only
@@ -633,7 +679,7 @@ static void __unix_gc(struct work_struct/* All candidates should have been detached by now. */ WARN_ON_ONCE (!list_empty (&gc_candidates)); - +skip_gc:/* Paired with READ_ONCE() in wait_for_unix_gc(). */ WRITE_ONCE (gc_in_progress, false);
Greg Kroah-Hartman
maintainerPATCH 298/325 af_unix: Avoid Tarjans algorithm if unnecessary.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit ad081928a8b0f57f269df999a28087fce6f2b6ce upstream.
Once a cyclic reference is formed, we need to run GC to check if there is dead SCC.
However, we do not need to run Tarjan's algorithm if we know that the shape of the inflight graph has not been changed.
If an edge is added/updated/deleted and the edge's successor is inflight, we set false to unix_graph_grouped, which means we need to re-classify SCC.
Once we finalise SCC, we set true to unix_graph_grouped.
While unix_graph_grouped is true, we can iterate the grouped SCC using vertex->scc_entry in unix_walk_scc_fast().
list_add() and list_for_each_entry_reverse() uses seem weird, but they are to keep the vertex order consistent and make writing test easier.
--- net/unix/garbage.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
net/unix/garbage.c +27 -1
@@ -113,6 +113,7 @@ static struct unix_vertex *unix_edge_suc }static bool unix_graph_maybe_cyclic; +static bool unix_graph_grouped;static void unix_update_graph (struct unix_vertex *vertex) {
@@ -123,6 +124,7 @@ static void unix_update_graph(struct unireturn ; unix_graph_maybe_cyclic = true; + unix_graph_grouped = false; }static LIST_HEAD (unix_unvisited_vertices);
@@ -144,6 +146,7 @@ static void unix_add_edge(struct scm_fp_ vertex->index = unix_vertex_unvisited_index; vertex->out_degree =0 ;INIT_LIST_HEAD (&vertex->edges); +INIT_LIST_HEAD (&vertex->scc_entry);list_move_tail (&vertex->entry, &unix_unvisited_vertices); edge->predecessor->vertex = vertex;
@@ -418,6 +421,26 @@ static void unix_walk_scc(void)list_replace_init (&unix_visited_vertices, &unix_unvisited_vertices);swap (unix_vertex_unvisited_index, unix_vertex_grouped_index); + + unix_graph_grouped = true; +} + +static void unix_walk_scc_fast (void ) +{ +while (!list_empty (&unix_unvisited_vertices)) { +struct unix_vertex *vertex; +struct list_head scc; + + vertex =list_first_entry (&unix_unvisited_vertices,typeof (*vertex), entry); +list_add (&scc, &vertex->scc_entry); + +list_for_each_entry_reverse (vertex, &scc, scc_entry) +list_move_tail (&vertex->entry, &unix_visited_vertices); + +list_del (&scc); + } + +list_replace_init (&unix_visited_vertices, &unix_unvisited_vertices); }static LIST_HEAD (gc_candidates);
@@ -570,7 +593,10 @@ static void __unix_gc(struct work_structif (!unix_graph_maybe_cyclic) goto skip_gc; -unix_walk_scc (); +if (unix_graph_grouped) +unix_walk_scc_fast (); +else +unix_walk_scc ();/* First, select candidates for garbage collection. Only * in-flight sockets are considered, and from those only ones
Greg Kroah-Hartman
maintainerPATCH 299/325 af_unix: Assign a unique index to SCC.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit bfdb01283ee8f2f3089656c3ff8f62bb072dabb2 upstream.
The definition of the lowlink in Tarjan's algorithm is the smallest index of a vertex that is reachable with at most one back-edge in SCC. This is not useful for a cross-edge.
If we start traversing from A in the following graph, the final lowlink of D is 3. The cross-edge here is one between D and C.
A -> B -> D D = (4, 3) (index, lowlink) ^ | | C = (3, 1) | V | B = (2, 1) `--- C <--' A = (1, 1)
This is because the lowlink of D is updated with the index of C.
In the following patch, we detect a dead SCC by checking two conditions for each vertex.
1) vertex has no edge directed to another SCC (no bridge)
2) vertex's out_degree is the same as the refcount of its file
If 1) is false, there is a receiver of all fds of the SCC and its ancestor SCC.
To evaluate 1), we need to assign a unique index to each SCC and assign it to all vertices in the SCC.
This patch changes the lowlink update logic for cross-edge so that in the example above, the lowlink of D is updated with the lowlink of C.
A -> B -> D D = (4, 1) (index, lowlink) ^ | | C = (3, 1) | V | B = (2, 1) `--- C <--' A = (1, 1)
Then, all vertices in the same SCC have the same lowlink, and we can quickly find the bridge connecting to different SCC if exists.
However, it is no longer called lowlink, so we rename it to scc_index. (It's sometimes called lowpoint.)
Also, we add a global variable to hold the last index used in DFS so that we do not reset the initial index in each DFS.
This patch can be squashed to the SCC detection patch but is split deliberately for anyone wondering why lowlink is not used as used in the original Tarjan's algorithm and many reference implementations.
--- include/net/af_unix.h | 2 +- net/unix/garbage.c | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-)
include/net/af_unix.h +1 -1
@@ -36,7 +36,7 @@ struct unix_vertex {struct list_head scc_entry;unsigned long out_degree;unsigned long index; -unsigned long lowlink; +unsigned long scc_index; };struct unix_edge {
net/unix/garbage.c +15 -14
@@ -312,9 +312,8 @@ static bool unix_scc_cyclic(struct list_static LIST_HEAD (unix_visited_vertices);static unsigned long unix_vertex_grouped_index =UNIX_VERTEX_INDEX_MARK2 ; -static void __unix_walk_scc (struct unix_vertex *vertex) +static void __unix_walk_scc (struct unix_vertex *vertex,unsigned long *last_index) { -unsigned long index =UNIX_VERTEX_INDEX_START ;LIST_HEAD (vertex_stack);struct unix_edge *edge;LIST_HEAD (edge_stack);
@@ -326,9 +325,9 @@ next_vertex:*/ list_add (&vertex->scc_entry, &vertex_stack); - vertex->index = index; - vertex->lowlink = index; - index++; + vertex->index = *last_index; + vertex->scc_index = *last_index; + (*last_index)++;/* Explore neighbour vertices (receivers of the current vertex's fd). */ list_for_each_entry (edge, &vertex->edges, vertex_entry) {
@@ -358,30 +357,30 @@ prev_vertex: next_vertex = vertex; vertex = edge->predecessor->vertex; -/* If the successor has a smaller lowlink, two vertices -* are in the same SCC, so propagate the smaller lowlink +/* If the successor has a smaller scc_index, two vertices +* are in the same SCC, so propagate the smaller scc_index * to skip SCC finalisation. */ - vertex->lowlink =min (vertex->lowlink, next_vertex->lowlink); + vertex->scc_index =min (vertex->scc_index, next_vertex->scc_index); }else if (next_vertex->index != unix_vertex_grouped_index) {/* Loop detected by a back/cross edge. * -* The successor is on vertex_stack, so two vertices are -* in the same SCC. If the successor has a smaller index, +* The successor is on vertex_stack, so two vertices are in +* the same SCC. If the successor has a smaller *scc_index*, * propagate it to skip SCC finalisation. */ - vertex->lowlink =min (vertex->lowlink, next_vertex->index); + vertex->scc_index =min (vertex->scc_index, next_vertex->scc_index); }else {/* The successor was already grouped as another SCC */ } } -if (vertex->index == vertex->lowlink) { +if (vertex->index == vertex->scc_index) {struct list_head scc;/* SCC finalised. * -* If the lowlink was not updated, all the vertices above on +* If the scc_index was not updated, all the vertices above on * vertex_stack are in the same SCC. Group them using scc_entry. */ __list_cut_position (&scc, &vertex_stack, &vertex->scc_entry);
@@ -407,6 +406,8 @@ prev_vertex:static void unix_walk_scc (void ) { +unsigned long last_index =UNIX_VERTEX_INDEX_START ; + unix_graph_maybe_cyclic = false;/* Visit every vertex exactly once.
@@ -416,7 +417,7 @@ static void unix_walk_scc(void)struct unix_vertex *vertex; vertex =list_first_entry (&unix_unvisited_vertices,typeof (*vertex), entry); -__unix_walk_scc (vertex); +__unix_walk_scc (vertex, &last_index); }list_replace_init (&unix_visited_vertices, &unix_unvisited_vertices);
Greg Kroah-Hartman
maintainerPATCH 300/325 af_unix: Detect dead SCC.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit a15702d8b3aad8ce5268c565bd29f0e02fd2db83 upstream.
When iterating SCC, we call unix_vertex_dead() for each vertex to check if the vertex is close()d and has no bridge to another SCC.
If both conditions are true for every vertex in SCC, we can execute garbage collection for all skb in the SCC.
The actual garbage collection is done in the following patch, replacing the old implementation.
--- net/unix/garbage.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
net/unix/garbage.c +43 -1
@@ -289,6 +289,39 @@ void unix_destroy_fpl(struct scm_fp_listunix_free_vertices (fpl); } +static bool unix_vertex_dead (struct unix_vertex *vertex) +{ +struct unix_edge *edge; +struct unix_sock *u; +long total_ref; + +list_for_each_entry (edge, &vertex->edges, vertex_entry) { +struct unix_vertex *next_vertex =unix_edge_successor (edge); + +/* The vertex's fd can be received by a non-inflight socket. */ +if (!next_vertex) +return false; + +/* The vertex's fd can be received by an inflight socket in +* another SCC. +*/ +if (next_vertex->scc_index != vertex->scc_index) +return false; + } + +/* No receiver exists out of the same SCC. */ + + edge =list_first_entry (&vertex->edges,typeof (*edge), vertex_entry); + u = edge->predecessor; + total_ref =file_count (u->sk.sk_socket->file); + +/* If not close()d, total_ref > out_degree. */ +if (total_ref != vertex->out_degree) +return false; + +return true; +} +static bool unix_scc_cyclic (struct list_head *scc) {struct unix_vertex *vertex;
@@ -377,6 +410,7 @@ prev_vertex:if (vertex->index == vertex->scc_index) {struct list_head scc; +bool scc_dead = true;/* SCC finalised. *
@@ -391,6 +425,9 @@ prev_vertex:/* Mark vertex as off-stack. */ vertex->index = unix_vertex_grouped_index; + +if (scc_dead) + scc_dead =unix_vertex_dead (vertex); }if (!unix_graph_maybe_cyclic)
@@ -431,13 +468,18 @@ static void unix_walk_scc_fast(void)while (!list_empty (&unix_unvisited_vertices)) {struct unix_vertex *vertex;struct list_head scc; +bool scc_dead = true; vertex =list_first_entry (&unix_unvisited_vertices,typeof (*vertex), entry);list_add (&scc, &vertex->scc_entry); -list_for_each_entry_reverse (vertex, &scc, scc_entry) +list_for_each_entry_reverse (vertex, &scc, scc_entry) {list_move_tail (&vertex->entry, &unix_visited_vertices); +if (scc_dead) + scc_dead =unix_vertex_dead (vertex); + } +list_del (&scc); }
Greg Kroah-Hartman
maintainerPATCH 301/325 af_unix: Replace garbage collection algorithm.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 4090fa373f0e763c43610853d2774b5979915959 upstream.
If we find a dead SCC during iteration, we call unix_collect_skb() to splice all skb in the SCC to the global sk_buff_head, hitlist.
After iterating all SCC, we unlock unix_gc_lock and purge the queue.
--- include/net/af_unix.h | 8 - net/unix/af_unix.c | 12 - net/unix/garbage.c | 318 ++++++++++---------------------------------------- 3 files changed, 64 insertions(+), 274 deletions(-)
include/net/af_unix.h +0 -8
@@ -19,9 +19,6 @@ static inline struct unix_sock *unix_getextern spinlock_t unix_gc_lock;extern unsigned int unix_tot_inflight; - -void unix_inflight (struct user_struct *user,struct file *fp); -void unix_notinflight (struct user_struct *user,struct file *fp);void unix_add_edges (struct scm_fp_list *fpl,struct unix_sock *receiver);void unix_del_edges (struct scm_fp_list *fpl);void unix_update_edges (struct unix_sock *receiver);
@@ -85,12 +82,7 @@ struct unix_sock {struct sock *peer;struct sock *listener;struct unix_vertex *vertex; -struct list_head link; -unsigned long inflight;spinlock_t lock; -unsigned long gc_flags; -#define UNIX_GC_CANDIDATE 0 -#define UNIX_GC_MAYBE_CYCLE 1struct socket_wq peer_wq;wait_queue_entry_t peer_wake;struct scm_stat scm_stat;
net/unix/af_unix.c +0 -12
@@ -955,12 +955,10 @@ static struct sock *unix_create1(struct sk->sk_destruct = unix_sock_destructor; u =unix_sk (sk); u->listener =NULL ; - u->inflight =0 ; u->vertex =NULL ; u->path.dentry =NULL ; u->path.mnt =NULL ;spin_lock_init (&u->lock); -INIT_LIST_HEAD (&u->link);mutex_init (&u->iolock);/* single task reading lock */ mutex_init (&u->bindlock);/* single task binding lock */ init_waitqueue_head (&u->peer_wait);
@@ -1744,8 +1742,6 @@ static inline bool too_many_unix_fds(strstatic int unix_attach_fds (struct scm_cookie *scm,struct sk_buff *skb) { -int i; -if (too_many_unix_fds (current))return -ETOOMANYREFS ;
@@ -1757,9 +1753,6 @@ static int unix_attach_fds(struct scm_coif (!UNIXCB (skb).fp)return -ENOMEM ; -for (i = scm->fp->count -1 ; i >=0 ; i--) -unix_inflight (scm->fp->user, scm->fp->fp[i]); -if (unix_prepare_fpl (UNIXCB (skb).fp))return -ENOMEM ;
@@ -1768,15 +1761,10 @@ static int unix_attach_fds(struct scm_costatic void unix_detach_fds (struct scm_cookie *scm,struct sk_buff *skb) { -int i; - scm->fp =UNIXCB (skb).fp;UNIXCB (skb).fp =NULL ;unix_destroy_fpl (scm->fp); - -for (i = scm->fp->count -1 ; i >=0 ; i--) -unix_notinflight (scm->fp->user, scm->fp->fp[i]); }static void unix_peek_fds (struct scm_cookie *scm,struct sk_buff *skb)
net/unix/garbage.c +64 -254
384 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 302/325 af_unix: Remove lock dance in unix_peek_fds().
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 118f457da9ed58a79e24b73c2ef0aa1987241f0e upstream.
In the previous GC implementation, the shape of the inflight socket graph was not expected to change while GC was in progress.
MSG_PEEK was tricky because it could install inflight fd silently and transform the graph.
Let's say we peeked a fd, which was a listening socket, and accept()ed some embryo sockets from it. The garbage collection algorithm would have been confused because the set of sockets visited in scan_inflight() would change within the same GC invocation.
That's why we placed spin_lock(&unix_gc_lock) and spin_unlock() in unix_peek_fds() with a fat comment.
In the new GC implementation, we no longer garbage-collect the socket if it exists in another queue, that is, if it has a bridge to another SCC. Also, accept() will require the lock if it has edges.
Thus, we need not do the complicated lock dance.
--- include/net/af_unix.h | 1 - net/unix/af_unix.c | 42 ------------------------------------------ net/unix/garbage.c | 2 +- 3 files changed, 1 insertion(+), 44 deletions(-)
include/net/af_unix.h +0 -1
@@ -17,7 +17,6 @@ static inline struct unix_sock *unix_get }#endif -extern spinlock_t unix_gc_lock;extern unsigned int unix_tot_inflight;void unix_add_edges (struct scm_fp_list *fpl,struct unix_sock *receiver);void unix_del_edges (struct scm_fp_list *fpl);
net/unix/af_unix.c +0 -42
48 lines not on this page · raw message
net/unix/garbage.c +1 -1
@@ -183,7 +183,7 @@ static void unix_free_vertices(struct sc } } -DEFINE_SPINLOCK (unix_gc_lock); +static DEFINE_SPINLOCK (unix_gc_lock);unsigned int unix_tot_inflight;void unix_add_edges (struct scm_fp_list *fpl,struct unix_sock *receiver)
Greg Kroah-Hartman
maintainerPATCH 303/325 af_unix: Try not to hold unix_gc_lock during accept().
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit fd86344823b521149bb31d91eba900ba3525efa6 upstream.
Commit dcf70df2048d ("af_unix: Fix up unix_edge.successor for embryo socket.") added spin_lock(&unix_gc_lock) in accept() path, and it caused regression in a stress test as reported by kernel test robot.
If the embryo socket is not part of the inflight graph, we need not hold the lock.
To decide that in O(1) time and avoid the regression in the normal use case,
1. add a new stat unix_sk(sk)->scm_stat.nr_unix_fds
2. count the number of inflight AF_UNIX sockets in the receive queue under unix_state_lock()
3. move unix_update_edges() call under unix_state_lock()
4. avoid locking if nr_unix_fds is 0 in unix_update_edges()
--- include/net/af_unix.h | 1 + net/unix/af_unix.c | 2 +- net/unix/garbage.c | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-)
include/net/af_unix.h +1 -0
@@ -67,6 +67,7 @@ struct unix_skb_parms {struct scm_stat {atomic_t nr_fds; +unsigned long nr_unix_fds; };#define UNIXCB (skb) (*(struct unix_skb_parms *)&((skb)->cb))
net/unix/af_unix.c +1 -1
@@ -1677,12 +1677,12 @@ static int unix_accept(struct socket *so } tsk = skb->sk; -unix_update_edges (unix_sk (tsk));skb_free_datagram (sk, skb);wake_up_interruptible (&unix_sk (sk)->peer_wait);/* attach accepted sock to socket */ unix_state_lock (tsk); +unix_update_edges (unix_sk (tsk)); newsock->state =SS_CONNECTED ;unix_sock_inherit_flags (sock, newsock);sock_graft (tsk, newsock);
net/unix/garbage.c +16 -4
@@ -209,6 +209,7 @@ void unix_add_edges(struct scm_fp_list *unix_add_edge (fpl, edge); }while (i < fpl->count_unix); + receiver->scm_stat.nr_unix_fds += fpl->count_unix;WRITE_ONCE (unix_tot_inflight, unix_tot_inflight + fpl->count_unix); out:WRITE_ONCE (fpl->user->unix_inflight, fpl->user->unix_inflight + fpl->count);
@@ -222,6 +223,7 @@ out:void unix_del_edges (struct scm_fp_list *fpl) { +struct unix_sock *receiver;int i =0 ;spin_lock (&unix_gc_lock);
@@ -235,6 +237,8 @@ void unix_del_edges(struct scm_fp_list *unix_del_edge (fpl, edge); }while (i < fpl->count_unix); + receiver = fpl->edges[0 ].successor; + receiver->scm_stat.nr_unix_fds -= fpl->count_unix;WRITE_ONCE (unix_tot_inflight, unix_tot_inflight - fpl->count_unix); out:WRITE_ONCE (fpl->user->unix_inflight, fpl->user->unix_inflight - fpl->count);
@@ -246,10 +250,18 @@ out:void unix_update_edges (struct unix_sock *receiver) { -spin_lock (&unix_gc_lock); -unix_update_graph (unix_sk (receiver->listener)->vertex); - receiver->listener =NULL ; -spin_unlock (&unix_gc_lock); +/* nr_unix_fds is only updated under unix_state_lock(). +* If it's 0 here, the embryo socket is not part of the +* inflight graph, and GC will not see it, so no lock needed. +*/ +if (!receiver->scm_stat.nr_unix_fds) { + receiver->listener =NULL ; + }else { +spin_lock (&unix_gc_lock); +unix_update_graph (unix_sk (receiver->listener)->vertex); + receiver->listener =NULL ; +spin_unlock (&unix_gc_lock); + } }int unix_prepare_fpl (struct scm_fp_list *fpl)
Greg Kroah-Hartman
maintainerPATCH 304/325 af_unix: Dont access successor in unix_del_edges() during GC.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 1af2dface5d286dd1f2f3405a0d6fa9f2c8fb998 upstream.
syzbot reported use-after-free in unix_del_edges(). [0]
What the repro does is basically repeat the following quickly.
1. pass a fd of an AF_UNIX socket to itself
socketpair(AF_UNIX, SOCK_DGRAM, 0, [3, 4]) = 0
sendmsg(3, {..., msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET,
cmsg_type=SCM_RIGHTS, cmsg_data=[4]}], ...}, 0) = 0 2. pass other fds of AF_UNIX sockets to the socket above
socketpair(AF_UNIX, SOCK_SEQPACKET, 0, [5, 6]) = 0
sendmsg(3, {..., msg_control=[{cmsg_len=48, cmsg_level=SOL_SOCKET,
cmsg_type=SCM_RIGHTS, cmsg_data=[5, 6]}], ...}, 0) = 03. close all sockets
Here, two skb are created, and every unix_edge->successor is the first socket. Then, __unix_gc() will garbage-collect the two skb:
(a) free skb with self-referencing fd
(b) free skb holding other sockets
After (a), the self-referencing socket will be scheduled to be freed later by the delayed_fput() task.
syzbot repeated the sequences above (1. ~ 3.) quickly and triggered the task concurrently while GC was running.
So, at (b), the socket was already freed, and accessing it was illegal.
unix_del_edges() accesses the receiver socket as edge->successor to optimise GC. However, we should not do it during GC.
Garbage-collecting sockets does not change the shape of the rest of the graph, so we need not call unix_update_graph() to update unix_graph_grouped when we purge skb.
However, if we clean up all loops in the unix_walk_scc_fast() path, unix_graph_maybe_cyclic remains unchanged (true), and __unix_gc() will call unix_walk_scc_fast() continuously even though there is no socket to garbage-collect.
To keep that optimisation while fixing UAF, let's add the same updating logic of unix_graph_maybe_cyclic in unix_walk_scc_fast() as done in unix_walk_scc() and __unix_walk_scc().
Note that when unix_del_edges() is called from other places, the receiver socket is always alive:
- sendmsg: the successor's sk_refcnt is bumped by sock_hold() unix_find_other() for SOCK_DGRAM, connect() for SOCK_STREAM
- recvmsg: the successor is the receiver, and its fd is alive
[0]:
BUG: KASAN: slab-use-after-free in unix_edge_successor net/unix/garbage.c:109 [inline] BUG: KASAN: slab-use-after-free in unix_del_edge net/unix/garbage.c:165 [inline] BUG: KASAN: slab-use-after-free in unix_del_edges+0x148/0x630 net/unix/garbage.c:237 Read of size 8 at addr ffff888079c6e640 by task kworker/u8:6/1099 CPU: 0 PID: 1099 Comm: kworker/u8:6 Not tainted 6.9.0-rc4-next-20240418-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 Workqueue: events_unbound __unix_gc Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114 print_address_description mm/kasan/report.c:377 [inline] print_report+0x169/0x550 mm/kasan/report.c:488 kasan_report+0x143/0x180 mm/kasan/report.c:601 unix_edge_successor net/unix/garbage.c:109 [inline] unix_del_edge net/unix/garbage.c:165 [inline] unix_del_edges+0x148/0x630 net/unix/garbage.c:237 unix_destroy_fpl+0x59/0x210 net/unix/garbage.c:298 unix_detach_fds net/unix/af_unix.c:1811 [inline] unix_destruct_scm+0x13e/0x210 net/unix/af_unix.c:1826 skb_release_head_state+0x100/0x250 net/core/skbuff.c:1127 skb_release_all net/core/skbuff.c:1138 [inline] __kfree_skb net/core/skbuff.c:1154 [inline] kfree_skb_reason+0x16d/0x3b0 net/core/skbuff.c:1190 __skb_queue_purge_reason include/linux/skbuff.h:3251 [inline] __skb_queue_purge include/linux/skbuff.h:3256 [inline] __unix_gc+0x1732/0x1830 net/unix/garbage.c:575 process_one_work kernel/workqueue.c:3218 [inline] process_scheduled_works+0xa2c/0x1830 kernel/workqueue.c:3299 worker_thread+0x86d/0xd70 kernel/workqueue.c:3380 kthread+0x2f0/0x390 kernel/kthread.c:389 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 </TASK> Allocated by task 14427: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 unpoison_slab_object mm/kasan/common.c:312 [inline] __kasan_slab_alloc+0x66/0x80 mm/kasan/common.c:338 kasan_slab_alloc include/linux/kasan.h:201 [inline] slab_post_alloc_hook mm/slub.c:3897 [inline] slab_alloc_node mm/slub.c:3957 [inline] kmem_cache_alloc_noprof+0x135/0x290 mm/slub.c:3964 sk_prot_alloc+0x58/0x210 net/core/sock.c:2074 sk_alloc+0x38/0x370 net/core/sock.c:2133 unix_create1+0xb4/0x770 unix_create+0x14e/0x200 net/unix/af_unix.c:1034 __sock_create+0x490/0x920 net/socket.c:1571 sock_create net/socket.c:1622 [inline] __sys_socketpair+0x33e/0x720 net/socket.c:1773 __do_sys_socketpair net/socket.c:1822 [inline] __se_sys_socketpair net/socket.c:1819 [inline] __x64_sys_socketpair+0x9b/0xb0 net/socket.c:1819 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 1805: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:579 poison_slab_object+0xe0/0x150 mm/kasan/common.c:240 __kasan_slab_free+0x37/0x60 mm/kasan/common.c:256 kasan_slab_free include/linux/kasan.h:184 [inline] slab_free_hook mm/slub.c:2190 [inline] slab_free mm/slub.c:4393 [inline] kmem_cache_free+0x145/0x340 mm/slub.c:4468 sk_prot_free net/core/sock.c:2114 [inline] __sk_destruct+0x467/0x5f0 net/core/sock.c:2208 sock_put include/net/sock.h:1948 [inline] unix_release_sock+0xa8b/0xd20 net/unix/af_unix.c:665 unix_release+0x91/0xc0 net/unix/af_unix.c:1049 __sock_release net/socket.c:659 [inline] sock_close+0xbc/0x240 net/socket.c:1421 __fput+0x406/0x8b0 fs/file_table.c:422 delayed_fput+0x59/0x80 fs/file_table.c:445 process_one_work kernel/workqueue.c:3218 [inline] process_scheduled_works+0xa2c/0x1830 kernel/workqueue.c:3299 worker_thread+0x86d/0xd70 kernel/workqueue.c:3380 kthread+0x2f0/0x390 kernel/kthread.c:389 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 The buggy address belongs to the object at ffff888079c6e000 which belongs to the cache UNIX of size 1920
The buggy address is located 1600 bytes inside of
freed 1920-byte region [ffff888079c6e000, ffff888079c6e780)
--- net/unix/garbage.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
net/unix/garbage.c +12 -5
@@ -158,11 +158,14 @@ static void unix_add_edge(struct scm_fp_unix_update_graph (unix_edge_successor (edge)); } +static bool gc_in_progress; +static void unix_del_edge (struct scm_fp_list *fpl,struct unix_edge *edge) {struct unix_vertex *vertex = edge->predecessor->vertex; -unix_update_graph (unix_edge_successor (edge)); +if (!gc_in_progress) +unix_update_graph (unix_edge_successor (edge));list_del (&edge->vertex_entry); vertex->out_degree--;
@@ -237,8 +240,10 @@ void unix_del_edges(struct scm_fp_list *unix_del_edge (fpl, edge); }while (i < fpl->count_unix); - receiver = fpl->edges[0 ].successor; - receiver->scm_stat.nr_unix_fds -= fpl->count_unix; +if (!gc_in_progress) { + receiver = fpl->edges[0 ].successor; + receiver->scm_stat.nr_unix_fds -= fpl->count_unix; + }WRITE_ONCE (unix_tot_inflight, unix_tot_inflight - fpl->count_unix); out:WRITE_ONCE (fpl->user->unix_inflight, fpl->user->unix_inflight - fpl->count);
@@ -526,6 +531,8 @@ static void unix_walk_scc(struct sk_buffstatic void unix_walk_scc_fast (struct sk_buff_head *hitlist) { + unix_graph_maybe_cyclic = false; +while (!list_empty (&unix_unvisited_vertices)) {struct unix_vertex *vertex;struct list_head scc;
@@ -543,6 +550,8 @@ static void unix_walk_scc_fast(struct skif (scc_dead)unix_collect_skb (&scc, hitlist); +else if (!unix_graph_maybe_cyclic) + unix_graph_maybe_cyclic =unix_scc_cyclic (&scc);list_del (&scc); }
@@ -550,8 +559,6 @@ static void unix_walk_scc_fast(struct sklist_replace_init (&unix_visited_vertices, &unix_unvisited_vertices); } -static bool gc_in_progress; -static void __unix_gc (struct work_struct *work) {struct sk_buff_head hitlist;
Greg Kroah-Hartman
maintainerPATCH 305/325 af_unix: Add dead flag to struct scm_fp_list.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
commit 7172dc93d621d5dc302d007e95ddd1311ec64283 upstream.
Commit 1af2dface5d2 ("af_unix: Don't access successor in unix_del_edges() during GC.") fixed use-after-free by avoid accessing edge->successor while GC is in progress.
However, there could be a small race window where another process could call unix_del_edges() while gc_in_progress is true and __skb_queue_purge() is on the way.
So, we need another marker for struct scm_fp_list which indicates if the skb is garbage-collected.
This patch adds dead flag in struct scm_fp_list and set it true before calling __skb_queue_purge().
--- include/net/scm.h | 1 + net/core/scm.c | 1 + net/unix/garbage.c | 14 ++++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-)
include/net/scm.h +1 -0
@@ -31,6 +31,7 @@ struct scm_fp_list {short max;#ifdef CONFIG_UNIX bool inflight; +bool dead;struct list_head vertices;struct unix_edge *edges;#endif
net/core/scm.c +1 -0
@@ -91,6 +91,7 @@ static int scm_fp_copy(struct cmsghdr *c fpl->user =NULL ;#if IS_ENABLED (CONFIG_UNIX ) fpl->inflight = false; + fpl->dead = false; fpl->edges =NULL ;INIT_LIST_HEAD (&fpl->vertices);#endif
net/unix/garbage.c +10 -4
@@ -158,13 +158,11 @@ static void unix_add_edge(struct scm_fp_unix_update_graph (unix_edge_successor (edge)); } -static bool gc_in_progress; -static void unix_del_edge (struct scm_fp_list *fpl,struct unix_edge *edge) {struct unix_vertex *vertex = edge->predecessor->vertex; -if (!gc_in_progress) +if (!fpl->dead)unix_update_graph (unix_edge_successor (edge));list_del (&edge->vertex_entry);
@@ -240,7 +238,7 @@ void unix_del_edges(struct scm_fp_list *unix_del_edge (fpl, edge); }while (i < fpl->count_unix); -if (!gc_in_progress) { +if (!fpl->dead) { receiver = fpl->edges[0 ].successor; receiver->scm_stat.nr_unix_fds -= fpl->count_unix; }
@@ -559,9 +557,12 @@ static void unix_walk_scc_fast(struct sklist_replace_init (&unix_visited_vertices, &unix_unvisited_vertices); } +static bool gc_in_progress; +static void __unix_gc (struct work_struct *work) {struct sk_buff_head hitlist; +struct sk_buff *skb;spin_lock (&unix_gc_lock);
@@ -579,6 +580,11 @@ static void __unix_gc(struct work_structspin_unlock (&unix_gc_lock); + skb_queue_walk(&hitlist, skb) { +if (UNIXCB (skb).fp) +UNIXCB (skb).fp->dead = true; + } +__skb_queue_purge (&hitlist); skip_gc:WRITE_ONCE (gc_in_progress, false);
Greg Kroah-Hartman
maintainerPATCH 306/325 af_unix: Fix garbage collection of embryos carrying OOB with SCM_RIGHTS
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Luczaj <[email protected]>
commit 041933a1ec7b4173a8e638cae4f8e394331d7e54 upstream.
GC attempts to explicitly drop oob_skb's reference before purging the hit list.
The problem is with embryos: kfree_skb(u->oob_skb) is never called on an embryo socket.
The python script below [0] sends a listener's fd to its embryo as OOB data. While GC does collect the embryo's queue, it fails to drop the OOB skb's refcount. The skb which was in embryo's receive queue stays as unix_sk(sk)->oob_skb and keeps the listener's refcount [1].
Tell GC to dispose embryo's oob_skb.
[0]:
from array import array
from socket import *
addr = '\x00unix-oob'
lis = socket(AF_UNIX, SOCK_STREAM)lis.bind(addr)lis.listen(1)
s = socket(AF_UNIX, SOCK_STREAM)s.connect(addr)
scm = (SOL_SOCKET, SCM_RIGHTS, array('i', [lis.fileno()])) s.sendmsg([b'x'], [scm], MSG_OOB)lis.close()
[1]
$ grep unix-oob /proc/net/unix $ ./unix-oob.py $ grep unix-oob /proc/net/unix 0000000000000000: 00000002 00000000 00000000 0001 02 0 @unix-oob 0000000000000000: 00000002 00000000 00010000 0001 01 6072 @unix-oob
--- net/unix/garbage.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
net/unix/garbage.c +14 -9
@@ -342,6 +342,18 @@ enum unix_recv_queue_lock_class { U_RECVQ_LOCK_EMBRYO, }; +static void unix_collect_queue (struct unix_sock *u,struct sk_buff_head *hitlist) +{ +skb_queue_splice_init (&u->sk.sk_receive_queue, hitlist); + +#if IS_ENABLED (CONFIG_AF_UNIX_OOB ) +if (u->oob_skb) { +WARN_ON_ONCE (skb_unref (u->oob_skb)); + u->oob_skb =NULL ; + } +#endif +} +static void unix_collect_skb (struct list_head *scc,struct sk_buff_head *hitlist) {struct unix_vertex *vertex;
@@ -365,18 +377,11 @@ static void unix_collect_skb(struct list/* listener -> embryo order, the inversion never happens. */ spin_lock_nested (&embryo_queue->lock,U_RECVQ_LOCK_EMBRYO ); -skb_queue_splice_init (embryo_queue, hitlist); +unix_collect_queue (unix_sk (skb->sk), hitlist);spin_unlock (&embryo_queue->lock); } }else { -skb_queue_splice_init (queue, hitlist); - -#if IS_ENABLED (CONFIG_AF_UNIX_OOB ) -if (u->oob_skb) { -kfree_skb (u->oob_skb); - u->oob_skb =NULL ; - } -#endif +unix_collect_queue (u, hitlist); }spin_unlock (&queue->lock);
Greg Kroah-Hartman
maintainerPATCH 307/325 af_unix: Fix uninit-value in __unix_walk_scc()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shigeru Yoshida <[email protected]>
commit 927fa5b3e4f52e0967bfc859afc98ad1c523d2d5 upstream.
KMSAN reported uninit-value access in __unix_walk_scc() [1].
In the list_for_each_entry_reverse() loop, when the vertex's index equals it's scc_index, the loop uses the variable vertex as a temporary variable that points to a vertex in scc. And when the loop is finished, the variable vertex points to the list head, in this case scc, which is a local variable on the stack (more precisely, it's not even scc and might underflow the call stack of __unix_walk_scc():container_of(&scc, struct unix_vertex, scc_entry)).
However, the variable vertex is used under the label prev_vertex. So if the edge_stack is not empty and the function jumps to the prev_vertex label, the function will access invalid data on the stack. This causes the uninit-value access issue.
Fix this by introducing a new temporary variable for the loop.
[1]
BUG: KMSAN: uninit-value in __unix_walk_scc net/unix/garbage.c:478 [inline] BUG: KMSAN: uninit-value in unix_walk_scc net/unix/garbage.c:526 [inline] BUG: KMSAN: uninit-value in __unix_gc+0x2589/0x3c20 net/unix/garbage.c:584 __unix_walk_scc net/unix/garbage.c:478 [inline] unix_walk_scc net/unix/garbage.c:526 [inline] __unix_gc+0x2589/0x3c20 net/unix/garbage.c:584 process_one_work kernel/workqueue.c:3231 [inline] process_scheduled_works+0xade/0x1bf0 kernel/workqueue.c:3312 worker_thread+0xeb6/0x15b0 kernel/workqueue.c:3393 kthread+0x3c4/0x530 kernel/kthread.c:389 ret_from_fork+0x6e/0x90 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
Uninit was stored to memory at:
unix_walk_scc net/unix/garbage.c:526 [inline] __unix_gc+0x2adf/0x3c20 net/unix/garbage.c:584 process_one_work kernel/workqueue.c:3231 [inline] process_scheduled_works+0xade/0x1bf0 kernel/workqueue.c:3312 worker_thread+0xeb6/0x15b0 kernel/workqueue.c:3393 kthread+0x3c4/0x530 kernel/kthread.c:389 ret_from_fork+0x6e/0x90 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
Local variable entries created at:
ref_tracker_free+0x48/0xf30 lib/ref_tracker.c:222 netdev_tracker_free include/linux/netdevice.h:4058 [inline] netdev_put include/linux/netdevice.h:4075 [inline] dev_put include/linux/netdevice.h:4101 [inline] update_gid_event_work_handler+0xaa/0x1b0 drivers/infiniband/core/roce_gid_mgmt.c:813 CPU: 1 PID: 12763 Comm: kworker/u8:31 Not tainted 6.10.0-rc4-00217-g35bb670d65fc #32 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014 Workqueue: events_unbound __unix_gc
--- net/unix/garbage.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/unix/garbage.c +5 -4
@@ -476,6 +476,7 @@ prev_vertex: }if (vertex->index == vertex->scc_index) { +struct unix_vertex *v;struct list_head scc;bool scc_dead = true;
@@ -486,15 +487,15 @@ prev_vertex:*/ __list_cut_position (&scc, &vertex_stack, &vertex->scc_entry); -list_for_each_entry_reverse (vertex, &scc, scc_entry) { +list_for_each_entry_reverse (v, &scc, scc_entry) {/* Don't restart DFS from this vertex in unix_walk_scc(). */ -list_move_tail (&vertex->entry, &unix_visited_vertices); +list_move_tail (&v->entry, &unix_visited_vertices);/* Mark vertex as off-stack. */ - vertex->index = unix_vertex_grouped_index; + v->index = unix_vertex_grouped_index;if (scc_dead) - scc_dead =unix_vertex_dead (vertex); + scc_dead =unix_vertex_dead (v); }if (scc_dead)
Greg Kroah-Hartman
maintainerPATCH 308/325 arm64: dts: qcom: sm8350: Fix typo in pil_camera_mem node
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alok Tiwari <[email protected]>
commit 295217420a44403a33c30f99d8337fe7b07eb02b upstream.
There is a typo in sm8350.dts where the node label mmeory@85200000 should be memory@85200000.
This patch corrects the typo for clarity and consistency.
--- arch/arm64/boot/dts/qcom/sm8350.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sm8350.dtsi +1 -1
@@ -421,7 +421,7 @@ no-map; }; - pil_camera_mem: mmeory@85200000 { + pil_camera_mem: memory@85200000 { reg = <0x0 0x85200000 0x0 0x500000>; no-map; };
Greg Kroah-Hartman
maintainerPATCH 309/325 net_sched: hfsc: Address reentrant enqueue adding class to eltree twice
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pedro Tammela <[email protected]>
commit ac9fe7dd8e730a103ae4481147395cc73492d786 upstream.
Savino says:
"We are writing to report that this recent patch (141d34391abbb315d68556b7c67ad97885407547) [1]
can be bypassed, and a UAF can still occur when HFSC is utilized with NETEM.
The patch only checks the cl->cl_nactive field to determine whether it is the first insertion or not [2], but this field is only incremented by init_vf [3].
By using HFSC_RSC (which uses init_ed) [4], it is possible to bypass the check and insert the class twice in the eltree.
Under normal conditions, this would lead to an infinite loop in hfsc_dequeue for the reasons we already explained in this report [5].
However, if TBF is added as root qdisc and it is configured with a very low rate,
it can be utilized to prevent packets from being dequeued. This behavior can be exploited to perform subsequent insertions in the HFSC eltree and cause a UAF."
To fix both the UAF and the infinite loop, with netem as an hfsc child, check explicitly in hfsc_enqueue whether the class is already in the eltree whenever the HFSC_RSC flag is set.
[1] https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=141d34391abbb315d68556b7c67ad97885407547
[2] https://elixir.bootlin.com/linux/v6.15-rc5/source/net/sched/sch_hfsc.c#L1572
[3] https://elixir.bootlin.com/linux/v6.15-rc5/source/net/sched/sch_hfsc.c#L677
[4] https://elixir.bootlin.com/linux/v6.15-rc5/source/net/sched/sch_hfsc.c#L1574
[5] https://lore.kernel.org/netdev/8DuRWwfqjoRDLDmBMlIfbrsZg9Gx50DHJc1ilxsEBNe2D6NMoigR_eIRIG0LOjMc3r10nUUZtArXx4oZBIdUfZQrwjcQhdinnMis_0G7VEk=@willsroot.io/T/#u
--- net/sched/sch_hfsc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/sched/sch_hfsc.c +8 -1
@@ -176,6 +176,11 @@ struct hfsc_sched {#define HT_INFINITY 0xffffffffffffffffULL/* infinite time value */ +static bool cl_in_el_or_vttree (struct hfsc_class *cl) +{ +return ((cl->cl_flags &HFSC_FSC ) && cl->cl_nactive) || + ((cl->cl_flags &HFSC_RSC ) && !RB_EMPTY_NODE (&cl->el_node)); +}/* * eligible tree holds backlogged classes being sorted by their eligible times.
@@ -1041,6 +1046,8 @@ hfsc_change_class(struct Qdisc *sch, u32if (cl ==NULL )return -ENOBUFS ; +RB_CLEAR_NODE (&cl->el_node); + err =tcf_block_get (&cl->block, &cl->filter_list, sch, extack);if (err) {kfree (cl);
@@ -1571,7 +1578,7 @@ hfsc_enqueue(struct sk_buff *skb, struct sch->qstats.backlog += len; sch->q.qlen++; -if (first && !cl->cl_nactive) { +if (first && !cl_in_el_or_vttree (cl)) {if (cl->cl_flags &HFSC_RSC )init_ed (cl, len);if (cl->cl_flags &HFSC_FSC )
Greg Kroah-Hartman
maintainerPATCH 310/325 perf/arm-cmn: Fix REQ2/SNP2 mixup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robin Murphy <[email protected]>
commit 11b0f576e0cbde6a12258f2af6753b17b8df342b upstream.
Somehow the encodings for REQ2/SNP2 channels in XP events got mixed up... Unmix them.
--- drivers/perf/arm-cmn.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/perf/arm-cmn.c +4 -4
@@ -675,8 +675,8 @@ static umode_t arm_cmn_event_attr_is_visif ((chan ==5 && cmn->rsp_vc_num <2 ) || (chan ==6 && cmn->dat_vc_num <2 ) || - (chan ==7 && cmn->snp_vc_num <2 ) || - (chan ==8 && cmn->req_vc_num <2 )) + (chan ==7 && cmn->req_vc_num <2 ) || + (chan ==8 && cmn->snp_vc_num <2 ))return 0 ; }
@@ -794,8 +794,8 @@ static umode_t arm_cmn_event_attr_is_vis _CMN_EVENT_XP(pub_##_name, (_event) | (4 << 5)), \ _CMN_EVENT_XP(rsp2_##_name, (_event) | (5 << 5)), \ _CMN_EVENT_XP(dat2_##_name, (_event) | (6 << 5)), \ - _CMN_EVENT_XP(snp2_##_name, (_event) | (7 << 5)), \ - _CMN_EVENT_XP(req2_##_name, (_event) | (8 << 5)) + _CMN_EVENT_XP(req2_##_name, (_event) | (7 << 5)), \ + _CMN_EVENT_XP(snp2_##_name, (_event) | (8 << 5))static struct attribute *arm_cmn_event_attrs[] = {
Greg Kroah-Hartman
maintainerPATCH 311/325 perf/arm-cmn: Initialise cmn->cpu earlier
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robin Murphy <[email protected]>
commit 597704e201068db3d104de3c7a4d447ff8209127 upstream.
For all the complexity of handling affinity for CPU hotplug, what we've apparently managed to overlook is that arm_cmn_init_irqs() has in fact always been setting the *initial* affinity of all IRQs to CPU 0, not the CPU we subsequently choose for event scheduling. Oh dear.
--- drivers/perf/arm-cmn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/arm-cmn.c +1 -1
@@ -2313,6 +2313,7 @@ static int arm_cmn_probe(struct platform cmn->dev = &pdev->dev; cmn->part = (unsigned long )device_get_match_data (cmn->dev); + cmn->cpu =cpumask_local_spread (0 ,dev_to_node (cmn->dev));platform_set_drvdata (pdev, cmn);if (cmn->part ==PART_CMN600 &&has_acpi_companion (cmn->dev)) {
@@ -2340,7 +2341,6 @@ static int arm_cmn_probe(struct platformif (err)return err; - cmn->cpu =cpumask_local_spread (0 ,dev_to_node (cmn->dev)); cmn->pmu = (struct pmu ) { .module =THIS_MODULE , .attr_groups = arm_cmn_attr_groups,
Greg Kroah-Hartman
maintainerPATCH 312/325 coredump: fix error handling for replace_fd()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit 95c5f43181fe9c1b5e5a4bd3281c857a5259991f upstream.
The replace_fd() helper returns the file descriptor number on success and a negative error code on failure. The current error handling in umh_pipe_setup() only works because the file descriptor that is replaced is zero but that's pretty volatile. Explicitly check for a negative error code.
--- fs/coredump.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/coredump.c +7 -2
@@ -493,7 +493,9 @@ static int umh_pipe_setup(struct subproc {struct file *files[2 ];struct coredump_params *cp = (struct coredump_params *)info->data; -int err =create_pipe_files (files,0 ); +int err; + + err =create_pipe_files (files,0 );if (err)return err;
@@ -501,10 +503,13 @@ static int umh_pipe_setup(struct subproc err =replace_fd (0 , files[0 ],0 );fput (files[0 ]); +if (err <0 ) +return err; +/* and disallow core files too */ current->signal->rlim[RLIMIT_CORE ] = (struct rlimit ){1 ,1 }; -return err; +return 0 ; }void do_coredump (const kernel_siginfo_t *siginfo)
Greg Kroah-Hartman
maintainerPATCH 313/325 pid: add pidfd_prepare()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit 6ae930d9dbf2d093157be33428538c91966d8a9f upstream.
Add a new helper that allows to reserve a pidfd and allocates a new pidfd file that stashes the provided struct pid. This will allow us to remove places that either open code this function or that call pidfd_create() but then have to call close_fd() because there are still failure points after pidfd_create() has been called.
Message-Id: <[email protected]>
--- include/linux/pid.h | 1 kernel/fork.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/pid.c | 19 ++++------- 3 files changed, 93 insertions(+), 12 deletions(-)
include/linux/pid.h +1 -0
@@ -80,6 +80,7 @@ extern struct pid *pidfd_pid(const strucstruct pid *pidfd_get_pid (unsigned int fd,unsigned int *flags);struct task_struct *pidfd_get_task (int pidfd,unsigned int *flags);int pidfd_create (struct pid *pid,unsigned int flags); +int pidfd_prepare (struct pid *pid,unsigned int flags,struct file **ret);static inline struct pid *get_pid (struct pid *pid) {
kernel/fork.c +85 -0
91 lines not on this page · raw message
kernel/pid.c +7 -12
@@ -594,20 +594,15 @@ struct task_struct *pidfd_get_task(int p*/ int pidfd_create (struct pid *pid,unsigned int flags) { -int fd; +int pidfd; +struct file *pidfd_file; -if (!pid || !pid_has_task (pid,PIDTYPE_TGID )) -return -EINVAL ; + pidfd =pidfd_prepare (pid, flags, &pidfd_file); +if (pidfd <0 ) +return pidfd; -if (flags & ~(O_NONBLOCK |O_RDWR |O_CLOEXEC )) -return -EINVAL ; - - fd =anon_inode_getfd ("[pidfd]" , &pidfd_fops,get_pid (pid), - flags |O_RDWR |O_CLOEXEC ); -if (fd <0 ) -put_pid (pid); - -return fd; +fd_install (pidfd, pidfd_file); +return pidfd; }/**
Greg Kroah-Hartman
maintainerPATCH 314/325 fork: use pidfd_prepare()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit ca7707f5430ad6b1c9cb7cee0a7f67d69328bb2d upstream.
Stop open-coding get_unused_fd_flags() and anon_inode_getfile(). That's brittle just for keeping the flags between both calls in sync. Use the dedicated helper.
Message-Id: <[email protected]>
--- kernel/fork.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
kernel/fork.c +2 -11
@@ -2378,21 +2378,12 @@ static __latent_entropy struct task_stru* if the fd table isn't shared). */ if (clone_flags &CLONE_PIDFD ) { - retval =get_unused_fd_flags (O_RDWR |O_CLOEXEC ); +/* Note that no task has been attached to @pid yet. */ + retval =__pidfd_prepare (pid,O_RDWR |O_CLOEXEC , &pidfile);if (retval <0 ) goto bad_fork_free_pid; - pidfd = retval; - pidfile =anon_inode_getfile ("[pidfd]" , &pidfd_fops, pid, -O_RDWR |O_CLOEXEC ); -if (IS_ERR (pidfile)) { -put_unused_fd (pidfd); - retval =PTR_ERR (pidfile); - goto bad_fork_free_pid; - } -get_pid (pid);/* held by pidfile now */ - retval =put_user (pidfd, args->pidfd);if (retval) goto bad_fork_put_pidfd;
Greg Kroah-Hartman
maintainerPATCH 315/325 coredump: hand a pidfd to the usermode coredump helper
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
commit b5325b2a270fcaf7b2a9a0f23d422ca8a5a8bdea upstream.
Give userspace a way to instruct the kernel to install a pidfd into the usermode helper process. This makes coredump handling a lot more reliable for userspace. In parallel with this commit we already have systemd adding support for this in [1].
We create a pidfs file for the coredumping process when we process the corename pattern. When the usermode helper process is forked we then install the pidfs file as file descriptor three into the usermode helpers file descriptor table so it's available to the exec'd program.
Since usermode helpers are either children of the system_unbound_wq workqueue or kthreadd we know that the file descriptor table is empty and can thus always use three as the file descriptor number.
Note, that we'll install a pidfd for the thread-group leader even if a subthread is calling do_coredump(). We know that task linkage hasn't been removed due to delay_group_leader() and even if this @current isn't the actual thread-group leader we know that the thread-group leader cannot be reaped until @current has exited.
[brauner: This is a backport for the v6.1 series. Upstream has significantly changed and backporting all that infra is a non-starter. So simply backport the pidfd_prepare() helper and waste the file descriptor we allocated. Then we minimally massage the umh coredump setup code.]
--- fs/coredump.c | 78 ++++++++++++++++++++++++++++++++++++++++++----- include/linux/coredump.h | 1 2 files changed, 72 insertions(+), 7 deletions(-)
fs/coredump.c +71 -7
@@ -42,6 +42,7 @@#include <linux/timekeeping.h> #include <linux/sysctl.h> #include <linux/elf.h> +#include <uapi/linux/pidfd.h> #include <linux/uaccess.h> #include <asm/mmu_context.h>
@@ -56,6 +57,13 @@static bool dump_vma_snapshot (struct coredump_params *cprm);static void free_vma_snapshot (struct coredump_params *cprm); +/* +* File descriptor number for the pidfd for the thread-group leader of +* the coredumping task installed into the usermode helper's file +* descriptor table. +*/ +#define COREDUMP_PIDFD_NUMBER 3 +static int core_uses_pid;static unsigned int core_pipe_limit;static char core_pattern[CORENAME_MAX_SIZE ] ="core" ;
@@ -325,6 +333,27 @@ static int format_corename(struct core_n err =cn_printf (cn,"%lu" ,rlimit (RLIMIT_CORE ));break ; +/* pidfd number */ +case 'F' : { +/* +* Installing a pidfd only makes sense if +* we actually spawn a usermode helper. +*/ +if (!ispipe) +break ; + +/* +* Note that we'll install a pidfd for the +* thread-group leader. We know that task +* linkage hasn't been removed yet and even if +* this @current isn't the actual thread-group +* leader we know that the thread-group leader +* cannot be reaped until @current has exited. +*/ + cprm->pid =task_tgid (current); + err =cn_printf (cn,"%d" ,COREDUMP_PIDFD_NUMBER ); +break ; + }default :break ; }
@@ -479,7 +508,7 @@ static void wait_for_dump_helpers(struct }/* -* umh_pipe_setup +* umh_coredump_setup * helper function to customize the process used * to collect the core in userspace. Specifically * it sets up a pipe and installs it as fd 0 (stdin)
@@ -489,27 +518,62 @@ static void wait_for_dump_helpers(struct* is a special value that we use to trap recursive * core dumps */ -static int umh_pipe_setup (struct subprocess_info *info,struct cred *new) +static int umh_coredump_setup (struct subprocess_info *info,struct cred *new) {struct file *files[2 ]; +struct file *pidfs_file =NULL ;struct coredump_params *cp = (struct coredump_params *)info->data;int err; +if (cp->pid) { +int fd; + + fd =pidfd_prepare (cp->pid,0 , &pidfs_file); +if (fd <0 ) +return fd; + +/* +* We don't care about the fd. We also cannot simply +* replace it below because dup2() will refuse to close +* this file descriptor if its in a larval state. So +* close it! +*/ +put_unused_fd (fd); + +/* +* Usermode helpers are childen of either +* system_unbound_wq or of kthreadd. So we know that +* we're starting off with a clean file descriptor +* table. So we should always be able to use +* COREDUMP_PIDFD_NUMBER as our file descriptor value. +*/ + err =replace_fd (COREDUMP_PIDFD_NUMBER , pidfs_file,0 ); +if (err <0 ) + goto out_fail; + + pidfs_file =NULL ; + } + err =create_pipe_files (files,0 );if (err) -return err; + goto out_fail; cp->file = files[1 ]; err =replace_fd (0 , files[0 ],0 );fput (files[0 ]);if (err <0 ) -return err; + goto out_fail;/* and disallow core files too */ current->signal->rlim[RLIMIT_CORE ] = (struct rlimit ){1 ,1 }; -return 0 ; + err =0 ; + +out_fail: +if (pidfs_file) +fput (pidfs_file); +return err; }void do_coredump (const kernel_siginfo_t *siginfo)
@@ -585,7 +649,7 @@ void do_coredump(const kernel_siginfo_t }if (cprm.limit ==1 ) { -/* See umh_pipe_setup() which sets RLIMIT_CORE = 1. +/* See umh_coredump_setup() which sets RLIMIT_CORE = 1. * * Normally core limits are irrelevant to pipes, since * we're not writing to the file system, but we use
@@ -630,7 +694,7 @@ void do_coredump(const kernel_siginfo_t retval = -ENOMEM ; sub_info =call_usermodehelper_setup (helper_argv[0 ], helper_argv,NULL ,GFP_KERNEL , - umh_pipe_setup,NULL , &cprm); + umh_coredump_setup,NULL , &cprm);if (sub_info) retval =call_usermodehelper_exec (sub_info,UMH_WAIT_EXEC );
include/linux/coredump.h +1 -0
@@ -28,6 +28,7 @@ struct coredump_params {int vma_count;size_t vma_data_size;struct core_vma_metadata *vma_meta; +struct pid *pid; };/*
Greg Kroah-Hartman
maintainerPATCH 316/325 HID: quirks: Add ADATA XPG alpha wireless mouse support
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Milton Barrera <[email protected]>
[ Upstream commit fa9fdeea1b7d6440c22efa6d59a769eae8bc89f1 ]
This patch adds HID_QUIRK_ALWAYS_POLL for the ADATA XPG wireless gaming mouse (USB ID 125f:7505) and its USB dongle (USB ID 125f:7506). Without this quirk, the device does not generate input events properly.
--- drivers/hid/hid-ids.h | 4 ++++ drivers/hid/hid-quirks.c | 2 ++ 2 files changed, 6 insertions(+)
drivers/hid/hid-ids.h +4 -0
@@ -41,6 +41,10 @@#define USB_VENDOR_ID_ACTIONSTAR 0x2101#define USB_DEVICE_ID_ACTIONSTAR_1011 0x1011 +#define USB_VENDOR_ID_ADATA_XPG 0x125f +#define USB_VENDOR_ID_ADATA_XPG_WL_GAMING_MOUSE 0x7505 +#define USB_VENDOR_ID_ADATA_XPG_WL_GAMING_MOUSE_DONGLE 0x7506 +#define USB_VENDOR_ID_ADS_TECH 0x06e1#define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155
drivers/hid/hid-quirks.c +2 -0
@@ -27,6 +27,8 @@static const struct hid_device_id hid_quirks[] = { {HID_USB_DEVICE (USB_VENDOR_ID_AASHIMA ,USB_DEVICE_ID_AASHIMA_GAMEPAD ),HID_QUIRK_BADPAD }, {HID_USB_DEVICE (USB_VENDOR_ID_AASHIMA ,USB_DEVICE_ID_AASHIMA_PREDATOR ),HID_QUIRK_BADPAD }, + {HID_USB_DEVICE (USB_VENDOR_ID_ADATA_XPG ,USB_VENDOR_ID_ADATA_XPG_WL_GAMING_MOUSE ),HID_QUIRK_ALWAYS_POLL }, + {HID_USB_DEVICE (USB_VENDOR_ID_ADATA_XPG ,USB_VENDOR_ID_ADATA_XPG_WL_GAMING_MOUSE_DONGLE ),HID_QUIRK_ALWAYS_POLL }, {HID_USB_DEVICE (USB_VENDOR_ID_AFATECH ,USB_DEVICE_ID_AFATECH_AF9016 ),HID_QUIRK_FULLSPEED_INTERVAL }, {HID_USB_DEVICE (USB_VENDOR_ID_AIREN ,USB_DEVICE_ID_AIREN_SLIMPLUS ),HID_QUIRK_NOGET }, {HID_USB_DEVICE (USB_VENDOR_ID_AKAI_09E8 ,USB_DEVICE_ID_AKAI_09E8_MIDIMIX ),HID_QUIRK_NO_INIT_REPORTS },
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 317/325 nfs: dont share pNFS DS connections between net namespaces
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 6b9785dc8b13d9fb75ceec8cf4ea7ec3f3b1edbc ]
Currently, different NFS clients can share the same DS connections, even when they are in different net namespaces. If a containerized client creates a DS connection, another container can find and use it. When the first client exits, the connection will close which can lead to stalls in other clients.
Add a net namespace pointer to struct nfs4_pnfs_ds, and compare those value to the caller's netns in _data_server_lookup_locked() when searching for a nfs4_pnfs_ds to match.
--- fs/nfs/filelayout/filelayoutdev.c | 6 +++--- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 6 +++--- fs/nfs/pnfs.h | 4 +++- fs/nfs/pnfs_nfs.c | 9 +++++---- 4 files changed, 14 insertions(+), 11 deletions(-)
fs/nfs/filelayout/filelayoutdev.c +3 -3
@@ -75,6 +75,7 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,struct page *scratch;struct list_head dsaddrs;struct nfs4_pnfs_ds_addr *da; +struct net *net = server->nfs_client->cl_net;/* set up xdr stream */ scratch =alloc_page (gfp_flags);
@@ -158,8 +159,7 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, mp_count =be32_to_cpup (p);/* multipath count */ for (j =0 ; j < mp_count; j++) { - da =nfs4_decode_mp_ds_addr (server->nfs_client->cl_net, - &stream, gfp_flags); + da =nfs4_decode_mp_ds_addr (net, &stream, gfp_flags);if (da)list_add_tail (&da->da_node, &dsaddrs); }
@@ -169,7 +169,7 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, goto out_err_free_deviceid; } - dsaddr->ds_list[i] =nfs4_pnfs_ds_add (&dsaddrs, gfp_flags); + dsaddr->ds_list[i] =nfs4_pnfs_ds_add (net, &dsaddrs, gfp_flags);if (!dsaddr->ds_list[i]) goto out_err_drain_dsaddrs;
fs/nfs/flexfilelayout/flexfilelayoutdev.c +3 -3
@@ -49,6 +49,7 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,struct nfs4_pnfs_ds_addr *da;struct nfs4_ff_layout_ds *new_ds =NULL ;struct nfs4_ff_ds_version *ds_versions =NULL ; +struct net *net = server->nfs_client->cl_net;u32 mp_count;u32 version_count;__be32 *p;
@@ -80,8 +81,7 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,for (i =0 ; i < mp_count; i++) {/* multipath ds */ - da =nfs4_decode_mp_ds_addr (server->nfs_client->cl_net, - &stream, gfp_flags); + da =nfs4_decode_mp_ds_addr (net, &stream, gfp_flags);if (da)list_add_tail (&da->da_node, &dsaddrs); }
@@ -149,7 +149,7 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, new_ds->ds_versions = ds_versions; new_ds->ds_versions_cnt = version_count; - new_ds->ds =nfs4_pnfs_ds_add (&dsaddrs, gfp_flags); + new_ds->ds =nfs4_pnfs_ds_add (net, &dsaddrs, gfp_flags);if (!new_ds->ds) goto out_err_drain_dsaddrs;
fs/nfs/pnfs.h +3 -1
@@ -59,6 +59,7 @@ struct nfs4_pnfs_ds {struct list_head ds_node;/* nfs4_pnfs_dev_hlist dev_dslist */ char *ds_remotestr;/* comma sep list of addrs */ struct list_head ds_addrs; +const struct net *ds_net;struct nfs_client *ds_clp;refcount_t ds_count;unsigned long ds_state;
@@ -405,7 +406,8 @@ int pnfs_generic_commit_pagelist(struct inode *inode,int pnfs_generic_scan_commit_lists (struct nfs_commit_info *cinfo,int max);void pnfs_generic_write_commit_done (struct rpc_task *task,void *data);void nfs4_pnfs_ds_put (struct nfs4_pnfs_ds *ds); -struct nfs4_pnfs_ds *nfs4_pnfs_ds_add (struct list_head *dsaddrs, +struct nfs4_pnfs_ds *nfs4_pnfs_ds_add (const struct net *net, +struct list_head *dsaddrs,gfp_t gfp_flags);void nfs4_pnfs_v3_ds_connect_unload (void ); int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds,
fs/nfs/pnfs_nfs.c +5 -4
@@ -651,12 +651,12 @@ _same_data_server_addrs_locked(const struct list_head *dsaddrs1,* Lookup DS by addresses. nfs4_ds_cache_lock is held */ static struct nfs4_pnfs_ds * -_data_server_lookup_locked (const struct list_head *dsaddrs) +_data_server_lookup_locked (const struct net *net,const struct list_head *dsaddrs) {struct nfs4_pnfs_ds *ds;list_for_each_entry (ds, &nfs4_data_server_cache, ds_node) -if (_same_data_server_addrs_locked (&ds->ds_addrs, dsaddrs)) +if (ds->ds_net == net &&_same_data_server_addrs_locked (&ds->ds_addrs, dsaddrs))return ds;return NULL ; }
@@ -763,7 +763,7 @@ nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags)* uncached and return cached struct nfs4_pnfs_ds. */ struct nfs4_pnfs_ds * -nfs4_pnfs_ds_add (struct list_head *dsaddrs,gfp_t gfp_flags) +nfs4_pnfs_ds_add (const struct net *net,struct list_head *dsaddrs,gfp_t gfp_flags) {struct nfs4_pnfs_ds *tmp_ds, *ds =NULL ;char *remotestr;
@@ -781,13 +781,14 @@ nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags) remotestr =nfs4_pnfs_remotestr (dsaddrs, gfp_flags);spin_lock (&nfs4_ds_cache_lock); - tmp_ds =_data_server_lookup_locked (dsaddrs); + tmp_ds =_data_server_lookup_locked (net, dsaddrs);if (tmp_ds ==NULL ) {INIT_LIST_HEAD (&ds->ds_addrs);list_splice_init (dsaddrs, &ds->ds_addrs); ds->ds_remotestr = remotestr;refcount_set (&ds->ds_count,1 );INIT_LIST_HEAD (&ds->ds_node); + ds->ds_net = net; ds->ds_clp =NULL ;list_add (&ds->ds_node, &nfs4_data_server_cache); dprintk("%s add new data server %s\n", __func__,
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 318/325 platform/x86: thinkpad_acpi: Support also NEC Lavie X1475JAS
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Chau <[email protected]>
[ Upstream commit a032f29a15412fab9f4352e0032836d51420a338 ]
Change get_thinkpad_model_data() to check for additional vendor name "NEC" in order to support NEC Lavie X1475JAS notebook (and perhaps more).
The reason of this works with minimal changes is because NEC Lavie X1475JAS is a Thinkpad inside. ACPI dumps reveals its OEM ID to be "LENOVO", BIOS version "R2PET30W" matches typical Lenovo BIOS version, the existence of HKEY of LEN0268, with DMI fw string is "R2PHT24W".
I compiled and tested with my own machine, attached the dmesg below as proof of work:
[ 6.288932] thinkpad_acpi: ThinkPad ACPI Extras v0.26 [ 6.288937] thinkpad_acpi: http://ibm-acpi.sf.net/ [ 6.288938] thinkpad_acpi: ThinkPad BIOS R2PET30W (1.11 ), EC R2PHT24W [ 6.307000] thinkpad_acpi: radio switch found; radios are enabled [ 6.307030] thinkpad_acpi: This ThinkPad has standard ACPI backlight brightness control, supported by the ACPI video driver [ 6.307033] thinkpad_acpi: Disabling thinkpad-acpi brightness events by default... [ 6.320322] thinkpad_acpi: rfkill switch tpacpi_bluetooth_sw: radio is unblocked [ 6.371963] thinkpad_acpi: secondary fan control detected & enabled [ 6.391922] thinkpad_acpi: battery 1 registered (start 0, stop 85, behaviours: 0x7) [ 6.398375] input: ThinkPad Extra Buttons as /devices/platform/thinkpad_acpi/input/input13
--- drivers/platform/x86/thinkpad_acpi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +2 -0
@@ -11517,6 +11517,8 @@ static int __must_check __init get_thinkpad_model_data( tp->vendor =PCI_VENDOR_ID_IBM ; else if (dmi_name_in_vendors("LENOVO")) tp->vendor =PCI_VENDOR_ID_LENOVO ; + else if (dmi_name_in_vendors("NEC")) + tp->vendor =PCI_VENDOR_ID_LENOVO ; else return 0;
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 319/325 um: let make clean properly clean underlying SUBARCH as well
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masahiro Yamada <[email protected]>
[ Upstream commit ab09da75700e9d25c7dfbc7f7934920beb5e39b9 ]
Building the kernel with O= is affected by stale in-tree build artifacts.
So, if the source tree is not clean, Kbuild displays the following:
$ make ARCH=um O=build defconfig make[1]: Entering directory '/.../linux/build' *** *** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /.../linux *** make[2]: *** [/.../linux/Makefile:673: outputmakefile] Error 1 make[1]: *** [/.../linux/Makefile:248: __sub-make] Error 2 make[1]: Leaving directory '/.../linux/build' make: *** [Makefile:248: __sub-make] Error 2
Usually, running 'make mrproper' is sufficient for cleaning the source tree for out-of-tree builds.
However, building UML generates build artifacts not only in arch/um/, but also in the SUBARCH directory (i.e., arch/x86/). If in-tree stale files remain under arch/x86/, Kbuild will reuse them instead of creating new ones under the specified build directory.
This commit makes 'make ARCH=um clean' recurse into the SUBARCH directory.
--- arch/um/Makefile | 1 + 1 file changed, 1 insertion(+)
arch/um/Makefile +1 -0
@@ -155,5 +155,6 @@ MRPROPER_FILES += $(HOST_DIR)/include/generated archclean: @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ -o -name '*.gcov' \) -type f -print | xargs rm -f + $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) clean export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS DEV_NULL_PATH
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 320/325 spi: spi-sun4i: fix early activation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alessandro Grassi <[email protected]>
[ Upstream commit fb98bd0a13de2c9d96cb5c00c81b5ca118ac9d71 ]
The SPI interface is activated before the CPOL setting is applied. In that moment, the clock idles high and CS goes low. After a short delay, CPOL and other settings are applied, which may cause the clock to change state and idle low. This transition is not part of a clock cycle, and it can confuse the receiving device.
To prevent this unexpected transition, activate the interface while CPOL and the other settings are being applied.
--- drivers/spi/spi-sun4i.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/spi/spi-sun4i.c +4 -1
@@ -263,6 +263,9 @@ static int sun4i_spi_transfer_one(struct spi_master *master,else reg |=SUN4I_CTL_DHB ; +/* Now that the settings are correct, enable the interface */ + reg |=SUN4I_CTL_ENABLE ; +sun4i_spi_write (sspi,SUN4I_CTL_REG , reg);/* Ensure that we have a parent clock fast enough */
@@ -403,7 +406,7 @@ static int sun4i_spi_runtime_resume(struct device *dev) }sun4i_spi_write (sspi,SUN4I_CTL_REG , -SUN4I_CTL_ENABLE |SUN4I_CTL_MASTER |SUN4I_CTL_TP ); +SUN4I_CTL_MASTER |SUN4I_CTL_TP );return 0 ;
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 321/325 nvme-pci: add NVME_QUIRK_NO_DEEPEST_PS quirk for SOLIDIGM P44 Pro
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Guterman <[email protected]>
[ Upstream commit e765bf89f42b5c82132a556b630affeb82b2a21f ]
This commit adds the NVME_QUIRK_NO_DEEPEST_PS quirk for device [126f:2262], which belongs to device SOLIDIGM P44 Pro SSDPFKKW020X7
The device frequently have trouble exiting the deepest power state (5), resulting in the entire disk being unresponsive.
Verified by setting nvme_core.default_ps_max_latency_us=10000 and observing the expected behavior.
--- drivers/nvme/host/pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/host/pci.c +2 -0
@@ -3592,6 +3592,8 @@ static const struct pci_device_id nvme_id_table[] = { .driver_data = NVME_QUIRK_NO_DEEPEST_PS, }, { PCI_DEVICE(0x1e49, 0x0041), /* ZHITAI TiPro7000 NVMe SSD */ .driver_data = NVME_QUIRK_NO_DEEPEST_PS, }, + { PCI_DEVICE(0x025e, 0xf1ac), /* SOLIDIGM P44 pro SSDPFKKW020X7 */ + .driver_data = NVME_QUIRK_NO_DEEPEST_PS, }, { PCI_DEVICE(0xc0a9, 0x540a), /* Crucial P2 */ .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1d97, 0x2263), /* Lexar NM610 */
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 322/325 NFS: Avoid flushing data while holding directory locks in nfs_rename()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
[ Upstream commit dcd21b609d4abc7303f8683bce4f35d78d7d6830 ]
The Linux client assumes that all filehandles are non-volatile for renames within the same directory (otherwise sillyrename cannot work). However, the existence of the Linux 'subtree_check' export option has meant that nfs_rename() has always assumed it needs to flush writes before attempting to rename.
Since NFSv4 does allow the client to query whether or not the server exhibits this behaviour, and since knfsd does actually set the appropriate flag when 'subtree_check' is enabled on an export, it should be OK to optimise away the write flushing behaviour in the cases where it is clearly not needed.
--- fs/nfs/client.c | 2 ++ fs/nfs/dir.c | 15 ++++++++++++++- include/linux/nfs_fs_sb.h | 12 +++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-)
fs/nfs/client.c +2 -0
@@ -1052,6 +1052,8 @@ struct nfs_server *nfs_create_server(struct fs_context *fc)if (server->namelen ==0 || server->namelen >NFS2_MAXNAMLEN ) server->namelen =NFS2_MAXNAMLEN ; } +/* Linux 'subtree_check' borkenness mandates this setting */ + server->fh_expire_type =NFS_FH_VOL_RENAME ;if (!(fattr->valid &NFS_ATTR_FATTR )) { error = ctx->nfs_mod->rpc_ops->getattr(server, ctx->mntfh,
fs/nfs/dir.c +14 -1
@@ -2632,6 +2632,18 @@ nfs_unblock_rename(struct rpc_task *task, struct nfs_renamedata *data)unblock_revalidate (new_dentry); } +static bool nfs_rename_is_unsafe_cross_dir (struct dentry *old_dentry, +struct dentry *new_dentry) +{ +struct nfs_server *server =NFS_SB (old_dentry->d_sb); + +if (old_dentry->d_parent != new_dentry->d_parent) +return false; +if (server->fh_expire_type &NFS_FH_RENAME_UNSAFE ) +return !(server->fh_expire_type &NFS_FH_NOEXPIRE_WITH_OPEN ); +return true; +} +/* * RENAME * FIXME: Some nfsds, like the Linux user space nfsd, may generate a
@@ -2719,7 +2731,8 @@ int nfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir, } -if (S_ISREG (old_inode->i_mode)) +if (S_ISREG (old_inode->i_mode) && +nfs_rename_is_unsafe_cross_dir (old_dentry, new_dentry))nfs_sync_inode (old_inode); task =nfs_async_rename (old_dir, new_dir, old_dentry, new_dentry, must_unblock ? nfs_unblock_rename :NULL );
include/linux/nfs_fs_sb.h +9 -3
@@ -196,6 +196,15 @@ struct nfs_server {char *fscache_uniq;/* Uniquifier (or NULL) */ #endif +/* The following #defines numerically match the NFSv4 equivalents */ +#define NFS_FH_NOEXPIRE_WITH_OPEN (0x1) +#define NFS_FH_VOLATILE_ANY (0x2) +#define NFS_FH_VOL_MIGRATION (0x4) +#define NFS_FH_VOL_RENAME (0x8) +#define NFS_FH_RENAME_UNSAFE (NFS_FH_VOLATILE_ANY | NFS_FH_VOL_RENAME) +u32 fh_expire_type;/* V4 bitmask representing file +handle volatility type for +this filesystem */ u32 pnfs_blksize;/* layout_blksize attr */ #if IS_ENABLED (CONFIG_NFS_V4 )u32 attr_bitmask[3 ];/* V4 bitmask representing the set
@@ -219,9 +228,6 @@ struct nfs_server {u32 acl_bitmask;/* V4 bitmask representing the ACEs that are supported on this filesystem */ -u32 fh_expire_type;/* V4 bitmask representing file -handle volatility type for -this filesystem */ struct pnfs_layoutdriver_type *pnfs_curr_ld;/* Active layout driver */ struct rpc_wait_queue roc_rpcwaitq;void *pnfs_ld_data;/* per mount point data */
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 323/325 platform/x86: fujitsu-laptop: Support Lifebook S2110 hotkeys
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valtteri Koskivuori <[email protected]>
[ Upstream commit a7e255ff9fe4d9b8b902023aaf5b7a673786bb50 ]
The S2110 has an additional set of media playback control keys enabled by a hardware toggle button that switches the keys between "Application" and "Player" modes. Toggling "Player" mode just shifts the scancode of each hotkey up by 4.
Add defines for new scancodes, and a keymap and dmi id for the S2110.
Tested on a Fujitsu Lifebook S2110.
--- drivers/platform/x86/fujitsu-laptop.c | 33 +++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/platform/x86/fujitsu-laptop.c +29 -4
@@ -17,13 +17,13 @@/* * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional * features made available on a range of Fujitsu laptops including the -* P2xxx/P5xxx/S6xxx/S7xxx series. +* P2xxx/P5xxx/S2xxx/S6xxx/S7xxx series. * * This driver implements a vendor-specific backlight control interface for * Fujitsu laptops and provides support for hotkeys present on certain Fujitsu * laptops. * -* This driver has been tested on a Fujitsu Lifebook S6410, S7020 and +* This driver has been tested on a Fujitsu Lifebook S2110, S6410, S7020 and * P8010. It should work on most P-series and S-series Lifebooks, but * YMMV. *
@@ -102,7 +102,11 @@#define KEY2_CODE 0x411#define KEY3_CODE 0x412#define KEY4_CODE 0x413 -#define KEY5_CODE 0x420 +#define KEY5_CODE 0x414 +#define KEY6_CODE 0x415 +#define KEY7_CODE 0x416 +#define KEY8_CODE 0x417 +#define KEY9_CODE 0x420/* Hotkey ringbuffer limits */ #define MAX_HOTKEY_RINGBUFFER_SIZE 100
@@ -450,7 +454,7 @@ static const struct key_entry keymap_default[] = { { KE_KEY, KEY2_CODE, { KEY_PROG2 } }, { KE_KEY, KEY3_CODE, { KEY_PROG3 } }, { KE_KEY, KEY4_CODE, { KEY_PROG4 } }, - { KE_KEY, KEY5_CODE, { KEY_RFKILL } }, + { KE_KEY, KEY9_CODE, { KEY_RFKILL } },/* Soft keys read from status flags */ { KE_KEY, FLAG_RFKILL, { KEY_RFKILL } }, { KE_KEY, FLAG_TOUCHPAD_TOGGLE, { KEY_TOUCHPAD_TOGGLE } },
@@ -474,6 +478,18 @@ static const struct key_entry keymap_p8010[] = { { KE_END, 0 } }; +static const struct key_entry keymap_s2110[] = { + {KE_KEY ,KEY1_CODE , {KEY_PROG1 } },/* "A" */ + {KE_KEY ,KEY2_CODE , {KEY_PROG2 } },/* "B" */ + {KE_KEY ,KEY3_CODE , {KEY_WWW } },/* "Internet" */ + {KE_KEY ,KEY4_CODE , {KEY_EMAIL } },/* "E-mail" */ + {KE_KEY ,KEY5_CODE , {KEY_STOPCD } }, + {KE_KEY ,KEY6_CODE , {KEY_PLAYPAUSE } }, + {KE_KEY ,KEY7_CODE , {KEY_PREVIOUSSONG } }, + {KE_KEY ,KEY8_CODE , {KEY_NEXTSONG } }, + {KE_END ,0 } +}; +static const struct key_entry *keymap = keymap_default;static int fujitsu_laptop_dmi_keymap_override (const struct dmi_system_id *id)
@@ -511,6 +527,15 @@ static const struct dmi_system_id fujitsu_laptop_dmi_table[] = { }, .driver_data = (void *)keymap_p8010 }, + { + .callback = fujitsu_laptop_dmi_keymap_override, + .ident = "Fujitsu LifeBook S2110", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), + DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S2110"), + }, + .driver_data = (void *)keymap_s2110 + }, {} };
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 324/325 platform/x86: thinkpad_acpi: Ignore battery threshold change event notification
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Pearson <[email protected]>
[ Upstream commit 29e4e6b4235fefa5930affb531fe449cac330a72 ]
If user modifies the battery charge threshold an ACPI event is generated. Confirmed with Lenovo FW team this is only generated on user event. As no action is needed, ignore the event and prevent spurious kernel logs.
--- drivers/platform/x86/thinkpad_acpi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +5 -0
@@ -211,6 +211,7 @@ enum tpacpi_hkey_event_t {/* Thermal events */ TP_HKEY_EV_ALARM_BAT_HOT =0x6011 ,/* battery too hot */ TP_HKEY_EV_ALARM_BAT_XHOT =0x6012 ,/* battery critically hot */ +TP_HKEY_EV_ALARM_BAT_LIM_CHANGE =0x6013 ,/* battery charge limit changed*/ TP_HKEY_EV_ALARM_SENSOR_HOT =0x6021 ,/* sensor too hot */ TP_HKEY_EV_ALARM_SENSOR_XHOT =0x6022 ,/* sensor critically hot */ TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* windows; thermal table changed */
@@ -3948,6 +3949,10 @@ static bool hotkey_notify_6xxx(const u32 hkey,pr_alert ("THERMAL EMERGENCY: battery is extremely hot!\n" );/* recommended action: immediate sleep/hibernate */ break ; +case TP_HKEY_EV_ALARM_BAT_LIM_CHANGE : +pr_debug ("Battery Info: battery charge threshold changed\n" ); +/* User changed charging threshold. No action needed */ +return true;case TP_HKEY_EV_ALARM_SENSOR_HOT :pr_crit ("THERMAL ALARM: a sensor reports something is too hot!\n" );/* recommended action: warn user through gui, that */
Signature · 1 line
2.39.5
Greg Kroah-Hartman
maintainerPATCH 325/325 net: ethernet: ti: am65-cpsw: Lower random mac address error print to info
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nishanth Menon <[email protected]>
[ Upstream commit 50980d8da71a0c2e045e85bba93c0099ab73a209 ]
Using random mac address is not an error since the driver continues to function, it should be informative that the system has not assigned a MAC address. This is inline with other drivers such as ax88796c, dm9051 etc. Drop the error level to info level.
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +1 -1
@@ -1918,7 +1918,7 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common) port->slave.mac_addr);if (!is_valid_ether_addr (port->slave.mac_addr)) {eth_random_addr (port->slave.mac_addr); -dev_err (dev,"Use random MAC address\n" ); +dev_info (dev,"Use random MAC address\n" ); } } }
Signature · 1 line
2.39.5
Am 02.06.2025 um 15:44 schrieb Greg Kroah-Hartman:
Quoted 4 lines
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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]
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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 Wed, 04 Jun 2025 13:42:20 +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.1.141-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels, build tested on BMIPS_GENERIC:
Signature · 1 line
Florian
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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 Wed, 04 Jun 2025 13:42:20 +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.1.141-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
Built and booted successfully on RISC-V RV64 (HiFive Unmatched).
Quoted 10 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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 Wed, 04 Jun 2025 13:42:20 +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.1.141-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
Results from Linaro’s test farm.
No regressions on arm64, arm, x86_64, and i386.
## Build
* kernel: 6.1.141-rc1
* git: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
* git commit: 1c3f3a4d0cca7742a95419a6c91fff4326a2de1c
* git describe: v6.1.140-326-g1c3f3a4d0cca
* test details:
https://qa-reports.linaro.org/lkft/linux-stable-rc-linux-6.1.y/build/v6.1.140-326-g1c3f3a4d0cca
## Test Regressions (compared to v6.1.139-98-g1fb2f21fca77)
## Metric Regressions (compared to v6.1.139-98-g1fb2f21fca77)
## Test Fixes (compared to v6.1.139-98-g1fb2f21fca77)
## Metric Fixes (compared to v6.1.139-98-g1fb2f21fca77)
## Test result summary
total: 219869, pass: 201359, fail: 3409, skip: 14877, xfail: 224
## Build Summary
* arc: 5 total, 5 passed, 0 failed
* arm: 133 total, 133 passed, 0 failed
* arm64: 41 total, 41 passed, 0 failed
* i386: 21 total, 21 passed, 0 failed
* mips: 26 total, 25 passed, 1 failed
* parisc: 4 total, 4 passed, 0 failed
* powerpc: 32 total, 31 passed, 1 failed
* riscv: 11 total, 11 passed, 0 failed
* s390: 14 total, 14 passed, 0 failed
* sh: 10 total, 10 passed, 0 failed
* sparc: 7 total, 7 passed, 0 failed
* x86_64: 33 total, 33 passed, 0 failed
## Test suites summary
* boot
* commands
* kselftest-arm64
* kselftest-breakpoints
* kselftest-capabilities
* kselftest-clone3
* kselftest-core
* kselftest-cpu-hotplug
* kselftest-exec
* kselftest-fpu
* kselftest-futex
* kselftest-intel_pstate
* kselftest-kcmp
* kselftest-kvm
* kselftest-livepatch
* kselftest-membarrier
* kselftest-mincore
* kselftest-mqueue
* kselftest-openat2
* kselftest-ptrace
* kselftest-rseq
* kselftest-rtc
* kselftest-sigaltstack
* kselftest-size
* kselftest-timers
* kselftest-tmpfs
* kselftest-tpm2
* kselftest-user_events
* kselftest-vDSO
* kselftest-x86
* kunit
* kvm-unit-tests
* lava
* libgpiod
* libhugetlbfs
* log-parser-boot
* log-parser-build-clang
* log-parser-build-gcc
* log-parser-test
* ltp-capability
* ltp-commands
* ltp-containers
* ltp-controllers
* ltp-cpuhotplug
* ltp-crypto
* ltp-cve
* ltp-dio
* ltp-fcntl-locktests
* ltp-fs
* ltp-fs_bind
* ltp-fs_perms_simple
* ltp-hugetlb
* ltp-ipc
* ltp-math
* ltp-mm
* ltp-nptl
* ltp-pty
* ltp-sched
* ltp-smoke
* ltp-syscalls
* ltp-tracing
* modules
* perf
* rcutorture
--
Linaro LKFT
https://lkft.linaro.org
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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.1.y
Best regards,
Pavel
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Erika Unter HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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 Wed, 04 Jun 2025 13:42:20 +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.1.141-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Quoted 4 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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.
Quoted 8 lines · On Mon, 02 Jun 2025 15:44:36 +0200 Greg Kroah-Hartman…
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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 Wed, 04 Jun 2025 13:42:20 +0000. Anything received after that time might be too late.
Boot-tested under QEMU for Rust x86_64:
Thanks!
Cheers,
Miguel
The kernel, bpf tool, and perf tool builds fine for v6.1.141-rc1 on x86 and arm64 Azure VM.
Kernel binary size for x86 build:
text data bss dec hex filename 25847143 11304250 16613376 53764769 33462a1 vmlinux
Kernel binary size for arm64 build:
text data bss dec hex filename 31273699 12549552 831088 44654339 2a95f03 vmlinux
Thanks,
Hardik
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.141 release. There are 325 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 Wed, 04 Jun 2025 13:42:20 +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.1.141-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
All tests passing for Tegra ...
Test results for stable-v6.1:
10 builds: 10 pass, 0 fail
28 boots: 28 pass, 0 fail
115 tests: 115 pass, 0 failLinux version: 6.1.141-rc1-g1c3f3a4d0cca
Boards tested: tegra124-jetson-tk1, tegra186-p2771-0000,
tegra186-p3509-0000+p3636-0001, tegra194-p2972-0000,
tegra194-p3509-0000+p3668-0000, tegra20-ventana,
tegra210-p2371-2180, tegra210-p3450-0000,
tegra30-cardhu-a04Jon