5.15.226-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 1206/2214 assoc_array: move node splitting into a function of its own
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 3c99a07bc82b051771ce0eb69274aceb9abf1eb7 ]
Move the code after the do_split_node label into assoc_array_split_node(), which both the split path and the shortcut path still reach through that label.
It sets new_n1's back pointer itself, which both paths did before jumping there, and it no longer sets new_n1's parent slot to -1 first:
it always sets the real one.
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 194 +++++++++++++++++++++++++--------------------- 1 file changed, 104 insertions(+), 90 deletions(-)
lib/assoc_array.c +104 -90
@@ -547,6 +547,106 @@ static bool assoc_array_fill_segment_cache(struct assoc_array_edit *edit,return have_meta; } +/* +* Split a full node into new_n0, which takes its place, and new_n1, below +* new_n0 in the slot of a segment that at least two of the leaves share, +* the new one included. The caller has filled in the segment cache and +* set new_n0's back pointer and parent slot. +*/ +static void assoc_array_split_node (struct assoc_array_edit *edit, +struct assoc_array_node *node, +struct assoc_array_node *new_n0, +struct assoc_array_node *new_n1) +{ +struct assoc_array_shortcut *shortcut; +struct assoc_array_node *side; +struct assoc_array_ptr *ptr; +int slot, next_slot, free_slot, i, j; + +pr_devel ("split node\n" ); + + new_n1->back_pointer =assoc_array_node_to_ptr (new_n0); + new_n0->nr_leaves_on_branch = node->nr_leaves_on_branch; + new_n1->nr_leaves_on_branch =0 ; + +/* Begin by finding two matching leaves. There have to be at least two +* that match - even if there are meta pointers - because any leaf that +* would match a slot with a meta pointer in it must be somewhere +* behind that meta pointer and cannot be here. Further, given N +* remaining leaf slots, we now have N+1 leaves to go in them. +*/ +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { + slot = edit->segment_cache[i]; +if (slot !=0xff ) +for (j = i +1 ; j <ASSOC_ARRAY_FAN_OUT +1 ; j++) +if (edit->segment_cache[j] == slot) + goto found_slot_for_multiple_occupancy; + } +found_slot_for_multiple_occupancy: +pr_devel ("same slot: %x %x [%02x]\n" , i, j, slot); +BUG_ON (i >=ASSOC_ARRAY_FAN_OUT ); +BUG_ON (j >=ASSOC_ARRAY_FAN_OUT +1 ); +BUG_ON (slot >=ASSOC_ARRAY_FAN_OUT ); + + new_n1->parent_slot = slot; + +/* Metadata pointers cannot change slot */ +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) +if (assoc_array_ptr_is_meta (node->slots[i])) + new_n0->slots[i] = node->slots[i]; +else + new_n0->slots[i] =NULL ; +BUG_ON (new_n0->slots[slot] !=NULL ); + new_n0->slots[slot] =assoc_array_node_to_ptr (new_n1); + +/* Filter the leaf pointers between the new nodes */ + free_slot =-1 ; + next_slot =0 ; +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { +if (assoc_array_ptr_is_meta (node->slots[i])) +continue ; +if (edit->segment_cache[i] == slot) { + new_n1->slots[next_slot++] = node->slots[i]; + new_n1->nr_leaves_on_branch++; + }else { +do { + free_slot++; + }while (new_n0->slots[free_slot] !=NULL ); + new_n0->slots[free_slot] = node->slots[i]; + } + } + +pr_devel ("filtered: f=%x n=%x\n" , free_slot, next_slot); + +if (edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] != slot) { +do { + free_slot++; + }while (new_n0->slots[free_slot] !=NULL ); + edit->leaf_p = &new_n0->slots[free_slot]; + edit->adjust_count_on = new_n0; + }else { + edit->leaf_p = &new_n1->slots[next_slot++]; + edit->adjust_count_on = new_n1; + } + +BUG_ON (next_slot <=1 ); + + edit->set_backpointers_to =assoc_array_node_to_ptr (new_n0); +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { +if (edit->segment_cache[i] ==0xff ) { + ptr = node->slots[i]; +BUG_ON (assoc_array_ptr_is_leaf (ptr)); +if (assoc_array_ptr_is_node (ptr)) { + side =assoc_array_ptr_to_node (ptr); + edit->set_backpointers[i] = &side->back_pointer; + }else { + shortcut =assoc_array_ptr_to_shortcut (ptr); + edit->set_backpointers[i] = &shortcut->back_pointer; + } + } + } +} +/* * Handle insertion into a terminal node. */
@@ -555,14 +655,14 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,const void *index_key, struct assoc_array_walk_result *result) { - struct assoc_array_shortcut *shortcut, *new_s0; -struct assoc_array_node *node, *new_n0, *new_n1, *side; + struct assoc_array_shortcut *new_s0; +struct assoc_array_node *node, *new_n0, *new_n1;struct assoc_array_ptr *ptr;unsigned long dissimilarity, base_seg, blank;size_t keylen;bool have_meta;int level, diff; -int slot, next_slot, free_slot, i, j; +int i; node = result->terminal_node.node; level = result->terminal_node.level;
@@ -632,8 +732,6 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, } split_node: -pr_devel ("split node\n" ); -/* We need to split the current node. The node must contain anything * from a single leaf (in the one leaf case, this leaf will cluster * with the new leaf) and the rest meta-pointers, to all leaves, some
@@ -652,91 +750,9 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, edit->set[0 ].to =assoc_array_node_to_ptr (new_n0); new_n0->back_pointer = node->back_pointer; new_n0->parent_slot = node->parent_slot; - new_n1->back_pointer =assoc_array_node_to_ptr (new_n0); - new_n1->parent_slot =-1 ;/* Need to calculate this */ do_split_node: -pr_devel ("do_split_node\n" ); - - new_n0->nr_leaves_on_branch = node->nr_leaves_on_branch; - new_n1->nr_leaves_on_branch =0 ; - -/* Begin by finding two matching leaves. There have to be at least two -* that match - even if there are meta pointers - because any leaf that -* would match a slot with a meta pointer in it must be somewhere -* behind that meta pointer and cannot be here. Further, given N -* remaining leaf slots, we now have N+1 leaves to go in them. -*/ -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { - slot = edit->segment_cache[i]; -if (slot !=0xff ) -for (j = i +1 ; j <ASSOC_ARRAY_FAN_OUT +1 ; j++) -if (edit->segment_cache[j] == slot) - goto found_slot_for_multiple_occupancy; - } -found_slot_for_multiple_occupancy: -pr_devel ("same slot: %x %x [%02x]\n" , i, j, slot); -BUG_ON (i >=ASSOC_ARRAY_FAN_OUT ); -BUG_ON (j >=ASSOC_ARRAY_FAN_OUT +1 ); -BUG_ON (slot >=ASSOC_ARRAY_FAN_OUT ); - - new_n1->parent_slot = slot; - -/* Metadata pointers cannot change slot */ -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) -if (assoc_array_ptr_is_meta (node->slots[i])) - new_n0->slots[i] = node->slots[i]; -else - new_n0->slots[i] =NULL ; -BUG_ON (new_n0->slots[slot] !=NULL ); - new_n0->slots[slot] =assoc_array_node_to_ptr (new_n1); - -/* Filter the leaf pointers between the new nodes */ - free_slot =-1 ; - next_slot =0 ; -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { -if (assoc_array_ptr_is_meta (node->slots[i])) -continue ; -if (edit->segment_cache[i] == slot) { - new_n1->slots[next_slot++] = node->slots[i]; - new_n1->nr_leaves_on_branch++; - }else { -do { - free_slot++; - }while (new_n0->slots[free_slot] !=NULL ); - new_n0->slots[free_slot] = node->slots[i]; - } - } - -pr_devel ("filtered: f=%x n=%x\n" , free_slot, next_slot); - -if (edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] != slot) { -do { - free_slot++; - }while (new_n0->slots[free_slot] !=NULL ); - edit->leaf_p = &new_n0->slots[free_slot]; - edit->adjust_count_on = new_n0; - }else { - edit->leaf_p = &new_n1->slots[next_slot++]; - edit->adjust_count_on = new_n1; - } - -BUG_ON (next_slot <=1 ); - - edit->set_backpointers_to =assoc_array_node_to_ptr (new_n0); -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { -if (edit->segment_cache[i] ==0xff ) { - ptr = node->slots[i]; -BUG_ON (assoc_array_ptr_is_leaf (ptr)); -if (assoc_array_ptr_is_node (ptr)) { - side =assoc_array_ptr_to_node (ptr); - edit->set_backpointers[i] = &side->back_pointer; - }else { - shortcut =assoc_array_ptr_to_shortcut (ptr); - edit->set_backpointers[i] = &shortcut->back_pointer; - } - } - } +assoc_array_split_node (edit, node, new_n0, new_n1); ptr = node->back_pointer;if (!ptr)
@@ -791,8 +807,6 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, new_s0->next_node =assoc_array_node_to_ptr (new_n0); new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); new_n0->parent_slot =0 ; - new_n1->back_pointer =assoc_array_node_to_ptr (new_n0); - new_n1->parent_slot =-1 ;/* Need to calculate this */ new_s0->skip_to_level = level = diff & ~ASSOC_ARRAY_LEVEL_STEP_MASK ;pr_devel ("skip_to_level = %d [diff %d]\n" , level, diff);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1207/2214 assoc_array: move shortcut creation into a function of its own
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit fdc6124c55dd0c5aa8e3ec30e6425b4d423ada24 ]
Move the code after the all_leaves_cluster_together label into assoc_array_insert_shortcut(), which returns the new shortcut, or NULL when it cannot allocate one. The caller installs it and jumps to do_split_node as before.
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 146 ++++++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 64 deletions(-)
lib/assoc_array.c +82 -64
@@ -647,6 +647,84 @@ static void assoc_array_split_node(struct assoc_array_edit *edit, } } +/* +* All the leaves, new and old, want to cluster together in this node in the +* same slot, so we have to replace this node with a shortcut to skip over +* the identical parts of the key, leading to new_n0. The caller then splits +* the leaves between new_n0 and new_n1 at the shortcut's far end, for which +* this fills in the segment cache. +*/ +static struct assoc_array_shortcut * +assoc_array_insert_shortcut (struct assoc_array_edit *edit, +const struct assoc_array_ops *ops, +const void *index_key, +struct assoc_array_node *node,int level, +struct assoc_array_node *new_n0) +{ +struct assoc_array_shortcut *new_s0; +unsigned long base_seg, blank; +size_t keylen; +int diff, i; + +/* Firstly we need to work out where the leaves start diverging as a +* bit position into their keys so that we know how big the shortcut +* needs to be. +* +* We only need to make a single pass of N of the N+1 leaves because if +* any keys differ between themselves at bit X then at least one of +* them must also differ with the base key at bit X or before. +*/ +pr_devel ("all leaves cluster together\n" ); + diff =INT_MAX ; +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { +int x = ops->diff_objects (assoc_array_ptr_to_leaf (node->slots[i]), + index_key); +if (x < diff) { +BUG_ON (x <0 ); + diff = x; + } + } +BUG_ON (diff ==INT_MAX ); +BUG_ON (diff < level +ASSOC_ARRAY_LEVEL_STEP ); + + keylen =round_up (diff,ASSOC_ARRAY_KEY_CHUNK_SIZE ); + keylen >>=ASSOC_ARRAY_KEY_CHUNK_SHIFT ; + + new_s0 =kzalloc (struct_size (new_s0, index_key, keylen),GFP_KERNEL ); +if (!new_s0) +return NULL ; + edit->new_meta[2 ] =assoc_array_shortcut_to_ptr (new_s0); + + new_s0->back_pointer = node->back_pointer; + new_s0->parent_slot = node->parent_slot; + new_s0->next_node =assoc_array_node_to_ptr (new_n0); + new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); + new_n0->parent_slot =0 ; + + new_s0->skip_to_level = level = diff & ~ASSOC_ARRAY_LEVEL_STEP_MASK ; +pr_devel ("skip_to_level = %d [diff %d]\n" , level, diff); +BUG_ON (level <=0 ); + +for (i =0 ; i < keylen; i++) + new_s0->index_key[i] = + ops->get_key_chunk (index_key, i *ASSOC_ARRAY_KEY_CHUNK_SIZE ); + +if (level &ASSOC_ARRAY_KEY_CHUNK_MASK ) { + blank =ULONG_MAX << (level &ASSOC_ARRAY_KEY_CHUNK_MASK ); +pr_devel ("blank off [%zu] %d: %lx\n" , keylen -1 , level, blank); + new_s0->index_key[keylen -1 ] &= ~blank; + } + +/* This now reduces to a node splitting exercise for which we'll need +* to regenerate the disparity table. +*/ +assoc_array_fill_segment_cache (edit, ops, node, level); + base_seg = ops->get_key_chunk (index_key, level); + base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ; + edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = base_seg &ASSOC_ARRAY_FAN_MASK ; +return new_s0; +} +/* * Handle insertion into a terminal node. */
@@ -658,10 +736,9 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,struct assoc_array_shortcut *new_s0;struct assoc_array_node *node, *new_n0, *new_n1;struct assoc_array_ptr *ptr; -unsigned long dissimilarity, base_seg, blank; -size_t keylen; +unsigned long dissimilarity, base_seg;bool have_meta; -int level, diff; +int level;int i; node = result->terminal_node.node;
@@ -766,70 +843,11 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,return true; all_leaves_cluster_together: -/* All the leaves, new and old, want to cluster together in this node -* in the same slot, so we have to replace this node with a shortcut to -* skip over the identical parts of the key and then place a pair of -* nodes, one inside the other, at the end of the shortcut and -* distribute the keys between them. -* -* Firstly we need to work out where the leaves start diverging as a -* bit position into their keys so that we know how big the shortcut -* needs to be. -* -* We only need to make a single pass of N of the N+1 leaves because if -* any keys differ between themselves at bit X then at least one of -* them must also differ with the base key at bit X or before. -*/ -pr_devel ("all leaves cluster together\n" ); - diff =INT_MAX ; -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { -int x = ops->diff_objects (assoc_array_ptr_to_leaf (node->slots[i]), - index_key); -if (x < diff) { -BUG_ON (x <0 ); - diff = x; - } - } -BUG_ON (diff ==INT_MAX ); -BUG_ON (diff < level +ASSOC_ARRAY_LEVEL_STEP ); - - keylen =round_up (diff,ASSOC_ARRAY_KEY_CHUNK_SIZE ); - keylen >>=ASSOC_ARRAY_KEY_CHUNK_SHIFT ; - - new_s0 =kzalloc (struct_size (new_s0, index_key, keylen),GFP_KERNEL ); + new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, + node, level, new_n0);if (!new_s0)return false; - edit->new_meta[2 ] =assoc_array_shortcut_to_ptr (new_s0); - edit->set[0 ].to =assoc_array_shortcut_to_ptr (new_s0); - new_s0->back_pointer = node->back_pointer; - new_s0->parent_slot = node->parent_slot; - new_s0->next_node =assoc_array_node_to_ptr (new_n0); - new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); - new_n0->parent_slot =0 ; - - new_s0->skip_to_level = level = diff & ~ASSOC_ARRAY_LEVEL_STEP_MASK ; -pr_devel ("skip_to_level = %d [diff %d]\n" , level, diff); -BUG_ON (level <=0 ); - -for (i =0 ; i < keylen; i++) - new_s0->index_key[i] = - ops->get_key_chunk (index_key, i *ASSOC_ARRAY_KEY_CHUNK_SIZE ); - -if (level &ASSOC_ARRAY_KEY_CHUNK_MASK ) { - blank =ULONG_MAX << (level &ASSOC_ARRAY_KEY_CHUNK_MASK ); -pr_devel ("blank off [%zu] %d: %lx\n" , keylen -1 , level, blank); - new_s0->index_key[keylen -1 ] &= ~blank; - } - -/* This now reduces to a node splitting exercise for which we'll need -* to regenerate the disparity table. -*/ -assoc_array_fill_segment_cache (edit, ops, node, level); - - base_seg = ops->get_key_chunk (index_key, level); - base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ; - edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = base_seg &ASSOC_ARRAY_FAN_MASK ; goto do_split_node; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1208/2214 assoc_array: choose between splitting a node and a shortcut without gotos
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit c47aee71e14dd28d39fce95af83166d7a28a5f2b ]
With its jobs in functions, assoc_array_insert_into_terminal_node() comes down to one decision: replace the node with a shortcut when every leaf in it and the new key share one segment, or split it otherwise. Write that as an if and an else, in place of the labels split_node, do_split_node and all_leaves_cluster_together.
Each branch now works out where its replacement goes from that replacement's own back pointer and parent slot, with assoc_array_parent_link(), rather than both using the node's. The two are the same today.
None of the new functions is recursive, and gcc inlines all of them into assoc_array_insert(), whose stack frame is 240 bytes after this series against 224 before it, on an x86-64 defconfig.
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 127 ++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 66 deletions(-)
lib/assoc_array.c +61 -66
@@ -469,6 +469,21 @@ static bool assoc_array_insert_in_empty_tree(struct assoc_array_edit *edit)return true; } +/* +* The pointer that leads to a node or shortcut with the given back pointer +* and parent slot: the root, a slot in a node, or a shortcut's next node. +*/ +static struct assoc_array_ptr **assoc_array_parent_link (struct assoc_array *array, +struct assoc_array_ptr *back_pointer, +int parent_slot) +{ +if (!back_pointer) +return &array->root; +if (assoc_array_ptr_is_node (back_pointer)) +return &assoc_array_ptr_to_node (back_pointer)->slots[parent_slot]; +return &assoc_array_ptr_to_shortcut (back_pointer)->next_node; +} +/* * Insert into a terminal node without changing its shape, if that can be * done: in place of a leaf with the same index key, or in a free slot.
@@ -547,6 +562,20 @@ static bool assoc_array_fill_segment_cache(struct assoc_array_edit *edit,return have_meta; } +/* +* Whether the leaves of a full node and the new key all share one segment, +* so that splitting the node cannot make room. +*/ +static bool assoc_array_all_one_segment (const struct assoc_array_edit *edit) +{ +int i; + +for (i =1 ; i <ASSOC_ARRAY_FAN_OUT +1 ; i++) +if (edit->segment_cache[i] != edit->segment_cache[0 ]) +return false; +return true; +} +/* * Split a full node into new_n0, which takes its place, and new_n1, below * new_n0 in the slot of a segment that at least two of the leaves share,
@@ -735,11 +764,8 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, {struct assoc_array_shortcut *new_s0;struct assoc_array_node *node, *new_n0, *new_n1; -struct assoc_array_ptr *ptr; -unsigned long dissimilarity, base_seg;bool have_meta;int level; -int i; node = result->terminal_node.node; level = result->terminal_node.level;
@@ -777,78 +803,47 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, have_meta =assoc_array_fill_segment_cache (edit, ops, node, level); edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = result->terminal_node.slot; -if (have_meta) { -pr_devel ("have meta\n" ); - goto split_node; - } - -/* The node contains only leaves */ - dissimilarity =0 ; - base_seg = edit->segment_cache[0 ]; -for (i =1 ; i <ASSOC_ARRAY_FAN_OUT ; i++) - dissimilarity |= edit->segment_cache[i] ^ base_seg; - -pr_devel ("only leaves; dissimilarity=%lx\n" , dissimilarity); - -if ((dissimilarity &ASSOC_ARRAY_FAN_MASK ) ==0 ) { -/* The old leaves all cluster in the same slot. We will need -* to insert a shortcut if the new node wants to cluster with them. +if (!have_meta &&assoc_array_all_one_segment (edit)) { +/* The node only contains leaves and all the leaves cluster in +* the same slot, so we need to insert a shortcut to skip the +* common portion of the key and split the node at the +* shortcut's far end. */ -if ((edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] ^ base_seg) ==0 ) - goto all_leaves_cluster_together; - -/* Otherwise all the old leaves cluster in the same slot, but -* the new leaf wants to go into a different slot - so we -* create a new node (n0) to hold the new leaf and a pointer to -* a new node (n1) holding all the old leaves. + new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, + node, level, new_n0); +if (!new_s0) +return false; + edit->set[0 ].ptr =assoc_array_parent_link (edit->array, + new_s0->back_pointer, + new_s0->parent_slot); + edit->set[0 ].to =assoc_array_shortcut_to_ptr (new_s0); + }else { +/* We need to split the current node. The node must contain +* anything from a single leaf (in the one leaf case, this leaf +* will cluster with the new leaf) and the rest meta-pointers, +* to all leaves, some of which may cluster. +* +* We need to expel at least two leaves out of a set consisting +* of the leaves in the node and the new leaf. The current meta +* pointers can just be copied as they shouldn't cluster with +* any of the leaves. If all the old leaves cluster in one slot +* and the new leaf does not, they all go and the new leaf stays. * -* This can be done by falling through to the node splitting -* path. +* We need a new node (n0) to replace the current one and a new +* node to take the expelled nodes (n1). */ -pr_devel ("present leaves cluster but not new leaf\n" ); + new_n0->back_pointer = node->back_pointer; + new_n0->parent_slot = node->parent_slot; + edit->set[0 ].ptr =assoc_array_parent_link (edit->array, + new_n0->back_pointer, + new_n0->parent_slot); + edit->set[0 ].to =assoc_array_node_to_ptr (new_n0); } -split_node: -/* We need to split the current node. The node must contain anything -* from a single leaf (in the one leaf case, this leaf will cluster -* with the new leaf) and the rest meta-pointers, to all leaves, some -* of which may cluster. -* -* It won't contain the case in which all the current leaves plus the -* new leaves want to cluster in the same slot. -* -* We need to expel at least two leaves out of a set consisting of the -* leaves in the node and the new leaf. The current meta pointers can -* just be copied as they shouldn't cluster with any of the leaves. -* -* We need a new node (n0) to replace the current one and a new node to -* take the expelled nodes (n1). -*/ - edit->set[0 ].to =assoc_array_node_to_ptr (new_n0); - new_n0->back_pointer = node->back_pointer; - new_n0->parent_slot = node->parent_slot; - -do_split_node:assoc_array_split_node (edit, node, new_n0, new_n1); - - ptr = node->back_pointer; -if (!ptr) - edit->set[0 ].ptr = &edit->array->root; -else if (assoc_array_ptr_is_node (ptr)) - edit->set[0 ].ptr = &assoc_array_ptr_to_node (ptr)->slots[node->parent_slot]; -else - edit->set[0 ].ptr = &assoc_array_ptr_to_shortcut (ptr)->next_node; edit->excised_meta[0 ] =assoc_array_node_to_ptr (node);pr_devel ("<--%s() = ok [split node]\n" , __func__);return true; - -all_leaves_cluster_together: - new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, - node, level, new_n0); -if (!new_s0) -return false; - edit->set[0 ].to =assoc_array_shortcut_to_ptr (new_s0); - goto do_split_node; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1209/2214 assoc_array: dont chain a new shortcut onto an existing one
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 48691075b0adc590a6831390723e3603dfca76fc ]
When a full node's leaves and the new key all share the node's segment, assoc_array_insert_into_terminal_node() replaces the node with a shortcut to a pair of new nodes. If the node is itself the target of a shortcut, the new shortcut is installed as that shortcut's next node, and a shortcut leading to a shortcut is something nothing expects:assoc_array_walk() indexes the second one as a node, and assoc_array_apply_edit() hits the BUG_ON() in the loop that adjusts nr_leaves_on_branch, on that same insertion.
Deletion gets a node there. When the subtree below a shortcut shrinks enough, assoc_array_delete() collapses it into one node below the shortcut, and the leaves it collects can all share that node's segment. The next key that shares it too takes this path. Eighteen insertions and a deletion are enough: sixteen keys that agree on bits 0-11, one that leaves them at bit 8 and is deleted again, and one more that agrees with the sixteen.
Have the new shortcut replace the one in front of the node as well. assoc_array_insert_shortcut() gives it that shortcut's back pointer and parent slot, so the caller installs it where that one was, and excises the old shortcut along with the node, which takes a second entry in excised_meta[]. The new shortcut's index key comes from the new key up to the new skip level, so it covers what the old one did.
Found by a userspace test doing random insertions and deletions on keys that share long prefixes; a targeted case builds a shortcut, deletes down to the collapse and inserts one more key.
--- include/linux/assoc_array_priv.h | 2 +- lib/assoc_array.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)
include/linux/assoc_array_priv.h +1 -1
@@ -80,7 +80,7 @@ struct assoc_array_edit {struct assoc_array_ptr **leaf_p;struct assoc_array_ptr *dead_leaf;struct assoc_array_ptr *new_meta[3 ]; -struct assoc_array_ptr *excised_meta[1 ]; +struct assoc_array_ptr *excised_meta[2 ];struct assoc_array_ptr *excised_subtree;struct assoc_array_ptr **set_backpointers[ASSOC_ARRAY_FAN_OUT ];struct assoc_array_ptr *set_backpointers_to;
lib/assoc_array.c +20 -4
@@ -679,9 +679,10 @@ static void assoc_array_split_node(struct assoc_array_edit *edit,/* * All the leaves, new and old, want to cluster together in this node in the * same slot, so we have to replace this node with a shortcut to skip over -* the identical parts of the key, leading to new_n0. The caller then splits -* the leaves between new_n0 and new_n1 at the shortcut's far end, for which -* this fills in the segment cache. +* the identical parts of the key, leading to new_n0. If the node is the +* target of a shortcut, the new one replaces that shortcut as well. The +* caller then splits the leaves between new_n0 and new_n1 at the shortcut's +* far end, for which this fills in the segment cache. */ static struct assoc_array_shortcut * assoc_array_insert_shortcut(struct assoc_array_edit *edit,
@@ -726,6 +727,20 @@ assoc_array_insert_shortcut(struct assoc_array_edit *edit, new_s0->back_pointer = node->back_pointer; new_s0->parent_slot = node->parent_slot; + +/* A shortcut has to lead to a node, so a node at the end of a shortcut +* is replaced together with that shortcut. The new one holds the index +* key from the root, so it covers what the old one did. +*/ +if (node->back_pointer && +assoc_array_ptr_is_shortcut (node->back_pointer)) { +struct assoc_array_shortcut *above = +assoc_array_ptr_to_shortcut (node->back_pointer); + + new_s0->back_pointer = above->back_pointer; + new_s0->parent_slot = above->parent_slot; + edit->excised_meta[1 ] = node->back_pointer; + } new_s0->next_node =assoc_array_node_to_ptr (new_n0); new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); new_n0->parent_slot =0 ;
@@ -807,7 +822,8 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,/* The node only contains leaves and all the leaves cluster in * the same slot, so we need to insert a shortcut to skip the * common portion of the key and split the node at the -* shortcut's far end. +* shortcut's far end. The shortcut goes wherever its back +* pointer says, which may be further up than the node. */ new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, node, level, new_n0);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1210/2214 assoc_array: keep gcs cleanup out of the live tree on allocation failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 8afff2e4b90978b8203f9e3898995dcf86821b49 ]
assoc_array_gc() builds a copy of the tree. Where the copy reaches a shortcut, it allocates the copy of the shortcut with kmalloc_flex(), fills it with memcpy(), links it into the new tree, and only then allocates the copy of the node after it. The memcpy() leaves the new shortcut's next_node pointing at the old tree's node, so if that second allocation fails, the cleanup, assoc_array_destroy_subtree() on the new tree, follows the new shortcut into the old tree, and the BUG_ON() on the old node's back pointer fires.
Allocate the node first, and the shortcut once the node exists, freeing the node again if the shortcut cannot be allocated. A copied shortcut is then only linked into the new tree when the copy of its node is there to follow it. Nothing else changes: with no allocation failing, the trees gc builds are the same as before.
Found by a userspace test that makes each allocation of each operation fail in turn.
--- lib/assoc_array.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
lib/assoc_array.c +12 -7
@@ -1562,17 +1562,26 @@ int assoc_array_gc(struct assoc_array *array, cursor = array->root; descend: -/* If this point is a shortcut, then we need to duplicate it and -* advance the target cursor. +/* The node at this position is duplicated, and so is the shortcut in +* front of it if there is one. The node is allocated first: the copy +* of the shortcut starts out pointing at the old node, and must not be +* in the new tree if the node cannot be allocated, or the cleanup +* would follow it into the old tree. */ + new_n =kzalloc (sizeof (struct assoc_array_node ),GFP_KERNEL ); +if (!new_n) + goto enomem; +if (assoc_array_ptr_is_shortcut (cursor)) { shortcut =assoc_array_ptr_to_shortcut (cursor); keylen =round_up (shortcut->skip_to_level,ASSOC_ARRAY_KEY_CHUNK_SIZE ); keylen >>=ASSOC_ARRAY_KEY_CHUNK_SHIFT ; new_s =kmalloc (struct_size (new_s, index_key, keylen),GFP_KERNEL ); -if (!new_s) +if (!new_s) { +kfree (new_n); goto enomem; + }pr_devel ("dup shortcut %p -> %p\n" , shortcut, new_s);memcpy (new_s, shortcut,struct_size (new_s, index_key, keylen)); new_s->back_pointer = new_parent;
@@ -1582,11 +1591,7 @@ int assoc_array_gc(struct assoc_array *array, cursor = shortcut->next_node; } -/* Duplicate the node at this position */ node =assoc_array_ptr_to_node (cursor); - new_n =kzalloc (sizeof (struct assoc_array_node ),GFP_KERNEL ); -if (!new_n) - goto enomem;pr_devel ("dup node %p -> %p\n" , node, new_n); new_n->back_pointer = new_parent; new_n->parent_slot = node->parent_slot;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1211/2214 net/packet: check TX_RING fragments before memory accounting
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit dc4dd12f80e499dc034710cd8195489abcf0b059 ]
tpacket_fill_skb() adds the full non-linear payload length to skb->truesize and sk_wmem_alloc before checking MAX_SKB_FRAGS. With PACKET_VNET_HDR, userspace can submit a ring-sized frame even when it greatly exceeds the device MTU.
A near-INT_MAX frame can saturate sk_wmem_alloc before the fragment loop rejects it. A subsequent refcount_add(0x40000001) can temporarily turn REFCOUNT_SATURATED into 1. A concurrent TX completion can then drop that apparent last reference and free the still-live packet socket before refcount_warn_saturate() restores the counter.
Check that the remaining payload fits in MAX_SKB_FRAGS pages before accounting it. Include the initial page offset in the calculation, and move the existing -EFAULT handling out of the fragment loop. This preserves the accepted packet sizes and error code while preventing an invalid frame from injecting an oversized byte charge.
[ 5.15: adjust for context in kernels lacking 3948b05950fd ("net:
introduce a config option to tweak MAX_SKB_FRAGS") ]
--- net/packet/af_packet.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/packet/af_packet.c +6 -6
@@ -2646,6 +2646,12 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, } offset =offset_in_page (data); +if (unlikely (to_write >MAX_SKB_FRAGS *PAGE_SIZE - offset)) { +net_warn_ratelimited ("Packet exceed the number of skb frags(%u)\n" , + (unsigned int )MAX_SKB_FRAGS ); +return -EFAULT ; + } + len_max =PAGE_SIZE - offset; len = ((to_write > len_max) ? len_max : to_write);
@@ -2657,12 +2663,6 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,while (likely (to_write)) { nr_frags =skb_shinfo (skb)->nr_frags; -if (unlikely (nr_frags >=MAX_SKB_FRAGS )) { -pr_err ("Packet exceed the number of skb frags(%lu)\n" , -MAX_SKB_FRAGS ); -return -EFAULT ; - } - page =pgv_to_page (data); data += len;flush_dcache_page (page);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1212/2214 KVM: nSVM: Check validity of vmcs01 save area copied from SMRAM on RSM
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 053621535f014085c935879582dd3b65964a0dce ]
When doing RSM to L2, validate L1's state after copying it back into vmcb01 from SMRAM, as SMRAM is carved out of guest memory, i.e. is writable by the guest. Failure to validate L1's state is especially problematic for inputs to MMU context, as KVM can end up with impossible CR4 vs. EFER state. E.g. without the recent hardening FNAME(walk_addr_generic), a guest can trigger:
------------[ cut here ]------------ UBSAN: array-index-out-of-bounds in arch/x86/kvm/mmu/paging_tmpl.h:435:15 index 3 is out of range for type 'u32 [2]' CPU: 3 UID: 0 PID: 92 Comm: CPU 1/KVM Not tainted 7.3.0-rc1 #2 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.17.0-0-gb52ca86e094d-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x5f/0x90 dump_stack+0x10/0x18 ubsan_epilogue+0x9/0x39 __ubsan_handle_out_of_bounds.cold+0x50/0x55 paging32_walk_addr_generic+0x889/0x970 paging32_page_fault+0x79/0xa60 kvm_mmu_do_page_fault+0x125/0x270 kvm_mmu_page_fault+0x88/0x7b0 npf_interception+0xc8/0x220 [kvm_amd] svm_invoke_exit_handler+0x16d/0x1d0 [kvm_amd] svm_handle_exit+0xb7/0x160 [kvm_amd] vcpu_enter_guest+0x428/0x16a0 kvm_arch_vcpu_ioctl_run+0x479/0x920 kvm_vcpu_ioctl+0x316/0xb00 __x64_sys_ioctl+0xa3/0x100 x64_sys_call+0x281/0x23d0 do_syscall_64+0xba/0x550 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x79bb30deb04b </TASK> ---[ end trace ]---
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/nested.c | 19 ++++++++++--------- arch/x86/kvm/svm/svm.c | 2 ++ arch/x86/kvm/svm/svm.h | 2 ++ 3 files changed, 14 insertions(+), 9 deletions(-)
arch/x86/kvm/svm/nested.c +10 -9
@@ -292,10 +292,15 @@ static bool nested_vmcb_check_cr3_cr4(struct kvm_vcpu *vcpu,return true; } -/* Common checks that apply to both L1 and L2 state. */ -static bool nested_vmcb_valid_sregs (struct kvm_vcpu *vcpu, -struct vmcb_save_area *save) +bool nested_vmcb_valid_sregs (struct kvm_vcpu *vcpu, +struct vmcb_save_area *save,bool is_l1) { +if (is_l1 && (!(save->cr0 &X86_CR0_PG ) || + !(save->cr0 &X86_CR0_PE ) || + (save->rflags &X86_EFLAGS_VM ) || + ((save->efer &EFER_LMA ) && !(save->efer &EFER_LME )))) +return false; +/* * FIXME: these should be done after copying the fields, * to avoid TOC/TOU races. For these save area checks
@@ -674,7 +679,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)nested_load_control_from_vmcb12 (svm, &vmcb12->control); -if (!nested_vmcb_valid_sregs (vcpu, &vmcb12->save) || +if (!nested_vmcb_valid_sregs (vcpu, &vmcb12->save, false) || !nested_vmcb_check_controls (vcpu, &svm->nested.ctl)) { vmcb12->control.exit_code =SVM_EXIT_ERR ; vmcb12->control.exit_code_hi =-1u ;
@@ -1365,11 +1370,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,* Validate host state saved from before VMRUN (see * nested_svm_check_permissions). */ -if (!(save->cr0 &X86_CR0_PG ) || - !(save->cr0 &X86_CR0_PE ) || - (save->rflags &X86_EFLAGS_VM ) || - ((save->efer &EFER_LMA ) && !(save->efer &EFER_LME )) || - !nested_vmcb_valid_sregs (vcpu, save)) +if (!nested_vmcb_valid_sregs (vcpu, save, true)) goto out_free;
arch/x86/kvm/svm/svm.c +2 -0
@@ -4441,6 +4441,8 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)*/ svm_copy_vmrun_state (&svm->vmcb01.ptr->save, map_save.hva +0x400 ); +if (!nested_vmcb_valid_sregs (vcpu, &svm->vmcb01.ptr->save, true)) + goto unmap_save;/* * Enter the nested guest now
arch/x86/kvm/svm/svm.h +2 -0
@@ -491,6 +491,8 @@ void nested_load_control_from_vmcb12(struct vcpu_svm *svm,void __svm_write_tsc_multiplier (u64 multiplier);void nested_sync_control_from_vmcb02 (struct vcpu_svm *svm);void nested_vmcb02_compute_g_pat (struct vcpu_svm *svm); +bool nested_vmcb_valid_sregs (struct kvm_vcpu *vcpu, +struct vmcb_save_area *save,bool is_l1);void svm_switch_vmcb (struct vcpu_svm *svm,struct kvm_vmcb_info *target_vmcb);extern struct kvm_x86_nested_ops svm_nested_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1213/2214 inet: frags: limit the truesize of a reassembly queue
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 3ae20e4697eb969104fe4b1e98a675f0100382b6 ]
The truesize of fragments in a reassembly queue is only bounded by the per netns ipfrag_high_thresh sysctl, which has no upper limit.
inet_frag_reasm_finish() sums the truesize of all fragments in an int. If this sum reaches 2^32, it wraps, and the final sk_wmem_alloc adjustment of the socket owning the reassembled skb can cancel its own reference, leading to a use-after-free of this socket.
This can be triggered from an unprivileged user/network namespace, raising ipfrag_high_thresh and using padded TUN packets, which keep a large truesize after being trimmed by ip_rcv_core().
Track the sum of the truesize of fragments in each queue, and refuse a fragment that would make it bigger than INT_MAX / 2. Callers kill the queue on this error. This bound is far above the needs of legitimate traffic.
--- include/net/inet_frag.h | 9 +++++++++ net/ipv4/inet_fragment.c | 4 ++++ net/ipv4/ip_fragment.c | 1 + 3 files changed, 14 insertions(+)
include/net/inet_frag.h +9 -0
@@ -72,6 +72,7 @@ struct frag_v6_compare_key {* @meat: length of received fragments so far * @flags: fragment queue flags * @max_size: maximum received fragment size +* @truesize: sum of the truesize of queued fragments * @fqdir: pointer to struct fqdir * @rcu: rcu head for freeing deferall */
@@ -92,6 +93,7 @@ struct inet_frag_queue {int meat;__u8 flags;u16 max_size; +unsigned int truesize;struct fqdir *fqdir;struct rcu_head rcu; };
@@ -174,6 +176,13 @@ extern const u8 ip_frag_ecn_table[16];#define IPFRAG_OK 0#define IPFRAG_DUP 1#define IPFRAG_OVERLAP 2 +#define IPFRAG_TOOBIG 4 + +/* Max sum of the truesize of fragments in a queue. This keeps the sums +* done in inet_frag_reasm_prepare() and inet_frag_reasm_finish() well +* below INT_MAX. Legitimate traffic stays far below this limit. +*/ +#define INET_FRAG_MAX_TRUESIZE (INT_MAX / 2)int inet_frag_queue_insert (struct inet_frag_queue *q,struct sk_buff *skb,int offset,int end); void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb,
net/ipv4/inet_fragment.c +4 -0
@@ -384,6 +384,9 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, {struct sk_buff *last = q->fragments_tail; +if (skb->truesize >INET_FRAG_MAX_TRUESIZE - q->truesize) +return IPFRAG_TOOBIG ; +/* An IP fragment is never a GSO packet, but an untrusted source * (virtio_net_hdr) may have attached GSO metadata to it. Do not let * that reach the reassembled skb, whose head keeps the first
@@ -446,6 +449,7 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb,FRAG_CB (skb)->ip_defrag_offset = offset; + q->truesize += skb->truesize;return IPFRAG_OK ; }EXPORT_SYMBOL (inet_frag_queue_insert);
net/ipv4/ip_fragment.c +1 -0
@@ -263,6 +263,7 @@ static int ip_frag_reinit(struct ipq *qp) qp->q.rb_fragments =RB_ROOT ; qp->q.fragments_tail =NULL ; qp->q.last_run_head =NULL ; + qp->q.truesize =0 ; qp->iif =0 ; qp->ecn =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1214/2214 9p/xen: drain response work after unbinding IRQ
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
[ Upstream commit 7b6f2e3c29fb4d76f1e4973280792eabbd526602 ]
commit ea4f1009408e ("9p/xen : Fix use after free bug in xen_9pfs_front_remove due to race condition") added cancel_work_sync() to keep xen_9pfs_front_free() from freeing a ring while p9_xen_response() is still running.
The work is currently drained before the event channel IRQ is unbound. That leaves a race window where xen_9pfs_front_event_handler() can run after cancel_work_sync() returns and queue p9_xen_response() again. The following unbind_from_irqhandler() synchronizes with the IRQ handler, but it does not cancel work that the handler already queued. The teardown can then free the ring and private data while the response work remains pending, and the worker later dereferences ring->priv and priv->client.
Unbind the event channel IRQ before draining the work. Once the IRQ is unbound, no new response work can be queued by the backend event channel, and cancel_work_sync() waits for any work that was queued before or during the unbind. It is then safe to release the ring resources.
Message-ID: <[email protected]>
--- net/9p/trans_xen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/9p/trans_xen.c +2 -2
@@ -312,12 +312,12 @@ static void xen_9pfs_front_free(struct xen_9pfs_front_priv *priv)for (i =0 ; i < priv->num_rings; i++) {struct xen_9pfs_dataring *ring = &priv->rings[i]; -cancel_work_sync (&ring->work); -if (!priv->rings[i].intf)break ;if (priv->rings[i].irq >0 )unbind_from_irqhandler (priv->rings[i].irq, ring); +cancel_work_sync (&ring->work); +if (priv->rings[i].data.in) { for (j = 0; j < (1 << priv->rings[i].intf->ring_order);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1215/2214 mm/ksm: fix use of a freed anon_vma at swap-in
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 4c2dec1dce368ad9e9b1814307cb5ef3832fa07e ]
A folio read from a swap slot previously shared by KSM can remain in the swap cache after the process that first mapped it exits. Its anon_vma can then be freed, so ksm_might_need_to_copy() must not dereference it to compare roots.
Doing so can result in some false-positives, resulting in the reverse mapping missing the new folio mapping, preventing migration and reclaim.
SLAB_TYPESAFE_BY_RCU allows individual anon_vma objects to be reused immediately after freeing. A stale pointer can then refer to another anon_vma whose root matches, even though the target VMA is not linked to that anon_vma.
Move the anonymous rmap compatibility checks into folio_anon_rmap_compatible(). Keep the page-index check and compare the folio's anon_vma pointer against the VMA's own anon_vma and root first.
If neither matches, bite the bullet and walk the VMA's anon_vma_chain. The VMA keeps these anon_vmas alive, and finding a match guarantees that reverse mapping can find the new mapping.
Lorenzo Stoakes says in a private discussion:
"This isn't quite equivalent to the existing check.
Every anon_vma in an anon_vma_chain shares the same root, but if you split a VMA then fork both of them like this:
VMA A
/ \ <split>
VMA B VMA C
\ /
root <- anon_vma 1
----^ ^---- <fork>
/ parent \
anon_vma 2 anon_vma 3
| |
VMA D VMA E
VMA's D and E both get their own new
anon_vma's such that:
VMA D: anon_vma 2 -> anon_vma 1 -> root
VMA E: anon_vma 3 -> anon_vma 1 -> root
And if you found a folio referencing anon_vma 2, the existing check:
anon_vma->root == vma->anon-vma->root
Would be true for VMA's B, C, D & E.
However after your change it'd be true for VMA D only, as it's the only one with anon_vma 2 in its anon_vma_chain.
Whether or not that could actually happen in practice... 🙂 I don't know.
[...] after your change it'd be true for VMA D only, as it's the only one with anon_vma 2 in its anon_vma_chain. [...] I would [...] say that you are making the test stricter but more correct.
"
If this affects performance when KSM was never even involved, we could just track whether KSM ever merged anything and just skip these checks.
There isn't really a lot we can do otherwise: for mapped folios we might be able to use folio_get_anon_vma(), but for unmapped folios there really is no easy way to see if the anon_vma is still valid.
Document the (confusing) lifetime requirements of folio_anon_vma().
--- mm/ksm.c | 16 +++++++++++++--- mm/util.c | 13 +++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-)
mm/ksm.c +13 -3
@@ -2662,6 +2662,7 @@ struct page *ksm_might_need_to_copy(struct page *page, struct vm_area_struct *vma, unsigned long address) {struct anon_vma *anon_vma =page_anon_vma (page); +struct anon_vma_chain *avc;struct page *new_page;if (PageKsm (page)) {
@@ -2670,9 +2671,18 @@ struct page *ksm_might_need_to_copy(struct page *page,return page;/* no need to copy it */ }else if (!anon_vma) {return page;/* no need to copy it */ - }else if (anon_vma->root == vma->anon_vma->root && - page->index ==linear_page_index (vma, address)) { -return page;/* still no need to copy it */ + }else if (page->index ==linear_page_index (vma, address)) { +/* +* Careful: anon_vma might have been freed, so we cannot safely +* dereference it. Add a fast path before we walk the anon_vma chain. +*/ +if (anon_vma == vma->anon_vma || anon_vma == vma->anon_vma->root) +return page;/* still no need to copy it */ + +list_for_each_entry (avc, &vma->anon_vma_chain, same_vma) { +if (avc->anon_vma == anon_vma) +return page; + } }if (!PageUptodate (page))return page;/* let do_swap_page report the error */
mm/util.c +13 -0
@@ -778,6 +778,19 @@ bool page_mapped(struct page *page) }EXPORT_SYMBOL (page_mapped); +/** +* page_anon_vma - Get a page's raw anon_vma pointer. +* @page: The page. +* +* The returned pointer may be stale for an unmapped page. The caller +* must ensure the anon_vma stays alive before dereferencing it. A page +* reference or lock alone is insufficient; use page_get_anon_vma() when +* the anon_vma's lifetime is not otherwise protected. Note that +* page_get_anon_vma() is only useful for pages that are still mapped. +* +* Return: The raw anon_vma pointer for an anonymous, non-KSM page, or +* %NULL otherwise. +*/ struct anon_vma *page_anon_vma (struct page *page) {unsigned long mapping;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1216/2214 ksmbd: enforce the read-only share flag when creating a stream
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 09139429fab3a5114c18d7c15fb161511d4d66c9 ]
When a share is read-only, smb2_open() rejects opens that would create or truncate a file. Creating a named stream on an existing file with streams_xattr sets neither O_CREAT nor O_TRUNC, so it passes this check, and smb2_set_stream_name_xattr() then creates the stream. On a Time Machine share, opening a missing AFP_AfpInfo stream also writes one. A user who can write a file at the filesystem level can therefore add streams to it through a read-only share.
Do not create a stream or synthesize AFP_AfpInfo when the share is not writable. Existing streams still open normally, and a missing stream opened with FILE_OPEN still returns STATUS_OBJECT_NAME_NOT_FOUND.
--- fs/ksmbd/smb2pdu.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ksmbd/smb2pdu.c +3 -0
@@ -2538,6 +2538,9 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,return -EBADF ; } +if (!test_tree_conn_flag (fp->tcon,KSMBD_TREE_CONN_FLAG_WRITABLE )) +return -EACCES ; + rc =ksmbd_vfs_setxattr (user_ns, path, xattr_stream_name,NULL ,0 ,0 , false);if (rc <0 )pr_err ("Failed to store XATTR stream name :%d\n" , rc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1217/2214 fbcon: Rebuild rotated font buffer on font change
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yao Yiqi <[email protected]>
[ Upstream commit e4b6b865d45d8dafb6c6f28c8a993a5b4431d25a ]
fbcon_rotate_font() caches a rotated copy of the console font in par->rotated.buf. The buffer is sized from the font's width, height and charcount, and is rebuilt in fbcon_init(), fbcon_switch() and fbcon_modechanged(), but not in fbcon_do_set_font().
When the font is changed through KDFONTOP, the new geometry is installed and vc_resize() redraws before the buffer is rebuilt. The rotated putcs/cursor ops then index the old buffer with the new cell size; KASAN reports a slab-out-of-bounds read in soft_cursor().
Rebuild the buffer for the visible console before the redraw, as the other callers do: select the console's blitting state with set_blitting_type() (which also uploads the new font's map on tile-blitting hardware), then rebuild. Background consoles keep their rebuild at fbcon_switch() time, as the buffer is shared per framebuffer and must not be updated for a console that is not being displayed.
To ensure a correct rollback when the rebuild or the following vc_resize() fails, save the rotated font state, clear it before rebuilding, and restore it in the error path of fbcon_do_set_font().
--- drivers/video/fbdev/core/fbcon.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
drivers/video/fbdev/core/fbcon.c +57 -0
@@ -2389,6 +2389,12 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,int resize, ret, old_userfont, old_width, old_height, old_charcount;u8 *old_data = vc->vc_font.data;unsigned short old_hi_font_mask = vc->vc_hi_font_mask; +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +u8 *saved_fontdata =NULL , *saved_fontbuffer =NULL ; +u32 saved_fd_size =0 ; +int saved_cur_rotate =0 ; +bool rotated_saved = false; +#endif resize = (w != vc->vc_font.width) || (h != vc->vc_font.height); vc->vc_font.data = (void *)(p->fontdata = data);
@@ -2408,6 +2414,33 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,else if (!vc->vc_hi_font_mask && charcount ==512 )set_vc_hi_font (vc, true); +/* +* Select the console's blitting state and update the rotated font buffer +* to match the new font, so that the rendering below does not use a +* cache that was built for the old font. Clear the cached state so +* the rebuild allocates a fresh buffer; the old state is kept until +* the font change can no longer fail. +*/ +if (con_is_visible (vc)) { +set_blitting_type (vc, info); +if (par->rotate_font) { +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION + saved_fontdata = par->fontdata; + saved_fontbuffer = par->fontbuffer; + saved_fd_size = par->fd_size; + saved_cur_rotate = par->cur_rotate; + par->fontdata =NULL ; + par->fontbuffer =NULL ; + par->fd_size =0 ; + par->cur_rotate =0 ; + rotated_saved = true; +#endif + ret = par->rotate_font (info, vc); +if (ret) + goto err_out; + } + } +if (resize) {int cols, rows;
@@ -2424,11 +2457,28 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,update_screen (vc); } +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +if (rotated_saved) +kfree (saved_fontbuffer); +#endif if (old_userfont && (--REFCOUNT (old_data) ==0 ))kfree (old_data -FONT_EXTRA_WORDS *sizeof (int ));return 0 ; err_out: +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +/* +* Drop the buffer built for the new font and restore the saved +* state. +*/ +if (rotated_saved) { +kfree (par->fontbuffer); + par->fontdata = saved_fontdata; + par->fontbuffer = saved_fontbuffer; + par->fd_size = saved_fd_size; + par->cur_rotate = saved_cur_rotate; + } +#endif p->fontdata = old_data; vc->vc_font.data = old_data;
@@ -2448,6 +2498,13 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,else if (!old_hi_font_mask && vc->vc_hi_font_mask)set_vc_hi_font (vc, false); +/* +* Re-select the blitting type, which re-uploads the font map on +* tile-blitting hardware. +*/ +if (con_is_visible (vc)) +set_blitting_type (vc, info); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1218/2214 btrfs: prevent deleting the wrong subvolume by ID
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: guolingxing <[email protected]>
[ Upstream commit 1960146913b31b288ed2cd607d103ee3b41681d4 ]
When deleting a subvolume by ID, btrfs_ioctl_snap_destroy() first resolves the requested ID to a name, then looks up that name again under the parent directory lock.
A concurrent rename can change which subvolume is associated with the name between these operations. Since the deletion path does not verify the ID of the resolved subvolume, it can delete a different subvolume while leaving the requested one intact.
This was reproduced by repeatedly exchanging the names of two subvolumes using renameat2(RENAME_EXCHANGE) while deleting one of them by ID. The wrong subvolume was deleted in 9 out of 14 independent tests.
Fix this by checking that the resolved subvolume ID matches the requested ID while holding the parent directory lock. Return -EAGAIN on a mismatch so that userspace can retry the operation instead of being told that the requested subvolume does not exist.
--- fs/btrfs/ioctl.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/btrfs/ioctl.c +11 -0
@@ -3070,6 +3070,17 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, inode =d_inode (dentry); dest =BTRFS_I (inode)->root; + +/* +* A concurrent rename may have changed which subvolume the name +* refers to. Verify that the resolved ID still matches the requested ID. +*/ +if (destroy_v2 && (vol_args2->flags &BTRFS_SUBVOL_SPEC_BY_ID ) && +btrfs_root_id (dest) != vol_args2->subvolid) { + err = -EAGAIN ; + goto out_dput; + } +if (!capable (CAP_SYS_ADMIN )) {/* * Regular user. Only allow this with a special mount
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1219/2214 ALSA: compress: fix buffer leak on failed SET_PARAMS
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit fbc74ca9fbf7e0b8f6872ccac62f9f4a1f3b5e53 ]
When the driver has neither ops->copy nor a preallocated dma_buffer_p, snd_compr_allocate_buffer() kmallocs runtime->buffer. If ops->set_params() then rejects the parameters, SET_PARAMS fails, the stream stays in the OPEN state and keeps the buffer. The next SET_PARAMS allocates a new buffer and overwrites the pointer, so repeated SET_PARAMS calls with parameters that the driver rejects leak one buffer per call.
Release the framework-owned buffer when ops->set_params() fails on an OPEN stream, so that a failed SET_PARAMS leaves no buffer behind and the buffer is allocated only once per successful setup. Use the same ownership check as snd_compr_free().
--- sound/core/compress_offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/core/compress_offload.c +8 -1
@@ -602,8 +602,15 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) } retval = stream->ops->set_params (stream, params); -if (retval) +if (retval) { +/* the stream stays OPEN: drop the buffer of the rejected setup */ +if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN && + !stream->runtime->dma_buffer_p) { +kfree (stream->runtime->buffer); + stream->runtime->buffer =NULL ; + } goto out; + } stream->metadata_set = false; stream->next_track = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1220/2214 io_uring/timeout: count cancelled timeouts in cq_timeouts
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Yongkang <[email protected]>
[ Upstream commit 1c8b49851543f41fc8bb18bcd1f15cc93d14b530 ]
io_timeout_cancel() posts the cancelled timeout's -ECANCELED CQE without advancing ctx->cq_timeouts. io_timeout_fn() and io_kill_timeout() advance it for every timeout CQE they post, and io_flush_timeouts() computes the number of non-timeout completions as
seq = cached_cq_tail - cq_timeouts
to compare against each off timeout's target_seq. The cancelled timeout's CQE is therefore counted as a regular completion, so every cancellation makes an already armed off timeout fire one completion early.
A ring with a keep-alive timeout of off=4 completes it after two NOPs when one off=100 victim is cancelled through IORING_OP_ASYNC_CANCEL, and before any NOP when two victims are cancelled. The cancel CQE should count, but the cancelled timeouts' -ECANCELED CQEs must not: the expected counts are three and two NOPs respectively.
Advance cq_timeouts when io_timeout_extract() succeeds, under timeout_lock and before the -ECANCELED completion is queued, matching io_timeout_fn() and io_kill_timeout(). The -ENOENT and -EALREADY paths post no new timeout CQE and keep their accounting. Both the ASYNC_CANCEL and the TIMEOUT_REMOVE path go through io_timeout_cancel().
--- io_uring/io_uring.c | 2 ++ 1 file changed, 2 insertions(+)
io_uring/io_uring.c +2 -0
@@ -6264,6 +6264,8 @@ static int io_timeout_cancel(struct io_ring_ctx *ctx, __u64 user_data)if (IS_ERR (req))return PTR_ERR (req); +atomic_set (&ctx->cq_timeouts, +atomic_read (&ctx->cq_timeouts) +1 );req_set_fail (req);io_fill_cqe_req (req, -ECANCELED ,0 );io_put_req_deferred (req);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1221/2214 /proc/sys: use d_splice_alias() calling conventions to simplify failure exits
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 1eae9a47835ed4703055afbb3c52fef6d07a8a4c ]
Stable-dep-of: eeecea75ece2 ("proc: don't let an entry below /proc/<pid>/net be a mountpoint")
--- fs/proc/proc_sysctl.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
fs/proc/proc_sysctl.c +2 -12
@@ -522,13 +522,8 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, goto out; } - inode =proc_sys_make_inode (dir->i_sb, h ? h : head, p); -if (IS_ERR (inode)) { - err =ERR_CAST (inode); - goto out; - } -d_set_d_op (dentry, &proc_sys_dentry_operations); + inode =proc_sys_make_inode (dir->i_sb, h ? h : head, p); err =d_splice_alias (inode, dentry); out:
@@ -686,13 +681,8 @@ static bool proc_sys_fill_cache(struct file *file,return false;if (d_in_lookup (child)) {struct dentry *res; - inode =proc_sys_make_inode (dir->d_sb, head, table); -if (IS_ERR (inode)) { -d_lookup_done (child); -dput (child); -return false; - }d_set_d_op (child, &proc_sys_dentry_operations); + inode =proc_sys_make_inode (dir->d_sb, head, table); res =d_splice_alias (inode, child);d_lookup_done (child);if (unlikely (res)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1222/2214 proc: add proc_splice_unmountable()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 32a0a965b8a5b7b505babae2ee10c513ede376d8 ]
Add a tiny procfs helper to splice a dentry that cannot be mounted upon.
Stable-dep-of: eeecea75ece2 ("proc: don't let an entry below /proc/<pid>/net be a mountpoint")
--- fs/proc/internal.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/proc/internal.h +13 -0
@@ -332,3 +332,16 @@ static inline void pde_force_lookup(struct proc_dir_entry *pde)/* /proc/net/ entries can be changed under us by setns(CLONE_NEWNET) */ pde->proc_dops = &proc_net_dentry_ops; } + +/* +* Add a new procfs dentry that can't serve as a mountpoint. That should +* encompass anything that is ephemeral and can just disappear while the +* process is still around. +*/ +static inline struct dentry *proc_splice_unmountable (struct inode *inode, +struct dentry *dentry,const struct dentry_operations *d_ops) +{ +d_set_d_op (dentry, d_ops); +dont_mount (dentry); +return d_splice_alias (inode, dentry); +}
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1223/2214 procfs: kill ->proc_dops
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 5943c611c47c9444e834555c867dec744158b7ad ]
It has two possible values - one for "forced lookup" entries, another for the normal ones. We'd be better off with that as an explicit flag anyway and in addition to that it opens some fun possibilities with ->d_op and ->d_flags handling.
[moved PROC_ENTRY_FORCE_LOOKUP to include/linux/proc_fs.h, switched it to an unused bit - there was a conflict]
Stable-dep-of: eeecea75ece2 ("proc: don't let an entry below /proc/<pid>/net be a mountpoint")
--- fs/proc/generic.c | 8 +++++--- fs/proc/internal.h | 3 +-- include/linux/proc_fs.h | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-)
fs/proc/generic.c +5 -3
@@ -256,7 +256,10 @@ struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry, inode =proc_get_inode (dir->i_sb, de);if (!inode)return ERR_PTR (-ENOMEM ); -d_set_d_op (dentry, de->proc_dops); +if (de->flags &PROC_ENTRY_FORCE_LOOKUP ) +d_set_d_op (dentry, &proc_net_dentry_ops); +else +d_set_d_op (dentry, &proc_misc_dentry_ops);return d_splice_alias (inode, dentry); }read_unlock (&proc_subdir_lock);
@@ -448,9 +451,8 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,INIT_LIST_HEAD (&ent->pde_openers);proc_set_user (ent, (*parent)->uid, (*parent)->gid); - ent->proc_dops = &proc_misc_dentry_ops;/* Revalidate everything under /proc/${pid}/net */ -if ((*parent)->proc_dops == &proc_net_dentry_ops) +if ((*parent)->flags &PROC_ENTRY_FORCE_LOOKUP )pde_force_lookup (ent); out:
fs/proc/internal.h +1 -2
@@ -43,7 +43,6 @@ struct proc_dir_entry {const struct proc_ops *proc_ops;const struct file_operations *proc_dir_ops; }; -const struct dentry_operations *proc_dops;union {const struct seq_operations *seq_ops;int (*single_show)(struct seq_file *,void *);
@@ -330,7 +329,7 @@ extern const struct dentry_operations proc_net_dentry_ops;static inline void pde_force_lookup (struct proc_dir_entry *pde) {/* /proc/net/ entries can be changed under us by setns(CLONE_NEWNET) */ - pde->proc_dops = &proc_net_dentry_ops; + pde->flags |=PROC_ENTRY_FORCE_LOOKUP ; }/*
include/linux/proc_fs.h +2 -0
@@ -27,6 +27,8 @@ enum { PROC_ENTRY_proc_read_iter =1U <<1 , PROC_ENTRY_proc_compat_ioctl =1U <<2 , + + PROC_ENTRY_FORCE_LOOKUP = 1U << 7, }; struct proc_ops {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1224/2214 new helper: d_splice_alias_ops()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 790fa81b8c43cda9fe25c1b564d0afe3ddeeb370 ]
Uses of d_set_d_op() on live dentry can be very dangerous; it is going to be withdrawn and replaced with saner things.
The best way for a filesystem is to have the default dentry_operations set at mount time and be done with that - __d_alloc() will use that.
Currently there are two cases when d_set_d_op() is used on a live dentry - one is procfs, which has several genuinely different dentry_operations instances (different ->d_revalidate(), etc.) and another is simple_lookup(), where we would be better off without overriding ->d_op.
For procfs we have d_set_d_op() calls followed by d_splice_alias(); provide a new helper (d_splice_alias_ops(inode, dentry, d_ops)) that would combine those two, and do the d_set_d_op() part while under ->d_lock. That eliminates one of the places where ->d_flags had been modified without holding ->d_lock; current behaviour is not racy, but the reasons for that are far too brittle. Better move to uniform locking rules and simpler proof of correctness...
The next commit will convert procfs to use of that helper; it is not exported and won't be until somebody comes up with convincing modular user for it.
Again, the best approach is to have default ->d_op and let __d_alloc() do the right thing; filesystem _may_ need non-uniform ->d_op (procfs does), but there'd better be good reasons for that.
Stable-dep-of: eeecea75ece2 ("proc: don't let an entry below /proc/<pid>/net be a mountpoint")
--- fs/dcache.c | 63 ++++++++++++++++++++++++------------------ include/linux/dcache.h | 3 ++ 2 files changed, 39 insertions(+), 27 deletions(-)
fs/dcache.c +36 -27
@@ -2703,7 +2703,8 @@ EXPORT_SYMBOL(__d_lookup_done);/* inode->i_lock held if inode is non-NULL */ -static inline void __d_add (struct dentry *dentry,struct inode *inode) +static inline void __d_add (struct dentry *dentry,struct inode *inode, +const struct dentry_operations *ops) {struct inode *dir =NULL ;unsigned n;
@@ -2713,6 +2714,8 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode) n =start_dir_add (dir);__d_lookup_done (dentry); } +if (unlikely (ops)) +d_set_d_op (dentry, ops);if (inode) {unsigned add_flags =d_flags_for_inode (inode);hlist_add_head (&dentry->d_u.d_alias, &inode->i_dentry);
@@ -2744,7 +2747,7 @@ void d_add(struct dentry *entry, struct inode *inode)security_d_instantiate (entry, inode);spin_lock (&inode->i_lock); } -__d_add (entry, inode); +__d_add (entry, inode,NULL ); }EXPORT_SYMBOL (d_add);
@@ -3039,30 +3042,8 @@ static int __d_unalias(struct inode *inode,return ret; } -/** -* d_splice_alias - splice a disconnected dentry into the tree if one exists -* @inode: the inode which may have a disconnected dentry -* @dentry: a negative dentry which we want to point to the inode. -* -* If inode is a directory and has an IS_ROOT alias, then d_move that in -* place of the given dentry and return it, else simply d_add the inode -* to the dentry and return NULL. -* -* If a non-IS_ROOT directory is found, the filesystem is corrupt, and -* we should error out: directories can't have multiple aliases. -* -* This is needed in the lookup routine of any filesystem that is exportable -* (via knfsd) so that we can build dcache paths to directories effectively. -* -* If a dentry was found and moved, then it is returned. Otherwise NULL -* is returned. This matches the expected return value of ->lookup. -* -* Cluster filesystems may call this function with a negative, hashed dentry. -* In that case, we know that the inode will be a regular file, and also this -* will only occur during atomic_open. So we need to check for the dentry -* being already hashed only in the final case. -*/ -struct dentry *d_splice_alias (struct inode *inode,struct dentry *dentry) +struct dentry *d_splice_alias_ops (struct inode *inode,struct dentry *dentry, +const struct dentry_operations *ops) {if (IS_ERR (inode))return ERR_CAST (inode);
@@ -3108,9 +3089,37 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) } } out: -__d_add (dentry, inode); +__d_add (dentry, inode, ops);return NULL ; } + +/** +* d_splice_alias - splice a disconnected dentry into the tree if one exists +* @inode: the inode which may have a disconnected dentry +* @dentry: a negative dentry which we want to point to the inode. +* +* If inode is a directory and has an IS_ROOT alias, then d_move that in +* place of the given dentry and return it, else simply d_add the inode +* to the dentry and return NULL. +* +* If a non-IS_ROOT directory is found, the filesystem is corrupt, and +* we should error out: directories can't have multiple aliases. +* +* This is needed in the lookup routine of any filesystem that is exportable +* (via knfsd) so that we can build dcache paths to directories effectively. +* +* If a dentry was found and moved, then it is returned. Otherwise NULL +* is returned. This matches the expected return value of ->lookup. +* +* Cluster filesystems may call this function with a negative, hashed dentry. +* In that case, we know that the inode will be a regular file, and also this +* will only occur during atomic_open. So we need to check for the dentry +* being already hashed only in the final case. +*/ +struct dentry *d_splice_alias (struct inode *inode,struct dentry *dentry) +{ +return d_splice_alias_ops (inode, dentry,NULL ); +}EXPORT_SYMBOL (d_splice_alias);/*
include/linux/dcache.h +3 -0
@@ -242,6 +242,9 @@ extern struct dentry * d_alloc_anon(struct super_block *);extern struct dentry *d_alloc_parallel (struct dentry *,const struct qstr *,wait_queue_head_t *);extern struct dentry *d_splice_alias (struct inode *,struct dentry *); +/* weird procfs mess; *NOT* exported */ +extern struct dentry *d_splice_alias_ops (struct inode *,struct dentry *, +const struct dentry_operations *);extern struct dentry *d_add_ci (struct dentry *,struct inode *,struct qstr *);extern struct dentry *d_exact_alias (struct dentry *,struct inode *);extern struct dentry *d_find_any_alias (struct inode *inode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1225/2214 switch procfs from d_set_d_op() to d_splice_alias_ops()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit ec169ef86ba45389b353189cf1fc06461163f667 ]
Stable-dep-of: eeecea75ece2 ("proc: don't let an entry below /proc/<pid>/net be a mountpoint")
--- fs/proc/base.c | 9 +++------ fs/proc/generic.c | 8 ++++---- fs/proc/internal.h | 3 +-- fs/proc/namespaces.c | 3 +-- fs/proc/proc_sysctl.c | 7 +++---- 5 files changed, 12 insertions(+), 18 deletions(-)
fs/proc/base.c +3 -6
@@ -2690,8 +2690,7 @@ static struct dentry *proc_pident_instantiate(struct dentry *dentry, inode->i_fop = p->fop; ei->op = p->op;pid_update_inode (task, inode); -d_set_d_op (dentry, &pid_dentry_operations); -return d_splice_alias (inode, dentry); +return d_splice_alias_ops (inode, dentry, &pid_dentry_operations); } static struct dentry *proc_pident_lookup(struct inode *dir,
@@ -3430,8 +3429,7 @@ static struct dentry *proc_pid_instantiate(struct dentry * dentry,set_nlink (inode, nlink_tgid);pid_update_inode (task, inode); -d_set_d_op (dentry, &pid_dentry_operations); -return d_splice_alias (inode, dentry); +return d_splice_alias_ops (inode, dentry, &pid_dentry_operations); }struct dentry *proc_pid_lookup (struct dentry *dentry,unsigned int flags)
@@ -3731,8 +3729,7 @@ static struct dentry *proc_task_instantiate(struct dentry *dentry,set_nlink (inode, nlink_tid);pid_update_inode (task, inode); -d_set_d_op (dentry, &pid_dentry_operations); -return d_splice_alias (inode, dentry); +return d_splice_alias_ops (inode, dentry, &pid_dentry_operations); }static struct dentry *proc_task_lookup (struct inode *dir,struct dentry * dentry,unsigned int flags)
fs/proc/generic.c +4 -4
@@ -257,10 +257,10 @@ struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry,if (!inode)return ERR_PTR (-ENOMEM );if (de->flags &PROC_ENTRY_FORCE_LOOKUP ) -d_set_d_op (dentry, &proc_net_dentry_ops); -else -d_set_d_op (dentry, &proc_misc_dentry_ops); -return d_splice_alias (inode, dentry); +return d_splice_alias_ops (inode, dentry, + &proc_net_dentry_ops); +return d_splice_alias_ops (inode, dentry, + &proc_misc_dentry_ops); }read_unlock (&proc_subdir_lock);return ERR_PTR (-ENOENT );
fs/proc/internal.h +1 -2
@@ -340,7 +340,6 @@ static inline void pde_force_lookup(struct proc_dir_entry *pde)static inline struct dentry *proc_splice_unmountable (struct inode *inode,struct dentry *dentry,const struct dentry_operations *d_ops) { -d_set_d_op (dentry, d_ops);dont_mount (dentry); -return d_splice_alias (inode, dentry); +return d_splice_alias_ops (inode, dentry, d_ops); }
fs/proc/namespaces.c +1 -2
@@ -125,8 +125,7 @@ static struct dentry *proc_ns_instantiate(struct dentry *dentry, ei->ns_ops = ns_ops;pid_update_inode (task, inode); -d_set_d_op (dentry, &pid_dentry_operations); -return d_splice_alias (inode, dentry); +return d_splice_alias_ops (inode, dentry, &pid_dentry_operations); }static int proc_ns_dir_readdir (struct file *file,struct dir_context *ctx)
fs/proc/proc_sysctl.c +3 -4
@@ -522,9 +522,8 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, goto out; } -d_set_d_op (dentry, &proc_sys_dentry_operations); inode =proc_sys_make_inode (dir->i_sb, h ? h : head, p); - err =d_splice_alias (inode, dentry); + err =d_splice_alias_ops (inode, dentry, &proc_sys_dentry_operations); out:if (h)
@@ -681,9 +680,9 @@ static bool proc_sys_fill_cache(struct file *file,return false;if (d_in_lookup (child)) {struct dentry *res; -d_set_d_op (child, &proc_sys_dentry_operations); inode =proc_sys_make_inode (dir->d_sb, head, table); - res =d_splice_alias (inode, child); + res =d_splice_alias_ops (inode, child, + &proc_sys_dentry_operations);d_lookup_done (child);if (unlikely (res)) {if (IS_ERR (res)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1226/2214 proc: dont let an entry below /proc/<pid>/net be a mountpoint
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit eeecea75ece2ba894bee4d3c53ed2e40abda8f0e ]
proc_net_d_revalidate() always returns 0 so that a dentry below /proc/<pid>/net is never reused after setns(). So lookup_fast() will end up calling d_invalidate(), which unhashes the dentry and detaches every mount on it, in every mount namespace; including locked mounts.
Then lookup_slow() creates a new dentry for the same entry. So a mount on /proc/<pid>/net/dev succeeds and goes away with the first lookup of the name by anybody with search permission on the directory. Given it's 0555 that's everyone's grandma. A mask on such a name hides nothing as the repro below shows.
Treat those entries like I did fd/, fdinfo/ and map_files/ and refuse to mount on them in the first place. It's nonsensical theater otherwise:
procnet net/dev stat
// SPDX-License-Identifier: GPL-2.0
/*
* procnet: cover an entry of /proc/<pid>/ with a bind mount, lock the mount,
* then look the name up.
*
* The first task stays alive, <pid> is its pid. The "container" task has its
* own mount namespace. There it binds a mask on /proc/<pid>/<name>. It drops to
* uid 1000 and enters a new user namespace with a new mount namespace, so that
* the mask is locked. Then one task looks the name up:
*
* stat the container calls stat() on the name * umount the container calls umount2(MNT_DETACH) on the name * nobody a task with uid 65534 in the first namespaces calls stat()
*
* The container lists its mounts before and after (that does not look the
* name up) and then reads the name. MASK is fine. Anything else means that
* the lookup uncovered the entry.
*
* usage: procnet <name> stat|umount|nobody
* name "status" is the control, "net/dev" is a file below net, "net/stat" is
* a directory below net
*/
#define _GNU_SOURCE
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#define WORK "/run/pn"
static char target[128];
static void die(const char *what)
{
fprintf(stderr, "FATAL %s: %s\n", what, strerror(errno));
exit(2);
}
static void write_str(const char *path, const char *s, int flags)
{
int fd = open(path, O_WRONLY | flags, 0644);
if (fd < 0 || write(fd, s, strlen(s)) < 0)
die(path);
close(fd);
}
/* list the mounts below /proc without a lookup of the target */
static void mounts(const char *when)
{
char line[512];
FILE *f = fopen("/proc/self/mountinfo", "r");
int n = 0;
if (!f)
die("mountinfo");
while (fgets(line, sizeof(line), f)) {
if (!strstr(line, " /proc/"))
continue;
printf("container: %s: mount: %s", when, line);
n++;
}
fclose(f);
if (!n)
printf("container: %s: nothing is mounted below /proc\n", when);
}
static void show(const char *when, int isdir)
{
char buf[48] = "";
int fd;
if (isdir) {
struct dirent *de;
DIR *d = opendir(target);
int hit = 0;
if (!d) {
printf("container: %s: opendir(%s) = %s\n", when, target, strerror(errno));
return;
}
printf("container: %s: readdir(%s) =", when, target);
while ((de = readdir(d))) {
if (de->d_name[0] == '.')
continue;
printf(" %s", de->d_name);
hit |= strcmp(de->d_name, "MASK");
}
closedir(d);
printf("%s\n", hit ? " <-- HIT" : "");
return;
}
fd = open(target, O_RDONLY);
if (fd < 0) {
printf("container: %s: open(%s) = %s\n", when, target, strerror(errno));
return;
}
if (read(fd, buf, sizeof(buf) - 1) < 0)
die("read");
close(fd);
if (strchr(buf, '\n'))
*strchr(buf, '\n') = 0;
printf("container: %s: read(%s) = \"%s\"%s\n", when, target, buf,
strncmp(buf, "MASK", 4) ? " <-- HIT" : "");
}
int main(int argc, char **argv)
{
const char *name = argc > 1 ? argv[1] : "net/dev";
const char *op = argc > 2 ? argv[2] : "stat";
int isdir = !strcmp(name, "net/stat");
int to_host[2], to_cont[2];
struct stat st;
pid_t pid;
char c;
setvbuf(stdout, NULL, _IOLBF, 0);
snprintf(target, sizeof(target), "/proc/%d/%s", getpid(), name);
if (unshare(CLONE_NEWNS) || mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL))
die("unshare");
mkdir(WORK, 0755);
if (mount("W", WORK, "tmpfs", 0, NULL))
die("mount W");
write_str(WORK "/mask", "MASK", O_CREAT);
mkdir(WORK "/maskdir", 0755);
write_str(WORK "/maskdir/MASK", "MASK", O_CREAT);
if (pipe(to_host) || pipe(to_cont))
die("pipe");
pid = fork();
if (pid < 0)
die("fork");
if (!pid) {
if (unshare(CLONE_NEWNS))
die("container unshare");
if (mount(isdir ? WORK "/maskdir" : WORK "/mask", target, NULL, MS_BIND, NULL)) {
printf("container: bind the mask on %s: %s\n", target, strerror(errno));
exit(0);
}
printf("container: bind the mask on %s: ok\n", target);
if (setgid(1000) || setuid(1000) || prctl(PR_SET_DUMPABLE, 1))
die("setuid");
/* lock the mount: a new user namespace with a copy of the tree */
if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
die("container userns");
write_str("/proc/self/setgroups", "deny", 0);
write_str("/proc/self/uid_map", "0 1000 1", 0);
write_str("/proc/self/gid_map", "0 1000 1", 0);
mounts("before");
errno = 0;
if (!strcmp(op, "stat")) {
stat(target, &st);
printf("container: stat(%s): %s\n", target, strerror(errno));
} else if (!strcmp(op, "umount")) {
umount2(target, MNT_DETACH);
printf("container: umount2(%s, MNT_DETACH): %s\n", target, strerror(errno));
} else if (write(to_host[1], "g", 1) != 1 || read(to_cont[0], &c, 1) != 1) {
die("sync");
}
mounts("after");
show("after", isdir);
exit(0);
}
close(to_host[1]);
if (read(to_host[0], &c, 1) == 1) {
pid_t p2 = fork();
if (!p2) {
if (setgid(65534) || setuid(65534))
die("setuid");
errno = 0;
stat(target, &st);
printf("nobody: uid %u: stat(%s): %s\n", getuid(), target, strerror(errno));
exit(0);
}
waitpid(p2, NULL, 0);
if (write(to_cont[1], "g", 1) != 1)
die("sync");
}
waitpid(pid, NULL, 0);
return 0;
}--- fs/proc/generic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/proc/generic.c +3 -2
@@ -256,9 +256,10 @@ struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry, inode =proc_get_inode (dir->i_sb, de);if (!inode)return ERR_PTR (-ENOMEM ); +/* never reused and so never a mountpoint for long */ if (de->flags &PROC_ENTRY_FORCE_LOOKUP ) -return d_splice_alias_ops (inode, dentry, - &proc_net_dentry_ops); +return proc_splice_unmountable (inode, dentry, + &proc_net_dentry_ops);return d_splice_alias_ops (inode, dentry, &proc_misc_dentry_ops); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1227/2214 nilfs2: validate directory position after llseek in readdir
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jake Labelle <[email protected]>
[ Upstream commit de7f49c12566cc5c7437a2f26c6c754b9d4d5648 ]
nilfs_readdir() uses ctx->pos, which userspace can set to an arbitrary value via llseek, as an offset into the directory folio and parses whatever bytes sit there as a directory entry. A position pointing into the middle of an entry -- or at unused bytes of a corrupted image that the page validator never inspected -- makes dir_emit() copy up to 255 (name_len) bytes from a bogus entry, possibly reading past the end of the folio and returning unrelated memory contents to userspace.
Snap unaligned positions onto a valid entry boundary by walking the rec_len chain from the chunk start before parsing, as ext2 does in ext2_validate_entry().
[ryusuke: fixed offset wrap-around in nilfs_validate_entry() and
conformed AI tag to guidelines]
--- fs/nilfs2/dir.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
fs/nilfs2/dir.c +34 -0
@@ -265,11 +265,27 @@ static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *inode) de->file_type = nilfs_type_by_mode[(mode &S_IFMT )>>S_SHIFT ]; } +static inline unsigned int +nilfs_validate_entry (char *base,unsigned int offset,unsigned int mask) +{ +struct nilfs_dir_entry *de = (struct nilfs_dir_entry *)(base + offset); +struct nilfs_dir_entry *p = + (struct nilfs_dir_entry *)(base + (offset & mask)); + +while ((char *)p < (char *)de) { +if (p->rec_len ==0 ) +break ; + p =nilfs_next_entry (p); + } +return (char *)p - base; +} +static int nilfs_readdir (struct file *file,struct dir_context *ctx) {loff_t pos = ctx->pos;struct inode *inode =file_inode (file);struct super_block *sb = inode->i_sb; +unsigned int chunk_size =nilfs_chunk_size (inode);unsigned int offset = pos & ~PAGE_MASK ;unsigned long n = pos >>PAGE_SHIFT ;unsigned long npages =dir_pages (inode);
@@ -288,6 +304,24 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx) ctx->pos +=PAGE_SIZE - offset;return -EIO ; } +/* +* ctx->pos comes from userspace via llseek and may point +* into the middle of an entry -- or at unvalidated bytes +* of a crafted image. offset is only nonzero here on the +* very first iteration (subsequent pages always start at +* offset 0, which -- like any chunk boundary -- is always +* a legitimate entry start, since no rec_len chain crosses +* a chunk boundary). Snap a non-chunk-aligned offset onto +* a real entry boundary by walking the chain from the +* enclosing chunk's start, as ext2 does; otherwise +* dir_emit() copies name_len bytes from a fake entry, +* reading past the end of the folio. +*/ +if (offset & (chunk_size -1 )) { + offset =nilfs_validate_entry (kaddr, offset, + ~(chunk_size -1 )); + ctx->pos = ((loff_t )n <<PAGE_SHIFT ) + offset; + } de = (struct nilfs_dir_entry *)(kaddr + offset); limit = kaddr +nilfs_last_byte (inode, n) -NILFS_DIR_REC_LEN (1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1228/2214 mm/userfaultfd: wake waiters when registration modes are removed
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 4eee9c389b072e161549d46dcb1ae10b0222717e ]
UFFDIO_REGISTER can replace MISSING or MINOR tracking without waking faults that are already queued. For example, switching an anonymous range from MISSING to WP leaves a missing-fault waiter asleep until userspace explicitly wakes it.
When a registration change removes a UFFD mode, wake waiters in the affected interval after updating the VMA. The VMA is write-locked at this point, so no new faults can queue under the old modes and woken threads cannot retry until mmap_write_unlock(). Waiters for retained modes in the same interval may also wake and refault.
The hang reproduces for MISSING-to-WP and MINOR-to-MISSING transitions, with both read and unread fault events.
--- fs/userfaultfd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/userfaultfd.c +12 -0
@@ -1421,6 +1421,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, ret =0 ; do { + const bool any_mode_removed = vma->vm_flags & __VM_UFFD_FLAGS & ~vm_flags; + cond_resched(); BUG_ON(!vma_can_userfault(vma, vm_flags));
@@ -1468,6 +1470,16 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, vma->vm_flags = new_flags; vma->vm_userfaultfd_ctx.ctx = ctx; +/* Retry faults for removed modes while the VMA is write-locked. */ +if (any_mode_removed) { +struct userfaultfd_wake_range range = { + .start = start, + .len = vma_end - start, + }; + +wake_userfault (ctx, &range); + } +if (is_vm_hugetlb_page (vma) &&uffd_disable_huge_pmd_share (vma))hugetlb_unshare_all_pmds (vma);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1229/2214 apparmor: remove fs entries created by a failed policy load
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Georgia Garcia <[email protected]>
[ Upstream commit 6ec46f8f1977d218bf2494ce276152b2d01424af ]
aa_replace_profiles() creates the raw_data/<rev> directory for the loaddata and the profile directories for new profiles before the last checks that can fail. When one of those checks fails, the fail path releases the ns lock without removing what this load created.
The raw_data directory is named after the current ns revision, and the revision is only bumped by a successful load. The stale directory is only removed once the loaddata's last profile reference is dropped, from a workqueue. Until then, every load fails to create raw_data/<rev> with -EEXIST. If the new profiles are never freed, which is the case when their dents are left behind pinning the proxy, that never happens and no policy can be loaded until reboot.
While still holding the ns lock in the fail path, remove the profile directories of the new profiles and, if this load created it, the raw_data directory.
--- security/apparmor/policy.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
security/apparmor/policy.c +14 -0
@@ -923,6 +923,7 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,const char *op;ssize_t count, error;ssize_t udata_sz; +bool rawdata_created = false;LIST_HEAD (lh); op = mask &AA_MAY_REPLACE_POLICY ?OP_PROF_REPL :OP_PROF_LOAD ;
@@ -1041,6 +1042,7 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label, ent =NULL ; goto fail_lock; } + rawdata_created = true; }list_for_each_entry (ent, &lh, list) {if (!ent->old) {
@@ -1119,6 +1121,18 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,return udata_sz; fail_lock: +/* +* Remove fs entries created by this load. Nothing else references +* them yet, and leaving them behind would leak the new profiles +* (their dents pin the proxy) and make the next load at the same, +* unbumped ns revision fail with -EEXIST on its raw_data dir. +*/ +list_for_each_entry (tmp, &lh, list) { +if (!tmp->old) +__aafs_profile_rmdir (tmp->new); + } +if (rawdata_created) +__aa_fs_remove_rawdata (udata);mutex_unlock (&ns->lock);/* audit cause of failure */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1230/2214 mm/madvise: add cond_resched() in THP branch of madvise_cold_or_pageout_pte_range()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Yang <[email protected]>
[ Upstream commit f5cfc8e3b20ad71949a1e5623ff45882c063a71b ]
During stress testing with stress-ng on a 256-CPU system, a softlockup was observed when madvise(MADV_COLD) was called on a 31GB memory region backed by transparent hugepages. The region contains 15935 THP PMD entries, and the softlockup was triggered after 14485 of them had been processed.
The THP branch of madvise_cold_or_pageout_pte_range() has no scheduling point. walk_pmd_range() invokes it once per 2MB PMD entry with no cond_resched() anywhere in the loop. Each iteration calls pmdp_invalidate() which issues a synchronous TLB shootdown (dsb ish) waiting for all CPUs to acknowledge. This operation can be time-consuming under heavy system load, causing the accumulated time across all PMD entries to exceed the softlockup threshold (20s) and panic when softlockup_panic=1. On a CONFIG_PREEMPT_NONE=y kernel, there is no other opportunity to reschedule during this entire traversal.
The regular PTE path already has an unconditional cond_resched() at the function tail (introduced by commit 9c276cc65a58 ("mm: introduce MADV_COLD") and commit 1a4e58cce84e ("mm: introduce MADV_PAGEOUT") when MADV_COLD and MADV_PAGEOUT were first introduced) and a conditional one inside the loop (commit b2f557a21bc8 ("mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()")). The THP branch never received equivalent treatment.
Fix by adding cond_resched() at the huge_unlock exit path after spin_unlock(ptl) and reclaim_pages(), which is the single exit point for all goto paths in the THP branch.
Crash log:
watchdog: BUG: soft lockup - CPU#63 stuck for 23s! [stress-ng-vm:1665914] ... Call trace: pmdp_invalidate+0x48/0x68 madvise_cold_or_pageout_pte_range+0x84c/0xb00 walk_pmd_range.isra.0+0x1ac/0x3b0 walk_pud_range+0x120/0x190 walk_pgd_range+0x170/0x1b8 __walk_page_range+0x184/0x198 walk_page_range_vma+0x94/0x128 madvise_cold+0xd8/0x198 madvise_vma_behavior+0x234/0x638 madvise_walk_vmas.constprop.0+0xdc/0x210 madvise_do_behavior+0xa8/0x328 do_madvise+0xd8/0x140 __arm64_sys_madvise+0x2c/0xe0
--- mm/madvise.c | 1 + 1 file changed, 1 insertion(+)
mm/madvise.c +1 -0
@@ -383,6 +383,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,spin_unlock (ptl);if (pageout)reclaim_pages (&page_list); +cond_resched ();return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1231/2214 f2fs: fix to update superblock crc in sanity_check_area_boundary()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit f8f956c7ec8c0285d7a80bed497d2f7adcbded15 ]
This patch fixes the bug reported by Sashiko:
We should update superblock crc along w/ raw_super->segment_count in sanity_check_area_boundary() if sb_checksum feature is enabled.
--- fs/f2fs/super.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/f2fs/super.c +6 -0
@@ -3268,6 +3268,12 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,/* fix in-memory information all the time */ raw_super->segment_count =cpu_to_le32 ((main_end_blkaddr - segment0_blkaddr) >> log_blocks_per_seg); +if (__F2FS_HAS_FEATURE (raw_super,F2FS_FEATURE_SB_CHKSUM )) { +__u32 crc =f2fs_crc32 (sbi, raw_super, + offsetof(struct f2fs_super_block , crc)); + + raw_super->crc =cpu_to_le32 (crc); + }if (f2fs_readonly (sb) ||bdev_read_only (sb->s_bdev)) {set_sbi_flag (sbi,SBI_NEED_SB_WRITE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1232/2214 libceph: initialize CRUSH choose argument weights
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darong Lu <[email protected]>
[ Upstream commit c3a995ff0782587789333c621e1f6bd5e574371e ]
Initialize the CRUSH choose argument weight-set array before decoding so entries start in a defined state while the decoder fills them.
--- net/ceph/osdmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/osdmap.c +1 -1
@@ -304,7 +304,7 @@ static int decode_choose_arg(void **p, void *end, struct crush_choose_arg *arg)if (arg->weight_set_size) {u32 i; - arg->weight_set =kmalloc_array (arg->weight_set_size, + arg->weight_set =kcalloc (arg->weight_set_size,sizeof (*arg->weight_set),GFP_NOIO );if (!arg->weight_set)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1233/2214 ovl: inherit FMODE_NONOTIFY when opening directory realfiles
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 323899b4ed233d5b6e2fc160c16fbf39cf0317da ]
When fanotify hands a listener an fd for a permission event on an overlay directory, ovl_dir_open_realfile() opens the real directory via dentry_open(), not backing_file_open(), so the lower open could still raise FS_OPEN_PERM and deadlock a listener that also marks the backing filesystem.
Export dentry_open_nonotify() and call it from ovl_path_open_realfile() when the overlay user file must not generate events. Ordinary ovl_path_open() callers are unchanged.
--- fs/overlayfs/readdir.c | 10 +++++++++- fs/overlayfs/util.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
fs/overlayfs/readdir.c +9 -1
@@ -850,9 +850,17 @@ static struct file *ovl_dir_open_realfile(const struct file *file, {struct file *res;const struct cred *old_cred; +int flags =O_RDONLY | (file->f_flags &O_LARGEFILE ); + +/* +* Inherit FMODE_NONOTIFY from a fanotify permission fd so a listener +* that also watches the real filesystem does not deadlock. +*/ +if (file->f_mode &FMODE_NONOTIFY ) + flags |= __FMODE_NONOTIFY; old_cred =ovl_override_creds (file_inode (file)->i_sb); - res =ovl_path_open (realpath,O_RDONLY | (file->f_flags &O_LARGEFILE )); + res =ovl_path_open (realpath, flags);revert_creds (old_cred);return res;
fs/overlayfs/util.c +1 -1
@@ -502,7 +502,7 @@ struct file *ovl_path_open(struct path *path, int flags)struct inode *inode =d_inode (path->dentry);int err, acc_mode; -if (flags & ~(O_ACCMODE |O_LARGEFILE )) +if (flags & ~(O_ACCMODE |O_LARGEFILE | __FMODE_NONOTIFY))BUG ();switch (flags &O_ACCMODE ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1234/2214 f2fs: fix to fetch ino via ino_of_node() under cache lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit cd6d8b1891395b681f2060916a4b83880b765698 ]
In f2fs_writeback_node_caches(), it's better to fetch ino via ino_of_node() under cache lock, otherwise, node cache content may become stale after cache is unlocked due to racing w/ truncation.
Commit 493b9dc8b52c ("f2fs: cache: use node cache") fixes similar issue in f2fs_flush_inline_data() introduced in commit 34c061ad85a2 ("f2fs: Avoid double lock for cp_rwsem during checkpoint").
--- fs/f2fs/node.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/node.c +3 -1
@@ -2025,9 +2025,11 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,/* flush inline_data */ if (page_private_inline (page)) { +nid_t ino =ino_of_node (page); +clear_page_private_inline (page);unlock_page (page); -flush_inline_data (sbi,ino_of_node (page)); +flush_inline_data (sbi, ino); goto lock_node; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1235/2214 xfs: dont skip free extents of the longest length in a whole-AG FITRIM
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 5745f4f10a1a16aa5bb020acc38afa33f2d5ff99 ]
Since commit a66d636385d6 ("xfs: fix fstrim offset calculations"), the by-length walk of an AG in FITRIM starts with xfs_alloc_lookup_ge(cur, 0, pagf_longest) and walks down. The lookup lands on the longest free extent with the lowest block number. The other free extents of that length sort after it and are never discarded.
Start every by-length batch with xfs_alloc_lookup_le() at restart_bno.
--- fs/xfs/xfs_discard.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/xfs/xfs_discard.c +3 -2
@@ -53,9 +53,10 @@ xfs_trim_extents( cur =xfs_allocbt_init_cursor (mp,NULL , agbp, pag,XFS_BTNUM_CNT );/* -* Look up the longest btree in the AGF and start with it. +* Start at the last record of the longest length. */ - error =xfs_alloc_lookup_ge (cur,0 ,be32_to_cpu (agf->agf_longest), &i); + error =xfs_alloc_lookup_le (cur,NULLAGBLOCK , +be32_to_cpu (agf->agf_longest), &i);if (error) goto out_del_cursor;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1236/2214 drm/amdgpu: finish GPU recovery callbacks before restarting schedulers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prike Liang <[email protected]>
[ Upstream commit 733389cb31e2c55e355410759fdc68afe74a4582 ]
Run GPU post-reset callbacks, including KFD and display-audio resume, before restarting DRM scheduler workqueues. IP hardware initialization already happens inside ASIC recovery; this change orders the remaining callbacks before new scheduler submissions. Preserve the emergency-stop and guity job completition path's callbacks without starting schedulers,
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +24 -14
@@ -5296,7 +5296,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, }if (need_emergency_restart) - goto skip_sched_resume; + goto post_resume;/* * Must check guilty signal here since after this point all old
@@ -5337,7 +5337,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, skip_hw_reset: -/* Post ASIC reset for all devs .*/ list_for_each_entry (tmp_adev, device_list_handle, reset_list) {/*
@@ -5351,6 +5350,29 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, !(tmp_vram_lost_counter < atomic_read(&adev->vram_lost_counter)))amdgpu_device_recheck_guilty_jobs ( tmp_adev, device_list_handle, &reset_context); + } + +post_resume: +list_for_each_entry (tmp_adev, device_list_handle, reset_list) { +/* unlock kfd: SRIOV would do it separately */ +if (!need_emergency_restart && !amdgpu_sriov_vf (tmp_adev)) +amdgpu_amdkfd_post_reset (tmp_adev); + +/* kfd_post_reset will do nothing if kfd device is not initialized, +* need to bring up kfd here if it's not be initialized before +*/ +if (!adev->kfd.init_complete) +amdgpu_amdkfd_device_init (adev); + +if (audio_suspended) +amdgpu_device_resume_display_audio (tmp_adev); + } + +if (need_emergency_restart) + goto skip_sched_resume; + +/* Post ASIC reset for all devs .*/ +list_for_each_entry (tmp_adev, device_list_handle, reset_list) {for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];
@@ -5384,18 +5406,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, skip_sched_resume:list_for_each_entry (tmp_adev, device_list_handle, reset_list) { -/* unlock kfd: SRIOV would do it separately */ -if (!need_emergency_restart && !amdgpu_sriov_vf (tmp_adev)) -amdgpu_amdkfd_post_reset (tmp_adev); - -/* kfd_post_reset will do nothing if kfd device is not initialized, -* need to bring up kfd here if it's not be initialized before -*/ -if (!adev->kfd.init_complete) -amdgpu_amdkfd_device_init (adev); - -if (audio_suspended) -amdgpu_device_resume_display_audio (tmp_adev);amdgpu_device_unlock_adev (tmp_adev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1237/2214 mm/ksm: mark migration stores with WRITE_ONCE()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit d3863210464f69c18615cbe400d48a6e53e770d4 ]
ksm_get_folio() deliberately samples stable_node->kpfn and folio->mapping without taking the folio lock because the KSM folio may be migrated concurrently. folio_migrate_ksm() updates the same state using plain assignments.
The reader can load the old kpfn, then the migrator can store the new kpfn, execute smp_wmb(), and clear the old folio's mapping before the reader checks that mapping. Thus the initial kpfn load can overlap its update and the subsequent mapping load can overlap the clear, with no common lock. This leaves marked READ_ONCE() accesses racing with plain stores.
The kernel reported:
BUG: KCSAN: data-race in folio_migrate_ksm / ksm_get_folio
read (marked) to 0xffff8ce401421330 of 8 bytes by task 48 on cpu 3:
ksm_get_folio+0x7f/0x2a0 ksm_scan_thread+0x1635/0x3330 kthread+0x1af/0x1f0
write to 0xffff8ce401421330 of 8 bytes by task 102 on cpu 1:
folio_migrate_ksm+0x6a/0xd0 folio_migrate_flags+0x193/0x420 __migrate_folio.isra.0+0x162/0x1a0 migrate_folio+0x4c/0x70 move_to_new_folio+0xd6/0x170
Use WRITE_ONCE() for both stores to pair them with the existing lockless reads. This preserves the existing smp_wmb()/smp_rmb() migration protocol and control flow while preventing compiler transformations of the shared accesses.
--- mm/ksm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/ksm.c +3 -2
@@ -862,7 +862,8 @@ static inline struct stable_node *page_stable_node(struct page *page)static inline void set_page_stable_node (struct page *page,struct stable_node *stable_node) { - page->mapping = (void *)((unsigned long )stable_node |PAGE_MAPPING_KSM ); +WRITE_ONCE (page->mapping, + (void *)((unsigned long )stable_node |PAGE_MAPPING_KSM )); }#ifdef CONFIG_SYSFS
@@ -2779,7 +2780,7 @@ void ksm_migrate_page(struct page *newpage, struct page *oldpage) stable_node =page_stable_node (newpage);if (stable_node) {VM_BUG_ON_PAGE (stable_node->kpfn !=page_to_pfn (oldpage), oldpage); - stable_node->kpfn =page_to_pfn (newpage); +WRITE_ONCE (stable_node->kpfn,page_to_pfn (newpage));/* * newpage->mapping was set in advance; now we need smp_wmb() * to make sure that the new stable_node->kpfn is visible
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1238/2214 selftests:core: test coverage for dup_fd() failure handling in unshare_fd()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 611fbeb44a777e5ab54ab3127ec85f72147911d8 ]
At some point there'd been a dumb braino during the dup_fd() calling conventions change; caught by smatch and immediately fixed. The trouble is, there had been no test coverage for the dup_fd() failure handling - neither in kselftests nor in LTP. Fortunately, it can be triggered on stock kernel - ENOMEM would require fault injection, but EMFILE can be had with sysctl alone (fs.nr_open).
Add a test for dup_fd() failure.
Fixed up commit log and short log - Shuah Khan
Stable-dep-of: df0b7e0ea59c ("selftests/core: fix unshare_test with large fs.nr_open")
--- tools/testing/selftests/core/Makefile | 2 +- tools/testing/selftests/core/unshare_test.c | 94 +++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/core/unshare_test.c
tools/testing/selftests/core/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only CFLAGS += -g -I../../../../usr/include/ -TEST_GEN_PROGS := close_range_test +TEST_GEN_PROGS := close_range_test unshare_test include ../lib.mk
tools/testing/selftests/core/unshare_test.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1239/2214 selftests/core: fix unshare_test with large fs.nr_open
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Khorenko <[email protected]>
[ Upstream commit df0b7e0ea59c43708cff8c7e34da5e2f8d430e5e ]
The test assumes fs.nr_open is close to the default 1048576, but some systems set it much higher (e.g. 1073741816). This is systemd's doing:
since systemd v240 (2018), PID 1 bumps fs.nr_open and fs.file-max to their largest possible values on boot, as file descriptors are already accounted for by memcg [1].
In that case, dup2() to nr_open + 64 requires the kernel to allocate a file descriptor table with ~1 billion entries, which fails with ENOMEM.
On a kernel that already carries 04a2c4b4511d1, dup2() no longer fails with ENOMEM. The allocation is now rejected up front and the caller gets EMFILE instead, without the WARNING, but the test still fails.
Cap the nr_open value used for the test's own arithmetic to a known reasonable base value (1048576) and restore the true original value once the test has completed.
--- tools/testing/selftests/core/unshare_test.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
tools/testing/selftests/core/unshare_test.c +17 -2
@@ -40,6 +40,14 @@ TEST(unshare_EMFILE)ASSERT_EQ (sscanf (buf,"%d" , &nr_open),1 ); +/* +* Cap nr_open for the duration of the test to avoid ENOMEM from a +* huge fd table allocation; buf/n keep the real original value so +* fs.nr_open can be restored to it once the test is done. +*/ +if (nr_open >1024 *1024 ) + nr_open =1024 *1024 ; +ASSERT_EQ (0 ,getrlimit (RLIMIT_NOFILE , &rlimit));/* bump fs.nr_open */
@@ -73,10 +81,13 @@ TEST(unshare_EMFILE)if (pid ==0 ) {int err; +char buf3[32 ]; +ssize_t n3; -/* restore fs.nr_open */ +/* restore fs.nr_open to the (possibly capped) test baseline */ + n3 =sprintf (buf3,"%d\n" , nr_open);lseek (fd,0 ,SEEK_SET ); -write (fd, buf, n); +write (fd, buf3, n3);/* ... and now unshare(CLONE_FILES) must fail with EMFILE */ err =unshare (CLONE_FILES );EXPECT_EQ (err,-1 )
@@ -89,6 +100,10 @@ TEST(unshare_EMFILE)EXPECT_EQ (waitpid (pid, &status,0 ), pid);EXPECT_EQ (true,WIFEXITED (status));EXPECT_EQ (0 ,WEXITSTATUS (status)); + +/* restore the real fs.nr_open value */ +lseek (fd,0 ,SEEK_SET ); +write (fd, buf, n); }TEST_HARNESS_MAIN
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1240/2214 scsi: ufs: core: Remove an always-false WARN_ONCE()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Jhu <[email protected]>
[ Upstream commit cd37a69c367b6a5f685db0ac7d01f08545081a30 ]
The WARN_ONCE() in ufshcd_poll() can never fire. completed_reqs is set to ~tr_doorbell & hba->outstanding_reqs on the line above, and hba->outstanding_reqs cannot change in between because ufshcd_poll() holds hba->outstanding_lock. So completed_reqs & ~hba->outstanding_reqs is always zero. Remove it. No functional change.
--- drivers/scsi/ufs/ufshcd.c | 3 --- 1 file changed, 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +0 -3
@@ -5322,9 +5322,6 @@ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba,spin_lock_irqsave (&hba->outstanding_lock, flags); tr_doorbell =ufshcd_readl (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL ); completed_reqs = ~tr_doorbell & hba->outstanding_reqs; -WARN_ONCE (completed_reqs & ~hba->outstanding_reqs, -"completed: %#lx; outstanding: %#lx\n" , completed_reqs, - hba->outstanding_reqs); hba->outstanding_reqs &= ~completed_reqs;spin_unlock_irqrestore (&hba->outstanding_lock, flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1241/2214 apparmor: on failed load ensure profile files are removed before parent
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
[ Upstream commit 97ba44a2aa4c7ab011a93ce94cb595200fe4ea4f ]
The load interface does not guarantee the order profiles are loaded. When a parent is loaded after its child, and the load fails, the current code will issue a warning, and leak a dentry.
For the loaded set of profiles, ensure that on failure list is ordered is traversed in reverse so any children processed after their parent is freed first. We do not need to deal with the cases where the children are processed before their parent, because either a parent outside the list already exists or a dummy parent outside of the list is created, and the list walk will not put those parents before their children.
--- security/apparmor/policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
security/apparmor/policy.c +3 -1
@@ -1126,8 +1126,10 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,* them yet, and leaving them behind would leak the new profiles * (their dents pin the proxy) and make the next load at the same, * unbumped ns revision fail with -EEXIST on its raw_data dir. +* ensure children (which are at the end of the list are removed +* before their parent */ -list_for_each_entry (tmp, &lh, list) { +list_for_each_entry_reverse (tmp, &lh, list) {if (!tmp->old)__aafs_profile_rmdir (tmp->new); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1242/2214 mptcp: pm: kernel: use RCU to free endpoint listeners
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 49b09ae0bf57b4230187d4cdd0a370558e44a6e8 ]
mptcp_pm_nl_create_listen_socket() starts the TCP listener directly instead of going through mptcp_listen(). It consequently misses setting SOCK_RCU_FREE on the parent MPTCP socket.
tcp_child_process() can invoke the listener's subflow_data_ready() callback without holding the MPTCP parent lock or a reference to the parent. An authenticated MP_JOIN racing with endpoint teardown can therefore access the parent after its last reference has been dropped. The ADD_ADDR error path can also close an already published listener.
Set SOCK_RCU_FREE before __inet_listen_sk() publishes the TCP listener, matching mptcp_listen(). This protects the parent on every subsequent close path, including a failed endpoint addition.
--- net/mptcp/pm_netlink.c | 1 + 1 file changed, 1 insertion(+)
net/mptcp/pm_netlink.c +1 -0
@@ -1111,6 +1111,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, goto out; } +sock_set_flag (newsk,SOCK_RCU_FREE );WRITE_ONCE (mptcp_subflow_ctx (ssock->sk)->pm_listener, true); err =kernel_listen (ssock, backlog);if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1243/2214 ocfs2: constify struct ocfs2_lock_res_ops
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit 3ebe69c0c3ae3ef5ecd1ad86aa98a3b7cbe3c7e9 ]
"struct ocfs2_lock_res_ops" are not modified in this driver.
Constifying this structure moves some data to a read-only section, so increase overall security.
In order to do it, "struct ocfs2_lock_res" also needs to be adjusted to this new const qualifier.
On a x86_64, with allmodconfig:
Before:
======
text data bss dec hex filename 83038 2632 400 86070 15036 fs/ocfs2/dlmglue.o
After:
=====
text data bss dec hex filename 83806 1992 272 86070 15036 fs/ocfs2/dlmglue.o
Stable-dep-of: 5b4696e0bfc3 ("ocfs2: cache the mount context for dentry lock callbacks")
--- fs/ocfs2/dlmglue.c | 28 ++++++++++++++-------------- fs/ocfs2/ocfs2.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-)
fs/ocfs2/dlmglue.c +14 -14
@@ -222,12 +222,12 @@ struct ocfs2_lock_res_ops {*/ #define LOCK_TYPE_USES_LVB 0x2 -static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = { .get_osb = ocfs2_get_inode_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { .get_osb = ocfs2_get_inode_osb, .check_downconvert = ocfs2_check_meta_downconvert, .set_lvb = ocfs2_set_meta_lvb,
@@ -235,50 +235,50 @@ static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { .flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB, }; -static struct ocfs2_lock_res_ops ocfs2_super_lops = { +static const struct ocfs2_lock_res_ops ocfs2_super_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH , }; -static struct ocfs2_lock_res_ops ocfs2_rename_lops = { +static const struct ocfs2_lock_res_ops ocfs2_rename_lops = { .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops = { +static const struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops = { .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_trim_fs_lops = { +static const struct ocfs2_lock_res_ops ocfs2_trim_fs_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { +static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_dentry_lops = { +static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_inode_open_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_open_lops = { .get_osb = ocfs2_get_inode_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_flock_lops = { +static const struct ocfs2_lock_res_ops ocfs2_flock_lops = { .get_osb = ocfs2_get_file_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_qinfo_lops = { +static const struct ocfs2_lock_res_ops ocfs2_qinfo_lops = { .set_lvb = ocfs2_set_qinfo_lvb, .get_osb = ocfs2_get_qinfo_osb, .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_refcount_block_lops = { +static const struct ocfs2_lock_res_ops ocfs2_refcount_block_lops = { .check_downconvert = ocfs2_check_refcount_downconvert, .downconvert_worker = ocfs2_refcount_convert_worker, .flags =0 ,
@@ -511,7 +511,7 @@ static inline void ocfs2_init_start_time(struct ocfs2_mask_waiter *mw)static void ocfs2_lock_res_init_common (struct ocfs2_super *osb,struct ocfs2_lock_res *res,enum ocfs2_lock_type type, -struct ocfs2_lock_res_ops *ops, +const struct ocfs2_lock_res_ops *ops,void *priv) { res->l_type = type;
@@ -554,7 +554,7 @@ void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,unsigned int generation, struct inode *inode) { - struct ocfs2_lock_res_ops *ops; + const struct ocfs2_lock_res_ops *ops;switch (type) {case OCFS2_LOCK_TYPE_RW :
fs/ocfs2/ocfs2.h +1 -1
@@ -154,7 +154,7 @@ struct ocfs2_lock_stats {struct ocfs2_lock_res {void *l_priv; -struct ocfs2_lock_res_ops *l_ops; +const struct ocfs2_lock_res_ops *l_ops;struct list_head l_blocked_list;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1244/2214 ocfs2: cache the mount context for dentry lock callbacks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 5b4696e0bfc358619adaeab25ad35b4979af8331 ]
ocfs2_drop_dentry_lock() drops the inode reference before releasing the DENTRY lock. This lets inode eviction release the local inode and open locks before a remote unlink can proceed past the DENTRY lock.
A DLM callback can still arrive before the DENTRY lock has been dropped. ocfs2_get_dentry_osb() obtains the mount context through dl_inode->i_sb, which can access a freed inode when the downconvert thread drops the last inode reference in its post-unlock callback:
Downconvert thread DLM callback thread
------------------ -------------------
ocfs2_process_blocked_lock()
ocfs2_dentry_post_unlock()
ocfs2_dentry_lock_put()
ocfs2_drop_dentry_lock()
iput(dl->dl_inode)
[inode reclaimed after RCU]
ocfs2_blocking_ast()
ocfs2_get_dentry_osb()
dl->dl_inode->i_sb
ocfs2_simple_drop_lockres()Store the mount context in the DENTRY lock resource's l_priv field and use the default mount-context lookup. Recover the containing dentry lock with container_of(), as already done for refcount locks, and remove ocfs2_get_dentry_osb(). ocfs2_dismount_volume() shuts down the DLM before freeing the mount context, so callbacks can use it without accessing the inode. Preserve the existing iput-before-unlock order to avoid delaying local inode and open lock release until after the DENTRY lock is released.
--- fs/ocfs2/dcache.h | 5 ++--- fs/ocfs2/dlmglue.c | 16 ++++------------ 2 files changed, 6 insertions(+), 15 deletions(-)
fs/ocfs2/dcache.h +2 -3
@@ -17,9 +17,8 @@ struct ocfs2_dentry_lock {u64 dl_parent_blkno;/* -* The ocfs2_dentry_lock keeps an inode reference until -* dl_lockres has been destroyed. This is usually done in -* ->d_iput() anyway, so there should be minimal impact. +* The inode reference is dropped before dl_lockres is unlocked. +* Callbacks must not use it to find the mount context during teardown. */ struct inode *dl_inode;struct ocfs2_lock_res dl_lockres;
fs/ocfs2/dlmglue.c +4 -12
@@ -56,7 +56,6 @@ struct ocfs2_mask_waiter {#endif }; -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_inode_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_file_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_qinfo_osb (struct ocfs2_lock_res *lockres);
@@ -256,7 +255,6 @@ static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { };static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { - .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags =0 ,
@@ -307,7 +305,7 @@ static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res {BUG_ON (lockres->l_type !=OCFS2_LOCK_TYPE_DENTRY ); -return (struct ocfs2_dentry_lock *)lockres->l_priv; + return container_of(lockres, struct ocfs2_dentry_lock, dl_lockres); }static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo (struct ocfs2_lock_res *lockres)
@@ -608,13 +606,6 @@ static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)return be64_to_cpu (inode_blkno_be); } -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres) -{ -struct ocfs2_dentry_lock *dl = lockres->l_priv; - -return OCFS2_SB (dl->dl_inode->i_sb); -} -void ocfs2_dentry_lock_res_init (struct ocfs2_dentry_lock *dl,u64 parent,struct inode *inode) {
@@ -622,6 +613,7 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,u64 inode_blkno =OCFS2_I (inode)->ip_blkno;__be64 inode_blkno_be =cpu_to_be64 (inode_blkno);struct ocfs2_lock_res *lockres = &dl->dl_lockres; +struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);ocfs2_lock_res_init_once (lockres);
@@ -650,9 +642,9 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,memcpy (&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START ], &inode_blkno_be,sizeof (__be64)); -ocfs2_lock_res_init_common (OCFS2_SB (inode->i_sb), lockres, +ocfs2_lock_res_init_common (osb, lockres,OCFS2_LOCK_TYPE_DENTRY , &ocfs2_dentry_lops, - dl); + osb); } static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1245/2214 ALSA: pcm: Optimize cpu_latency_qos_*() calls
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 9f6f4e97fd53908aecb0979507d9ff10a22288eb ]
We have a few cpu_latency_qos_*() calls in PCM callbacks, but they seem suboptimal in a few aspects:
- We call them at each time when the hw_params changed, but explicitly do remove and (re-)add; this could be cpu_latency_qos_update_request(), instead
- The setup of cpu_latency_qos_*() doesn't have to be in hw_params at all; it's not the place where the actual parameters are set up, but rather better at the prepare callback.
- The hw_free calls cpu_latency_qos_remove_request() unconditionally, which may be poking a WARNING when it wasn't queued.
For addressing the issues above, this patch cleans up and reorganize the cpu_latency_qos_*() calls in the PCM core by a couple helper functions. Now, they are set up at prepare callback, and cleared at hw_free and release callbacks via the new helpers.
Stable-dep-of: 9017bc3d13da ("ALSA: pcm: Prevent O_APPEND open on OSS streams")
--- sound/core/pcm_native.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-)
sound/core/pcm_native.c +25 -10
@@ -726,11 +726,32 @@ EXPORT_SYMBOL_GPL(snd_pcm_runtime_buffer_set_silence);#define is_oss_stream (substream) false#endif +static void pcm_qos_req_clear (struct snd_pcm_substream *substream) +{ +if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) +cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +} + +static void pcm_qos_req_update (struct snd_pcm_substream *substream,int usecs) +{ +if (usecs <0 ) { +pcm_qos_req_clear (substream); +return ; + } + +if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) +cpu_latency_qos_update_request (&substream->latency_pm_qos_req, + usecs); +else +cpu_latency_qos_add_request (&substream->latency_pm_qos_req, + usecs); +} +static int snd_pcm_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) {struct snd_pcm_runtime *runtime; -int err, usecs; +int err;unsigned int bits;snd_pcm_uframes_t frames;
@@ -837,12 +858,6 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,snd_pcm_timer_resolution_change (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_SETUP ); -if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); - usecs =period_to_usecs (runtime); -if (usecs >=0 ) -cpu_latency_qos_add_request (&substream->latency_pm_qos_req, - usecs); err =0 ; _error:if (err) {
@@ -921,7 +936,7 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream) goto unlock; result =do_hw_free (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_OPEN ); -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +pcm_qos_req_clear (substream); unlock:snd_pcm_buffer_access_unlock (runtime);return result;
@@ -1972,6 +1987,7 @@ static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, err = substream->ops->prepare (substream);if (err <0 )return err; +pcm_qos_req_update (substream,period_to_usecs (substream->runtime));return snd_pcm_do_reset (substream, state); }
@@ -2746,8 +2762,7 @@ void snd_pcm_release_substream(struct snd_pcm_substream *substream) substream->ops->close (substream); substream->hw_opened =0 ; } -if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +pcm_qos_req_clear (substream);if (substream->pcm_release) { substream->pcm_release (substream); substream->pcm_release =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1246/2214 ALSA: pcm: Prevent O_APPEND open on OSS streams
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 9017bc3d13da0ea4e63be618c87143a7b69185e6 ]
ALSA PCM core accepts to re-use the existing stream when O_APPEND is passed, and it's been used for dmix, etc. However, this mode isn't supposed to be used for OSS: the OSS stream allows re-configuration via its hw_params/hw_refine procedure even while it's being mmapped, so it implies the usage of only a single stream. Because of this assumption, the sanity check is skipped for OSS streams, and if user may attach to an existing OSS stream with O_APPEND, it may result in a UAF of the mapped pages which could be used as a privilege escalation exploit.
For addressing it, this patch simply prohibits the O_APPEND behavior on the OSS stream. O_APPEND is never used for OSS layer itself, so this can't break for the right applications.
--- sound/core/pcm.c | 2 ++ sound/core/pcm_local.h | 6 ++++++ sound/core/pcm_native.c | 6 ------ 3 files changed, 8 insertions(+), 6 deletions(-)
sound/core/pcm.c +2 -0
@@ -930,6 +930,8 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,return -ENODEV ;if (!SUBSTREAM_BUSY (substream))return -EBADFD ; +if (is_oss_stream (substream)) +return -EINVAL ; substream->ref_count++; *rsubstream = substream;return 0 ;
sound/core/pcm_local.h +6 -0
@@ -73,4 +73,10 @@ void snd_pcm_sync_stop(struct snd_pcm_substream *substream, bool sync_irq);for ((subs) = (pcm)->streams[str].substream; (subs); \ (subs) = (subs)->next) +#if IS_ENABLED (CONFIG_SND_PCM_OSS ) +#define is_oss_stream (substream) ((substream)->oss.oss) +#else +#define is_oss_stream (substream) false +#endif +#endif /* __SOUND_CORE_PCM_LOCAL_H */
sound/core/pcm_native.c +0 -6
@@ -720,12 +720,6 @@ int snd_pcm_runtime_buffer_set_silence(struct snd_pcm_runtime *runtime) }EXPORT_SYMBOL_GPL (snd_pcm_runtime_buffer_set_silence); -#if IS_ENABLED (CONFIG_SND_PCM_OSS ) -#define is_oss_stream (substream) ((substream)->oss.oss) -#else -#define is_oss_stream (substream) false -#endif -static void pcm_qos_req_clear (struct snd_pcm_substream *substream) {if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1247/2214 tools: linux/types.h: Add 128-bit integer types for arm64 UAPI structures
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
[ Upstream commit 10a47fb67340bca274276faf855d7d460afd9a7a ]
The arm64 UAPI exposes some 128-bit integer types to represent things such as fpsimd registers in the sigcontext. In preparation for defining these using the '__u128' typedef implemented by uapi/linux/types.h, copy that typedef over to the private linux/types.h header used by the tools directory.
--- tools/include/linux/types.h | 5 +++++ 1 file changed, 5 insertions(+)
tools/include/linux/types.h +5 -0
@@ -23,6 +23,11 @@ typedef enum {__GFP_HIGH } gfp_t; +#ifdef __SIZEOF_INT128__ +typedef __signed__ __int128 __s128 __attribute__((aligned(16))); +typedef unsigned __int128 __u128 __attribute__((aligned (16 ))); +#endif +/* * We define u64 as uint64_t for every architecture * so that we can print it with "%"PRIx64 without getting warnings.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1248/2214 hwmon: (sht15) Stop deferred work before releasing its resources
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 5eab1e7f7ed12893f3864fe46ffcd5a41a752d6a ]
The IRQ handler and regulator notifier can leave work pending after a measurement or notification completes. Neither work item is drained before its resources are released on removal or probe failure.
Disable read_work before freeing the IRQ, since the worker can re-enable it. Use request_irq()/free_irq() for explicit teardown. Unregister the regulator notifier before cancelling update_supply_work and disabling the regulator. Apply the same ordering to probe failures.
--- drivers/hwmon/sht15.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
drivers/hwmon/sht15.c +19 -9
@@ -31,6 +31,7 @@#include <linux/bitrev.h> #include <linux/gpio/consumer.h> #include <linux/of.h> +#include <linux/workqueue.h> /* Commands */ #define SHT15_MEASURE_TEMP 0x03
@@ -804,7 +805,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)disable_irq_nosync (irq);atomic_inc (&data->interrupt_handled);/* Then schedule a reading work struct */ -if (data->state !=SHT15_READING_NOTHING ) +if (READ_ONCE (data->state) !=SHT15_READING_NOTHING )schedule_work (&data->read_work);return IRQ_HANDLED ; }
@@ -976,11 +977,8 @@ static int sht15_probe(struct platform_device *pdev) goto err_release_reg; } - ret =devm_request_irq (&pdev->dev,gpiod_to_irq (data->data), - sht15_interrupt_fired, -IRQF_TRIGGER_FALLING , -"sht15 data" , - data); + ret =request_irq (gpiod_to_irq (data->data), sht15_interrupt_fired, +IRQF_TRIGGER_FALLING ,"sht15 data" , data);if (ret) {dev_err (&pdev->dev,"failed to get irq for data line\n" ); goto err_release_reg;
@@ -988,15 +986,15 @@ static int sht15_probe(struct platform_device *pdev)disable_irq_nosync (gpiod_to_irq (data->data)); ret =sht15_connection_reset (data);if (ret) - goto err_release_reg; + goto err_free_irq; ret =sht15_soft_reset (data);if (ret) - goto err_release_reg; + goto err_free_irq; ret =sysfs_create_group (&pdev->dev.kobj, &sht15_attr_group);if (ret) {dev_err (&pdev->dev,"sysfs create failed\n" ); - goto err_release_reg; + goto err_free_irq; } data->hwmon_dev =hwmon_device_register (data->dev);
@@ -1009,9 +1007,15 @@ static int sht15_probe(struct platform_device *pdev) err_release_sysfs_group:sysfs_remove_group (&pdev->dev.kobj, &sht15_attr_group); +err_free_irq: +WRITE_ONCE (data->state,SHT15_READING_NOTHING ); +disable_irq (gpiod_to_irq (data->data)); +cancel_work_sync (&data->read_work); +free_irq (gpiod_to_irq (data->data), data); err_release_reg:if (!IS_ERR (data->reg)) {regulator_unregister_notifier (data->reg, &data->nb); +cancel_work_sync (&data->update_supply_work);regulator_disable (data->reg); }return ret;
@@ -1025,12 +1029,18 @@ static int sht15_remove(struct platform_device *pdev)hwmon_device_unregister (data->hwmon_dev);sysfs_remove_group (&pdev->dev.kobj, &sht15_attr_group); +WRITE_ONCE (data->state,SHT15_READING_NOTHING ); +disable_irq (gpiod_to_irq (data->data)); +cancel_work_sync (&data->read_work); +free_irq (gpiod_to_irq (data->data), data); + ret =sht15_soft_reset (data);if (ret)dev_err (&pdev->dev,"Failed to reset device (%pe)\n" ,ERR_PTR (ret));if (!IS_ERR (data->reg)) {regulator_unregister_notifier (data->reg, &data->nb); +cancel_work_sync (&data->update_supply_work);regulator_disable (data->reg); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1249/2214 backing-file: always end a queued write
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 627cdcbc2a2eceb0452078a0c14370f9f1f17a91 ]
Writes to a loop device with direct I/O on an overlay file make the next freeze of the upper filesystem hang for ever.
Every kiocb_start_write() needs a kiocb_end_write(). For a write that is queued, vfs_iocb_iter_write() leaves the end to the completion, and backing_aio_rw_complete() only calls kiocb_end_write() when IOCB_WRITE is set in the flags copied from the submitter. In-kernel submitters such as loop do not set that flag, so each queued write keeps the freeze protection of the backing filesystem.
Direct writes to a loop device with direct I/O backed by an overlay file left fsfreeze of the ext4 upper filesystem, and a later touch there, blocked in D state. It takes write access to the node of the loop device, which root has by default, to attach the file and to write.
The fix used here is to mark a write in struct backing_aio and to call kiocb_end_write() on completion of every marked write.
Reproduced under qemu without KVM, on v7.3-rc6-21-g602042bf29f6 with earlier fixes of this series applied, with and without this change, once each. The kernel was not changed for the run. With this change fsfreeze finished in about a second. Not run: the nvmet and LIO file backends, which do not set IOCB_WRITE either, FUSE passthrough, and an xfs upper filesystem.
--- fs/overlayfs/file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/overlayfs/file.c +3 -1
@@ -19,6 +19,7 @@ struct ovl_aio_req {struct kiocb iocb;refcount_t ref;struct kiocb *orig_iocb; +bool is_write; };static struct kmem_cache *ovl_aio_request_cachep;
@@ -265,7 +266,7 @@ static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req)struct kiocb *iocb = &aio_req->iocb;struct kiocb *orig_iocb = aio_req->orig_iocb; -if (iocb->ki_flags &IOCB_WRITE ) { +if (aio_req->is_write) {struct inode *inode =file_inode (orig_iocb->ki_filp);/* Actually acquired in ovl_write_iter() */
@@ -394,6 +395,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) SB_FREEZE_WRITE); real.flags =0 ; aio_req->orig_iocb = iocb; + aio_req->is_write = true;kiocb_clone (&aio_req->iocb, iocb,get_file (real.file)); aio_req->iocb.ki_flags = ifl; aio_req->iocb.ki_complete = ovl_aio_rw_complete;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1250/2214 mm/mremap: fix moving PUD leaves
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 440c8779757f09f290770b1d361dc1516a9d0b3e ]
pud_none_or_clear_bad() only really works on page tables. PUD leaves confuse the check and make us clear the page table entry and print a warning.
Since commit aed877c2b4257 ("device/dax: properly refcount device dax pages when mapping"), this also leaks device-DAX folio references, mapcounts and RSS accounting, resulting in "Bad rss-counter state" warnings on exit.
Allow PUD leaves in get_old_pud(). If a PUD leaf cannot be moved as a whole or the move fails, split it. This unmaps it with proper accounting instead of treating the leaf entry as a PMD table.
Keep using pud_trans_huge() for now, in the future this code should be cleaned up to just check for PUD leaves.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/mremap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
mm/mremap.c +6 -6
@@ -45,7 +45,8 @@ static pud_t *get_old_pud(struct mm_struct *mm, unsigned long addr)return NULL ; pud =pud_offset (p4d, addr); -if (pud_none_or_clear_bad (pud)) +if (!pud_trans_huge (*pud) && !pud_devmap (*pud) && +pud_none_or_clear_bad (pud))return NULL ;return pud;
@@ -511,12 +512,11 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (!new_pud)break ;if (pud_trans_huge (*old_pud) ||pud_devmap (*old_pud)) { -if (extent ==HPAGE_PUD_SIZE ) { -move_pgt_entry (HPAGE_PUD , vma, old_addr, new_addr, - old_pud, new_pud, need_rmap_locks); -/* We ignore and continue on error? */ +if (extent ==HPAGE_PUD_SIZE && +move_pgt_entry (HPAGE_PUD , vma, old_addr, new_addr, + old_pud, new_pud, need_rmap_locks))continue ; - } +split_huge_pud (vma, old_pud, old_addr); }else if (IS_ENABLED (CONFIG_HAVE_MOVE_PUD ) && extent ==PUD_SIZE ) { if (move_pgt_entry(NORMAL_PUD, vma, old_addr, new_addr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1251/2214 mm/mremap: recheck PUDs under the page table lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 402882943dfa8bab5c2bcc66189f9fb2828f248e ]
Once get_old_pud() is fixed to accept PUD leaves, unmap_mapping_range() can clear a leaf between the lookup and the move. Holding mmap_lock in write mode does not prevent this.
If the zap happens before move_page_tables() tests the entry, an empty PUD can reach move_normal_pud(), where pud_populate() turns it into a present page table entry. If it happens after the test, move_huge_pud() can instead try to move an empty entry, triggering CONFIG_DEBUG_VM warnings on powerpc.
Recheck the source under the page table lock in both helpers. Treat an empty source in move_normal_pud() as a completed move, and use __pud_trans_huge_lock() in move_huge_pud().
In the future we should likely have the code lookup a PUD/PMD lockless once, instead of multiple times, because one of the problematic bits here is the:
pud_trans_huge(*old_pud)
--- mm/mremap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/mremap.c +8 -2
@@ -314,14 +314,18 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr,if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING ); -/* Clear the pud */ pud = *old_pud; +if (unlikely (pud_none (pud))) + goto out_unlock; + +/* Clear the pud */ pud_clear (old_pud);VM_BUG_ON (!pud_none (*new_pud));pud_populate (mm, new_pud,pud_pgtable (pud));flush_tlb_range (vma, old_addr, old_addr +PUD_SIZE ); +out_unlock:if (new_ptl != old_ptl)spin_unlock (new_ptl);spin_unlock (old_ptl);
@@ -356,7 +360,9 @@ static bool move_huge_pud(struct vm_area_struct *vma, unsigned long old_addr,* We don't have to worry about the ordering of src and dst * ptlocks because exclusive mmap_lock prevents deadlock. */ - old_ptl =pud_lock (vma->vm_mm, old_pud); + old_ptl =__pud_trans_huge_lock (old_pud, vma); +if (unlikely (!old_ptl)) +return false; new_ptl =pud_lockptr (mm, new_pud);if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1252/2214 mm: page_alloc: do not give all non-blocking requests reserve access
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Weiner <[email protected]>
[ Upstream commit 6ee3d87b940848aaed5d4e8d005c5f674bf2637a ]
Patch series "mm: page_alloc: fix reserve access for non-blocking requests", v2.
Two fixes for how non-blocking allocations interact with the highatomic reserve. There are prerequisites for Salvatore's "mm/page_alloc: avoid direct reclaim and compaction for costly __GFP_NORETRY allocations" [0].
Patch 1 narrows which requests may physically take highatomic pages, patch 2 narrows which requests may count them in their watermark check.
Both are prerequisites for Salvatore's patch: it clears __GFP_DIRECT_RECLAIM for costly __GFP_NORETRY requests, which turns every large page cache folio allocation that reaches the slowpath into a non-blocking one. Without patch 1, those requests may fall back to the highatomic freelists reserved for atomic requests. Without patch 2, they count the free highatomic pages in their watermark check while being served from regular memory, so they can consume regular high-order blocks below the min watermark by the size of the reserve. GFP_NOWAIT requests hit both paths today, so these are existing problems worthy of their own stable backports; but Salvatore's patch would widen them significantly.
Patch 2 reproduction: a GFP_NOWAIT burst under memory pressure can drain regular free memory to zero while the highatomic reserve sits idle. Measured on a 32G box with an anonymous working set, swap, and a full 290M reserve, three synthetic bursts drove the 28G Normal zone's regular free memory to 28M, 0.8M and 0.6M against a 60M min watermark. Swapout failed its swap table allocation inside reclaim, reclaim scanned 13M pages to free 200k, and page faults stalled for tens to hundreds of milliseconds. With the fix the burst stops at the min watermark and nothing else happens. This was found in review and reproduced synthetically; it has not been observed in production.
GFP_ATOMIC order-0 requests have a milder version of the same problem:
They are entitled to the reserve but are served regular memory first, so the fix there has to change the watermark check and the freelist order together. Salvatore's change doesn't interact with this, though; fixing that is left for a separate patch.
This patch (of 2):
281dd25c1a01 ("mm/page_alloc: let GFP_ATOMIC order-0 allocs access highatomic reserves") accidentally gave all non-blocking allocation requests access to highatomic reserves, which includes GFP_NOWAIT and other sites clearing __GFP_DIRECT_RECLAIM.
While this improved atomic request success rate, it's unintentionally broad and can actually worsen highatomic requests by squandering the reserves on requests that don't need it.
There are concurrent efforts to clear __GFP_DIRECT_RECLAIM altogether for costly order __GFP_NORETRY requests, which would then also fall into this exemption and deplete reserves even faster.
What GFP_ATOMIC has over the others is __GFP_HIGH, which alloc_flags_slowpath() translates to ALLOC_MIN_RESERVE.
Narrow the exemption to contexts that have both ALLOC_NON_BLOCK | ALLOC_MIN_RESERVE.
--- mm/internal.h | 3 +++ mm/page_alloc.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-)
mm/internal.h +3 -0
@@ -631,6 +631,9 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,/* Flags that allow allocations below the min watermark. */ #define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM) +/* Flags that mean GFP_ATOMIC */ +#define ALLOC_MASK_ATOMIC (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE) +enum ttu_flags ;struct tlbflush_unmap_batch ;
mm/page_alloc.c +3 -1
@@ -3633,7 +3633,9 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone,* reserves as failing now is worse than failing a * high-order atomic allocation in the future. */ -if (!page && (alloc_flags & (ALLOC_OOM |ALLOC_NON_BLOCK ))) +if (!page && + ((alloc_flags &ALLOC_OOM ) || + (alloc_flags &ALLOC_MASK_ATOMIC ) ==ALLOC_MASK_ATOMIC )) page =__rmqueue_smallest (zone, order,MIGRATE_HIGHATOMIC );if (!page) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1253/2214 drm/amdgpu: cancel idle work in hw_init failure paths for vcn/uvd/vce/jpeg
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Liu <[email protected]>
[ Upstream commit a56c2536c399d57a9bb1c02fd411e0c25859af3b ]
When hw_init() fails, amdgpu_device_ip_fini_early() skips hw_fini() because status.hw was never set. For VCN, UVD (including UVD ENC), VCE, and JPEG, hw_fini() is where cancel_delayed_work_sync() is called. Any idle work queued during the partial hw_init() is therefore left pending after sw_fini() frees the adev state the handler touches.
Cancel the idle work in each hw_init() error path, immediately before returning the error, so that hw_fini() remains the sole cancel site on the normal teardown path with no duplication.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/vce_v4_0.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 4 +++- 15 files changed, 53 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +3 -1
@@ -155,7 +155,9 @@ static int jpeg_v2_0_hw_init(void *handle) (adev->doorbell_index.vcn.vcn_ring0_1 << 1), 0); r =amdgpu_ring_test_helper (ring); -if (!r) +if (r) +cancel_delayed_work_sync (&adev->jpeg.idle_work); +else DRM_INFO ("JPEG decode initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +5 -1
@@ -169,12 +169,16 @@ static int jpeg_v2_5_hw_init(void *handle) r =amdgpu_ring_test_helper (ring);if (r) -return r; + goto error; }DRM_INFO ("JPEG decode initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->jpeg.idle_work); +return r; }/**
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +3 -1
@@ -144,8 +144,10 @@ static int jpeg_v3_0_hw_init(void *handle) (adev->doorbell_index.vcn.vcn_ring0_1 << 1), 0); r =amdgpu_ring_test_helper (ring); -if (r) +if (r) { +cancel_delayed_work_sync (&adev->jpeg.idle_work);return r; + }DRM_INFO ("JPEG decode initialized successfully.\n" );
drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c +3 -1
@@ -712,7 +712,9 @@ static int uvd_v3_1_hw_init(void *handle)amdgpu_ring_commit (ring); done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c +3 -1
@@ -195,7 +195,9 @@ static int uvd_v4_2_hw_init(void *handle)amdgpu_ring_commit (ring); done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +3 -1
@@ -192,7 +192,9 @@ static int uvd_v5_0_hw_init(void *handle)amdgpu_ring_commit (ring); done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +3 -1
@@ -522,7 +522,9 @@ static int uvd_v6_0_hw_init(void *handle) } done: -if (!r) { +if (r) { +cancel_delayed_work_sync (&adev->uvd.idle_work); + }else {if (uvd_v6_0_enc_support (adev))DRM_INFO ("UVD and UVD ENC initialized successfully.\n" );else
drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c +3 -1
@@ -589,7 +589,9 @@ static int uvd_v7_0_hw_init(void *handle) } } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD and UVD ENC initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +5 -1
@@ -467,12 +467,16 @@ static int vce_v2_0_hw_init(void *handle)for (i =0 ; i < adev->vce.num_rings; i++) { r =amdgpu_ring_test_helper (&adev->vce.ring[i]);if (r) -return r; + goto error; }DRM_INFO ("VCE initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->vce.idle_work); +return r; }static int vce_v2_0_hw_fini (void *handle)
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +5 -1
@@ -477,12 +477,16 @@ static int vce_v3_0_hw_init(void *handle)for (i =0 ; i < adev->vce.num_rings; i++) { r =amdgpu_ring_test_helper (&adev->vce.ring[i]);if (r) -return r; + goto error; }DRM_INFO ("VCE initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->vce.idle_work); +return r; }static int vce_v3_0_hw_fini (void *handle)
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +5 -1
@@ -530,12 +530,16 @@ static int vce_v4_0_hw_init(void *handle)for (i =0 ; i < adev->vce.num_rings; i++) { r =amdgpu_ring_test_helper (&adev->vce.ring[i]);if (r) -return r; + goto error; }DRM_INFO ("VCE initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->vce.idle_work); +return r; }static int vce_v4_0_hw_fini (void *handle)
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +3 -1
@@ -213,7 +213,9 @@ static int vcn_v1_0_hw_init(void *handle) goto done; done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +3 -1
@@ -248,7 +248,9 @@ static int vcn_v2_0_hw_init(void *handle) } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +3 -1
@@ -307,7 +307,9 @@ static int vcn_v2_5_hw_init(void *handle) } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +3 -1
@@ -372,7 +372,9 @@ static int vcn_v3_0_hw_init(void *handle) } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1254/2214 ovl: look up the index by the decoded origin
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 520ef67f47f69255695859b0008281a384d0bc20 ]
A file opened by file handle on an overlay with nfs_export=on can show the stale lower data of a file that was copied up to the upper layer. While the file opened this way stays in the inode cache, a lookup of the copied up file by path fails with ESTALE for all users. The open can also succeed for a file that was removed, where it has to fail with ESTALE. This happens with a handle that has one byte changed. The handle comes from an NFS client, or from a process that calls open_by_handle_at() with CAP_DAC_READ_SEARCH in the initial user namespace.
When a file in a lower layer is about to be modified, overlayfs first copies it to the upper layer (copy up). With nfs_export=on, each copy up also creates an entry in the index directory, a directory that overlayfs keeps for itself on the upper filesystem.
The handle of an overlay file that comes from a lower layer wraps the handle of its lower inode. Overlayfs calls this lower inode the origin. The overlay handle stays valid after a copy up.
To decode such a handle, ovl_lower_fh_to_d() first decodes the wrapped handle to the origin. If no overlay inode is cached for the origin, it looks in the index directory:
- An index entry there leads to the upper file.
- A whiteout, the marker that overlayfs uses for a removed file, means that the overlay file was removed.
The name of an index entry is the handle that copy up encoded for the origin, as a hex string.
ovl_lower_fh_to_d() builds the name for this lookup from the bytes that the caller passed in. But handles with different bytes can decode to the same inode:
- Overlayfs ignores some flag bits of the handle.
- A lower filesystem can accept a different fid type, extra bytes, or generation 0 for any generation.
Such a handle decodes to the origin but misses the index entry or the whiteout. So the decode returns an overlay inode that has only the lower file.
While that inode is cached, a path lookup of a copied up file fails with ESTALE, since the upper file that the lookup finds does not match the cached inode, which has none.
Reproduced on tmpfs and on ext4 with open_by_handle_at(), after a copy up and a mount cycle. A handle in which one flag bit, the fid type, the length or the generation was changed read the old lower data, and path lookups returned ESTALE.
Fix this by re-encoding the decoded origin and building the index name from that handle.
--- Documentation/filesystems/overlayfs.rst | 3 ++- fs/overlayfs/export.c | 4 ++-- fs/overlayfs/namei.c | 13 ++++++++++--- fs/overlayfs/overlayfs.h | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)
Documentation/filesystems/overlayfs.rst +2 -1
@@ -534,7 +534,8 @@ When decoding an overlay file handle, the following steps are followed: 1. Find underlying layer by UUID and path type information. 2. Decode the underlying filesystem file handle to underlying dentry. -3. For a lower file handle, lookup the handle in index directory by name. +3. For a lower file handle, encode the decoded underlying inode again and + lookup that handle in index directory by name. 4. If a whiteout is found in index, return ESTALE. This represents an overlay object that was deleted after its file handle was encoded. 5. For a non-directory, instantiate a disconnected overlay dentry from the
fs/overlayfs/export.c +2 -2
@@ -721,9 +721,9 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb, } } -/* Then lookup indexed upper/whiteout by origin fh */ +/* Then lookup indexed upper/whiteout by origin */ if (ofs->indexdir) { - index =ovl_get_index_fh (ofs, fh); + index =ovl_get_index_origin (ofs, origin.dentry); err =PTR_ERR (index);if (IS_ERR (index)) { index =NULL ;
fs/overlayfs/namei.c +10 -3
@@ -666,14 +666,21 @@ int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,return err; } -/* Lookup index by file handle for NFS export */ -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh) +/* +* Lookup index by decoded origin for NFS export. +* +* The name of an index is the hex of the file handle that copy up encoded. +* The bytes of the handle to decode cannot be used as the name, because a +* lower fs may decode many handles to the same inode. For example, it may +* ignore the fid type, extra fid bytes or a zero generation. +*/ +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin) {struct dentry *index;struct qstr name;int err; - err =ovl_get_index_name_fh (fh, &name); + err =ovl_get_index_name (ofs, origin, &name);if (err)return ERR_PTR (err);
fs/overlayfs/overlayfs.h +1 -1
@@ -500,7 +500,7 @@ struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index);int ovl_verify_index (struct ovl_fs *ofs,struct dentry *index);int ovl_get_index_name (struct ovl_fs *ofs,struct dentry *origin,struct qstr *name); -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh); +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin);struct dentry *ovl_lookup_index (struct ovl_fs *ofs,struct dentry *upper,struct dentry *origin,bool verify);int ovl_path_next (int idx,struct dentry *dentry,struct path *path);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1255/2214 drm/msm/hdmi: Handle msm_hdmi_power_on() errors during .atomic_pre_enable()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Kozlowski <[email protected]>
[ Upstream commit dd6ecace57851878e62367a6f1a26dd5b9aa217f ]
Properly handle power up failures during .atomic_pre_enable() by aborting the .atomic_pre_enable() to avoid accessing registers why blocks did not bring up. Otherwise this could lead to imprecise aborts when accessing MMIO while entire power domain is off.
Patchwork: https://patchwork.freedesktop.org/patch/752652/
--- drivers/gpu/drm/msm/hdmi/hdmi_bridge.c | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/msm/hdmi/hdmi_bridge.c +25 -5
@@ -17,7 +17,7 @@ void msm_hdmi_bridge_destroy(struct drm_bridge *bridge)msm_hdmi_hpd_disable (hdmi_bridge); } -static void msm_hdmi_power_on (struct drm_bridge *bridge) +static int msm_hdmi_power_on (struct drm_bridge *bridge) {struct drm_device *dev = bridge->dev;struct hdmi_bridge *hdmi_bridge =to_hdmi_bridge (bridge);
@@ -25,11 +25,15 @@ static void msm_hdmi_power_on(struct drm_bridge *bridge)const struct hdmi_platform_config *config = hdmi->config;int i, ret; -pm_runtime_get_sync (&hdmi->pdev->dev); + ret =pm_runtime_resume_and_get (&hdmi->pdev->dev); +if (ret) +return ret; ret =regulator_bulk_enable (config->pwr_reg_cnt, hdmi->pwr_regs); -if (ret) +if (ret) {DRM_DEV_ERROR (dev->dev,"failed to enable pwr regulator: %d\n" , ret); + goto err_pm_put; + }if (config->pwr_clk_cnt >0 ) {DBG ("pixclock: %lu" , hdmi->pixclock);
@@ -45,8 +49,19 @@ static void msm_hdmi_power_on(struct drm_bridge *bridge)if (ret) {DRM_DEV_ERROR (dev->dev,"failed to enable pwr clk: %s (%d)\n" , config->pwr_clk_names[i], ret); + goto err_clk_disable; } } + +return 0 ; + +err_clk_disable: +while (i--) +clk_disable_unprepare (hdmi->pwr_clks[i]); +regulator_bulk_disable (config->pwr_reg_cnt, hdmi->pwr_regs); +err_pm_put: +pm_runtime_put (&hdmi->pdev->dev); +return ret; }static void power_off (struct drm_bridge *bridge)
@@ -141,8 +156,13 @@ static void msm_hdmi_bridge_pre_enable(struct drm_bridge *bridge)DBG ("power up" );if (!hdmi->power_on) { -msm_hdmi_phy_resource_enable (phy); -msm_hdmi_power_on (bridge); +if (msm_hdmi_phy_resource_enable (phy)) +return ; + +if (msm_hdmi_power_on (bridge)) { +msm_hdmi_phy_resource_disable (phy); +return ; + } hdmi->power_on = true;if (hdmi->hdmi_mode) {msm_hdmi_config_avi_infoframe (hdmi);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1256/2214 iommu/virtio: Reset device before deleting virtqueues on probe failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 1f8efac19a0870cdfdf8477e447e5a07ddce9623 ]
viommu_probe() marks the device DRIVER_OK before populating the event virtqueue and registering the IOMMU device in sysfs. viommu_fill_evtq() hands the device a set of device-writable buffers through virtqueue_add_inbuf(), so from that point on the device may write into them and into the rings.
If either step fails, the error path deletes the virtqueues without resetting the device first. The event buffers are allocated with devm_kmalloc_array() and are released as probe unwinds, so the device can go on writing to memory that has been freed.
Reset the device before deleting the virtqueues, the way viommu_remove() already does.
Message-ID: <[email protected]>
--- drivers/iommu/virtio-iommu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/virtio-iommu.c +4 -2
@@ -1061,12 +1061,12 @@ static int viommu_probe(struct virtio_device *vdev)/* Populate the event queue with buffers */ ret =viommu_fill_evtq (viommu);if (ret) - goto err_free_vqs; + goto err_reset_vdev; ret =iommu_device_sysfs_add (&viommu->iommu, dev,NULL ,"%s" ,virtio_bus_name (vdev));if (ret) - goto err_free_vqs; + goto err_reset_vdev;iommu_device_register (&viommu->iommu, &viommu_ops, parent_dev);
@@ -1101,6 +1101,8 @@ static int viommu_probe(struct virtio_device *vdev) err_unregister:iommu_device_sysfs_remove (&viommu->iommu);iommu_device_unregister (&viommu->iommu); +err_reset_vdev: + vdev->config->reset (vdev); err_free_vqs: vdev->config->del_vqs (vdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1257/2214 drm/amdgpu: enable Navi 48-bit IH timestamp counter
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Philip Yang <[email protected]>
[ Upstream commit 8888e2fe9c77983a9644cd9bf0d23ca9023b16d4 ]
By default this timestamp is 32 bit counter. It gets overflowed in around 10 minutes.
Stable-dep-of: 146b96974b33 ("drm/amdgpu: clear RB_OVERFLOW bit when enabling interrupts for navi10_ih")
--- drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +1 -0
@@ -160,6 +160,7 @@ static int navi10_ih_toggle_ring_interrupts(struct amdgpu_device *adev, tmp =RREG32 (ih_regs->ih_rb_cntl); tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,RB_ENABLE , (enable ?1 :0 )); + tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,RB_GPU_TS_ENABLE ,1 );/* enable_intr field is only valid in ring0 */ if (ih == &adev->irq.ih) tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,ENABLE_INTR , (enable ?1 :0 ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1258/2214 drm/amdgpu: clear RB_OVERFLOW bit when enabling interrupts for navi10_ih
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Milan Milicevic <[email protected]>
[ Upstream commit 146b96974b33b8cca52755ffed3cd24a82836013 ]
Port this change to navi10_ih.c:
commit afbf7955ff01 ("drm/amdgpu: clear RB_OVERFLOW bit when enabling interrupts")
Setting IH_RB_WPTR to 0 does not clear RB_OVERFLOW if RB_ENABLE is not set. Pulse WPTR_OVERFLOW_CLEAR after RB_ENABLE (and with WPTR_OVERFLOW_ENABLE) so overflow is cleared when interrupts are enabled.
--- drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +28 -0
@@ -161,6 +161,34 @@ static int navi10_ih_toggle_ring_interrupts(struct amdgpu_device *adev, tmp =RREG32 (ih_regs->ih_rb_cntl); tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,RB_ENABLE , (enable ?1 :0 )); tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,RB_GPU_TS_ENABLE ,1 ); + +if (enable) { +/* Unset the CLEAR_OVERFLOW bit to make sure the next step +* is switching the bit from 0 to 1 +*/ + tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,WPTR_OVERFLOW_CLEAR ,0 ); +if (amdgpu_sriov_vf (adev) &&amdgpu_sriov_reg_indirect_ih (adev)) { +if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) +return -ETIMEDOUT ; + }else { +WREG32_NO_KIQ (ih_regs->ih_rb_cntl, tmp); + } + +/* Clear RB_OVERFLOW bit */ + tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,WPTR_OVERFLOW_CLEAR ,1 ); +if (amdgpu_sriov_vf (adev) &&amdgpu_sriov_reg_indirect_ih (adev)) { +if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) +return -ETIMEDOUT ; + }else { +WREG32_NO_KIQ (ih_regs->ih_rb_cntl, tmp); + } + +/* Unset the CLEAR_OVERFLOW bit immediately so new overflows +* can be detected. +*/ + tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,WPTR_OVERFLOW_CLEAR ,0 ); + } +/* enable_intr field is only valid in ring0 */ if (ih == &adev->irq.ih) tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,ENABLE_INTR , (enable ?1 :0 ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1259/2214 drm/amdgpu: keep the CS user fence BO in GTT
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 7a56d929dc2304edaa6231e1eb5eb82b7e8b74a9 ]
The CS ioctl hands the GPU the GART address of the user fence BO, but since the BO keeps its own preferred and allowed domains, it no longer makes sure the BO is in GTT. A user fence in a VRAM BO, which only needs to be a page in size, gets its address from amdgpu_bo_gpu_offset(), which warns about non-contiguous VRAM. On navi31, a CS with a user fence in a 4K VRAM BO, or in one created with AMDGPU_GEM_CREATE_VM_ALWAYS_VALID:
WARNING: amdgpu_object.c:1531 at amdgpu_bo_gpu_offset+0x86/0xb0 [amdgpu], CPU#11: cs_gem_checks/18393 RIP: 0010:amdgpu_bo_gpu_offset+0x86/0xb0 [amdgpu] Call Trace: <TASK> amdgpu_cs_parser_bos.isra.0+0x4eb/0x850 [amdgpu] amdgpu_cs_ioctl+0x97e/0x2510 [amdgpu] drm_ioctl_kernel+0xac/0x110 [drm] drm_ioctl+0x2c6/0x5b0 [drm] __x64_sys_ioctl+0xa0/0xf0 do_syscall_64+0xa3/0x4d0 entry_SYSCALL_64_after_hwframe+0x76/0x7e
and BOs which can't be in GTT at all, like GWS or OA ones of a page in size, pass the checks as well.
Only take BOs which can't be anywhere else than in GTT as user fence, which the CS then validates there along with its other BOs. While at it, detect userptrs with amdgpu_ttm_tt_is_userptr(); amdgpu_ttm_tt_get_usermm() returns NULL once the task which created the userptr is gone.
v2: only take BOs which can only be in GTT instead of special casing the
user fence BO in the validation, use amdgpu_ttm_tt_is_userptr() (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -1
@@ -62,7 +62,12 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,if (size !=PAGE_SIZE || data->offset > (size -8 ))return -EINVAL ; -if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm)) +if (amdgpu_ttm_tt_is_userptr (bo->tbo.ttm)) +return -EINVAL ; + +/* The GPU writes the user fence through the GART */ +if (bo->preferred_domains !=AMDGPU_GEM_DOMAIN_GTT && + bo->allowed_domains !=AMDGPU_GEM_DOMAIN_GTT )return -EINVAL ; *offset = data->offset;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1260/2214 ksmbd: do not read past the DACL in the access denied debug message
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 8296a64df5448548f410fb246c1d88a93609602b ]
When smb_check_perm_dacl() falls back to the POSIX ACL and then denies the request, its debug message prints the access mask of the ACE that the second DACL walk stopped at. On that path the walk ran to the end of the DACL, so the pointer is one past the last ACE. If the DACL is the last part of the stored security descriptor, the message reads 4 bytes past the buffer, and KASAN reports a slab-out-of-bounds read in smb_check_perm_dacl().
Print the requested and allowed masks instead. They are what the check compares.
--- fs/ksmbd/smbacl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ksmbd/smbacl.c +2 -2
@@ -1417,8 +1417,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, check_access_bits:if (granted & ~(access_bits |FILE_READ_ATTRIBUTES |READ_CONTROL |WRITE_DAC |DELETE )) { -ksmbd_debug (SMB ,"Access denied with winACL, granted : %x, access_req : %x\n" , - granted,le32_to_cpu (ace->access_req)); +ksmbd_debug (SMB ,"Access denied with winACL, requested : %x, allowed : %x\n" , + granted, access_bits); rc = -EACCES ; goto err_out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1261/2214 scsi: target: Fix demo-mode dynamic ACL dev-entry UAF vs LUN teardown
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Zhang <[email protected]>
[ Upstream commit 6a6e7d7230cd4e0a6c003bae5b85bf37a1e77b94 ]
A demo-mode (generate_node_acls=1) login that allocates a dynamic NodeACL populates that ACL's per-LUN dev entries in core_tpg_add_node_to_devs() *before* the ACL is linked onto tpg->acl_node_list by target_add_node_acl():
core_tpg_check_initiator_node_acl():
...
core_tpg_add_node_to_devs(acl, tpg, NULL); /* builds deves */
target_add_node_acl(acl); /* only now listed */
The LUN teardown sweep, core_clear_lun_from_tpg(), enumerates only tpg->acl_node_list, so a dev entry whose ACL is still in the window above is invisible to the sweep and is never disabled. It is left on the se_lun->lun_deve_list after core_tpg_remove_lun() frees the se_lun; when the same unpacked_lun is later re-added and the se_lun is reallocated at the same address, the stale dev entry is rediscovered by target_nacl_find_deve() and core_enable_device_list_for_node() corrupts lun_deve_list:
BUG: KASAN: slab-use-after-free ... core_enable_device_list_for_node+0x5ce/0x880 core_tpg_add_node_to_devs+0x169/0x190 core_dev_add_lun+0x146/0x190 target_fabric_port_link+0xe9/0x1b0 configfs_symlink+0x381/0xae0 __x64_sys_symlink+0x55/0x80
The demo-mode login path that drives the ACL/dev-entry creation is reachable by an unauthenticated initiator; the colliding LUN add/remove is a local configfs operation.
Commit 49cb77e297dc ("target: Avoid mappedlun symlink creation during lun shutdown") introduced se_lun->lun_shutdown and guarded the *explicit* ACL MappedLUN path (target_fabric_mappedlun_link()), but the demo-mode automatic path, core_tpg_add_node_to_devs() -> core_enable_device_list_for_node(), was never given the equivalent guard, and the publish-after-populate ordering in core_tpg_check_initiator_node_acl() was left unchanged.
Fix it in three cooperating parts:
1) Publish the dynamic NodeACL onto acl_node_list *before* creating its dev entries, so the teardown sweep can observe them.
2) Refuse to attach a dev entry to an se_lun that is shutting down, checked under nacl->lun_entry_mutex -- the same lock the sweep takes -- so once the sweep has passed an ACL any later enable for that LUN observes lun_shutdown and skips it.
3) In core_enable_device_list_for_node(), insert the new dev entry onto lun->lun_deve_list while still holding nacl->lun_entry_mutex, in both the replace and the new-entry branch. Previously the entry was added to nacl->lun_entry_hlist under the mutex but to lun->lun_deve_list only after dropping it; with the ACL now published early, the sweep could take the mutex in that gap, find the entry on the hlist, core_disable_device_list_for_node() it (list_del() on the not-yet- linked lun_link succeeds and the entry is freed), and then the enable would list_add_tail() the freed entry back onto lun_deve_list. Linking both lists under the mutex makes enable and the sweep mutually exclusive, closing that window.
core_tpg_add_node_to_devs() already ignores the return value of core_enable_device_list_for_node(), so a shutting-down LUN is simply skipped.
--- drivers/target/target_core_device.c | 18 +++++++++++++++--- drivers/target/target_core_tpg.c | 10 +++++++++- 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/target/target_core_device.c +15 -3
@@ -327,6 +327,19 @@ int core_enable_device_list_for_node( new->attach_count++;mutex_lock (&nacl->lun_entry_mutex); +/* +* Do not attach a new dev entry to an se_lun that is being torn down. +* lun_shutdown is set by core_tpg_remove_lun() before its +* core_clear_lun_from_tpg() sweep; checking it here under the same +* nacl->lun_entry_mutex the sweep takes guarantees that once the sweep +* has passed this ACL no dev entry can be left dangling on the +* se_lun->lun_deve_list that is about to be freed. +*/ +if (lun->lun_shutdown) { +mutex_unlock (&nacl->lun_entry_mutex); +kfree (new); +return -ENODEV ; + } orig =target_nacl_find_deve (nacl, mapped_lun);if (orig && orig->se_lun) { struct se_lun *orig_lun = rcu_dereference_check(orig->se_lun,
@@ -354,12 +367,12 @@ int core_enable_device_list_for_node(rcu_assign_pointer (new->se_lun_acl, lun_acl);hlist_del_rcu (&orig->link);hlist_add_head_rcu (&new->link, &nacl->lun_entry_hlist); -mutex_unlock (&nacl->lun_entry_mutex);spin_lock (&lun->lun_deve_lock);list_del (&orig->lun_link);list_add_tail (&new->lun_link, &lun->lun_deve_list);spin_unlock (&lun->lun_deve_lock); +mutex_unlock (&nacl->lun_entry_mutex);kref_put (&orig->pr_kref, target_pr_kref_release);wait_for_completion (&orig->pr_comp);
@@ -372,11 +385,10 @@ int core_enable_device_list_for_node(rcu_assign_pointer (new->se_lun, lun);rcu_assign_pointer (new->se_lun_acl, lun_acl);hlist_add_head_rcu (&new->link, &nacl->lun_entry_hlist); -mutex_unlock (&nacl->lun_entry_mutex); -spin_lock (&lun->lun_deve_lock);list_add_tail (&new->lun_link, &lun->lun_deve_list);spin_unlock (&lun->lun_deve_lock); +mutex_unlock (&nacl->lun_entry_mutex);target_luns_data_has_changed (nacl, new, true);return 0 ;
drivers/target/target_core_tpg.c +9 -1
@@ -265,6 +265,15 @@ struct se_node_acl *core_tpg_check_initiator_node_acl(kref_get (&acl->acl_kref); acl->dynamic_node_acl =1 ; +/* +* Publish the dynamic NodeACL on tpg->acl_node_list before creating +* its demo-mode MappedLUN dev entries below, so that a concurrent LUN +* teardown sweep (core_clear_lun_from_tpg(), which walks acl_node_list) +* can observe and disable those dev entries. Otherwise a dev entry can +* be left on an se_lun->lun_deve_list that is about to be freed. +*/ +target_add_node_acl (acl); +/* * Here we only create demo-mode MappedLUNs from the active * TPG LUNs if the fabric is not explicitly asking for
@@ -274,7 +283,6 @@ struct se_node_acl *core_tpg_check_initiator_node_acl( (tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg) != 1))core_tpg_add_node_to_devs (acl, tpg,NULL ); -target_add_node_acl (acl);return acl; }EXPORT_SYMBOL (core_tpg_check_initiator_node_acl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1262/2214 KVM: arm64: vgic-its: Dont map an LPI from more than one event
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit de81b28f0b83b22163d7d9a9b708d7aa912e0ef7 ]
KVM keeps one vgic_irq per LPI. A MAPTI of an LPI whose vgic_irq already exists reuses it for the new ITE and leaves its target vCPU as it was. Mapping one LPI from two events is UNPREDICTABLE (IHI 0069H.b, 5.2.10), but nothing stops a guest from doing it. If the first MAPTI names a collection the guest never maps and the second a mapped one, the LPI translates through the second event with a NULL target vCPU.
When the VMM routes an assigned device's MSI to that event on a host with GICv4 enabled, kvm_vgic_v4_set_forwarding() takes the vPE from the NULL target vCPU and the host oopses:
Unable to handle kernel paging request at virtual address 0000000000001980 [...] Call trace: its_build_vmapti_cmd (drivers/irqchip/irq-gic-v3-its.c:943) (P) its_irq_set_vcpu_affinity (drivers/irqchip/irq-gic-v3-its.c:1380) irq_set_vcpu_affinity (kernel/irq/manage.c:670) its_map_vlpi (drivers/irqchip/irq-gic-v4.c:326) kvm_vgic_v4_set_forwarding (arch/arm64/kvm/vgic/vgic-v4.c:485) kvm_arch_irq_bypass_add_producer (arch/arm64/kvm/arm.c:2977) irq_bypass_register_consumer (virt/lib/irqbypass.c:44) kvm_irqfd (arch/arm64/kvm/../../../virt/kvm/eventfd.c:496) kvm_vm_ioctl (arch/arm64/kvm/../../../virt/kvm/kvm_main.c:5270)
Track in each vgic_irq whether an ITE maps it. Drop a MAPTI of an LPI that is already mapped, as a failed MAPTI already is. Restoring the ITS tables keeps the first ITE it reads for each LPI and drops any later one, so a guest saved with a double mapping still restores. Key the check on the mapping, not on the vgic_irq. A vgic_irq outlives its ITE while anything holds a reference to it, such as the vCPU it was last queued on. A later MAPTI of such an LPI succeeds as before, and now retargets it to its collection.
--- arch/arm64/kvm/vgic/vgic-its.c | 40 ++++++++++++++++++++++++++++++++-- include/kvm/arm_vgic.h | 1 + 2 files changed, 39 insertions(+), 2 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +38 -2
@@ -821,13 +821,20 @@ int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)/* Requires the its_lock to be held. */ static void its_free_ite (struct kvm *kvm,struct its_ite *ite) { +unsigned long flags; +list_del (&ite->ite_list);/* This put matches the get in vgic_add_lpi. */ if (ite->irq) { +raw_spin_lock_irqsave (&ite->irq->irq_lock, flags);if (ite->irq->hw)WARN_ON (its_unmap_vlpi (ite->irq->host_irq)); + ite->irq->hw = false; + ite->irq->mapped = false; +raw_spin_unlock_irqrestore (&ite->irq->irq_lock, flags); +vgic_put_irq (kvm, ite->irq); }
@@ -1074,6 +1081,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,struct its_device *device;struct its_collection *collection, *new_coll =NULL ;struct vgic_irq *irq; +unsigned long flags;int lpi_nr; device =find_its_device (its, device_id);
@@ -1114,13 +1122,27 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, vcpu =kvm_get_vcpu (kvm, collection->target_addr); irq =vgic_add_lpi (kvm, lpi_nr, vcpu); +if (!IS_ERR (irq)) { +/* Mapping one LPI from two events is UNPREDICTABLE: the first ITE keeps it. */ +raw_spin_lock_irqsave (&irq->irq_lock, flags); +if (!irq->mapped) { + irq->mapped = true; + irq->target_vcpu = vcpu; + ite->irq = irq; + } +raw_spin_unlock_irqrestore (&irq->irq_lock, flags); + +if (!ite->irq) { +vgic_put_irq (kvm, irq); + irq =ERR_PTR (-EEXIST ); + } + }if (IS_ERR (irq)) {if (new_coll)vgic_its_free_collection (its, coll_id);its_free_ite (kvm, ite);return PTR_ERR (irq); } - ite->irq = irq;return 0 ; }
@@ -2186,6 +2208,7 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,struct vgic_irq *irq;u32 coll_id, lpi_id;struct its_ite *ite; +unsigned long flags;u32 offset; val = *p;
@@ -2219,7 +2242,20 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id, irq =vgic_add_lpi (kvm, lpi_id, vcpu);if (IS_ERR (irq))return PTR_ERR (irq); - ite->irq = irq; + +raw_spin_lock_irqsave (&irq->irq_lock, flags); +if (!irq->mapped) { + irq->mapped = true; + irq->target_vcpu = vcpu; + ite->irq = irq; + } +raw_spin_unlock_irqrestore (&irq->irq_lock, flags); + +/* Drop an ITE whose LPI another ITE maps, as MAPTI does. */ +if (!ite->irq) { +vgic_put_irq (kvm, irq); +its_free_ite (kvm, ite); + }return offset; }
include/kvm/arm_vgic.h +1 -0
@@ -136,6 +136,7 @@ struct vgic_irq {bool active;/* not used for LPIs */ bool enabled;bool hw;/* Tied to HW IRQ */ +bool mapped;/* LPIs: mapped by an ITE */ struct kref refcount;/* Used for LPIs */ u32 hwintid;/* HW INTID number */ unsigned int host_irq;/* linux irq corresponding to hwintid */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1263/2214 l2tp: snapshot sequencing state when building transmit headers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit d06ae66516e1aaf023808912af6292aef09d46c3 ]
Updates to send_seq from netlink, PPP setsockopt and receive-side negotiation race with packet transmission. The header length is updated separately, while transmit reads both fields repeatedly without synchronization.
For example, transmit can push a ten-byte L2TPv2 header, then a concurrent writer clears send_seq before the header builder reads it. The builder writes only six bytes, leaving four bytes of uninitialized skb headroom in the outgoing packet. The reverse mismatch overwrites the beginning of the payload. A later hdr_len read can also make the UDP length disagree with the skb length.
KCSAN reported:
BUG: KCSAN: data-race in l2tp_session_set_header_len / l2tp_xmit_skb
write to 0xffff888100d0944a of 2 bytes by task 116 on cpu 1:
l2tp_session_set_header_len+0x81/0xc0 l2tp_nl_cmd_session_modify+0x122/0x2c0 genl_family_rcv_msg_doit+0x170/0x1d0
read to 0xffff888100d0944a of 2 bytes by task 115 on cpu 0:
l2tp_xmit_skb+0x9c/0xc80 pppol2tp_sendmsg+0x21c/0x2a0 __sys_sendto+0x28c/0x2a0
The bug can lead to leak kernel base address for KASLR bypass, the corresponding reproducer can be provided per request.
Initialize hdr_len to the maximum header size and leave it unchanged when sequencing is toggled. Snapshot send_seq once per packet and use that snapshot for the actual header length and header construction, including the sequence flag. Use the same length for headroom, the header push and the UDP length. PPP callers can safely reserve the maximum size; L2TPv3 header sizes do not depend on sequencing.
Make send_seq a separate bool so READ_ONCE() and WRITE_ONCE() can be used without sharing a bitfield storage unit with other configuration flags. Preserve the netlink attribute's existing low-bit truncation.
--- net/l2tp/l2tp_core.c | 47 ++++++++++++++++++++--------------------- net/l2tp/l2tp_core.h | 5 ++--- net/l2tp/l2tp_debugfs.c | 4 ++-- net/l2tp/l2tp_netlink.c | 9 ++++---- net/l2tp/l2tp_ppp.c | 7 +++--- 5 files changed, 34 insertions(+), 38 deletions(-)
net/l2tp/l2tp_core.c +23 -24
@@ -695,10 +695,9 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,* check if we sre sending sequence numbers and if not, * configure it so. */ -if (!session->lns_mode && !session->send_seq) { +if (!session->lns_mode && !READ_ONCE (session->send_seq)) {trace_session_seqnum_lns_enable (session); - session->send_seq =1 ; -l2tp_session_set_header_len (session, tunnel->version); +WRITE_ONCE (session->send_seq, true); } }else {/* No sequence numbers.
@@ -716,11 +715,10 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,* If we're the LNS and we're sending sequence numbers, the * LAC is broken. Discard the frame. */ -if (!session->lns_mode && session->send_seq) { +if (!session->lns_mode &&READ_ONCE (session->send_seq)) {trace_session_seqnum_lns_disable (session); - session->send_seq =0 ; -l2tp_session_set_header_len (session, tunnel->version); - }else if (session->send_seq) { +WRITE_ONCE (session->send_seq, false); + }else if (READ_ONCE (session->send_seq)) {pr_debug_ratelimited ("%s: recv data has no seq numbers when required. Discarding.\n" , session->name);atomic_long_inc (&session->stats.rx_seq_discards);
@@ -930,7 +928,8 @@ EXPORT_SYMBOL_GPL(l2tp_udp_encap_recv);/* Build an L2TP header for the session into the buffer provided. */ -static int l2tp_build_l2tpv2_header (struct l2tp_session *session,void *buf) +static int l2tp_build_l2tpv2_header (struct l2tp_session *session,void *buf, +bool send_seq) {struct l2tp_tunnel *tunnel = session->tunnel;__be16 *bufp = buf;
@@ -939,14 +938,14 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf)u32 tunnel_id = tunnel->peer_tunnel_id;u32 session_id = session->peer_session_id; -if (session->send_seq) +if (send_seq) flags |=L2TP_HDRFLAG_S ;/* Setup L2TP header. */ *bufp++ =htons (flags); *bufp++ =htons (tunnel_id); *bufp++ =htons (session_id); -if (session->send_seq) { +if (send_seq) { *bufp++ =htons (session->ns); *bufp++ =0 ; session->ns++;
@@ -957,7 +956,8 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf)return bufp - optr; } -static int l2tp_build_l2tpv3_header (struct l2tp_session *session,void *buf) +static int l2tp_build_l2tpv3_header (struct l2tp_session *session,void *buf, +bool send_seq) {struct l2tp_tunnel *tunnel = session->tunnel;char *bufp = buf;
@@ -983,7 +983,7 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf)if (session->l2specific_type ==L2TP_L2SPECTYPE_DEFAULT ) {u32 l2h =0 ; -if (session->send_seq) { +if (send_seq) { l2h =0x40000000 | session->ns; session->ns++; session->ns &=0xffffff ;
@@ -1017,19 +1017,24 @@ static int l2tp_xmit_queue(struct l2tp_tunnel *tunnel, struct sk_buff *skb, strustatic int l2tp_xmit_core (struct l2tp_session *session,struct sk_buff *skb,unsigned int *len) {struct l2tp_tunnel *tunnel = session->tunnel; +bool send_seq =READ_ONCE (session->send_seq);unsigned int data_len = skb->len;struct sock *sk = tunnel->sock; +u16 hdr_len = session->hdr_len;int headroom, uhlen, udp_len;int ret =NET_XMIT_SUCCESS ;struct inet_sock *inet;struct udphdr *uh; +if (tunnel->version ==L2TP_HDR_VER_2 && !send_seq) + hdr_len -=4 ; +/* Check that there's enough headroom in the skb to insert IP, * UDP and L2TP headers. If not enough, expand it to * make room. Adjust truesize. */ uhlen = (tunnel->encap ==L2TP_ENCAPTYPE_UDP ) ?sizeof (*uh) :0 ; - headroom =NET_SKB_PAD +sizeof (struct iphdr ) + uhlen + session->hdr_len; + headroom =NET_SKB_PAD +sizeof (struct iphdr ) + uhlen + hdr_len;if (skb_cow_head (skb, headroom)) {kfree_skb (skb);return NET_XMIT_DROP ;
@@ -1037,9 +1042,9 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns/* Setup L2TP header */ if (tunnel->version ==L2TP_HDR_VER_2 ) -l2tp_build_l2tpv2_header (session,__skb_push (skb, session->hdr_len)); +l2tp_build_l2tpv2_header (session,__skb_push (skb, hdr_len), send_seq);else -l2tp_build_l2tpv3_header (session,__skb_push (skb, session->hdr_len)); +l2tp_build_l2tpv3_header (session,__skb_push (skb, hdr_len), send_seq);/* Reset skb netfilter state */ memset (&(IPCB (skb)->opt),0 ,sizeof (IPCB (skb)->opt));
@@ -1082,7 +1087,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns uh =udp_hdr (skb); uh->source = inet->inet_sport; uh->dest = inet->inet_dport; - udp_len = uhlen + session->hdr_len + data_len; + udp_len = uhlen + hdr_len + data_len;if (udp_len >U16_MAX ) {kfree_skb (skb); ret =NET_XMIT_DROP ;
@@ -1578,15 +1583,10 @@ void l2tp_session_delete(struct l2tp_session *session) }EXPORT_SYMBOL_GPL (l2tp_session_delete); -/* We come here whenever a session's send_seq, cookie_len or -* l2specific_type parameters are set. -*/ -void l2tp_session_set_header_len (struct l2tp_session *session,int version) +static void l2tp_session_set_header_len (struct l2tp_session *session,int version) {if (version ==L2TP_HDR_VER_2 ) { - session->hdr_len =6 ; -if (session->send_seq) - session->hdr_len +=4 ; + session->hdr_len =10 ; }else { session->hdr_len =4 + session->cookie_len; session->hdr_len +=l2tp_get_l2specific_len (session);
@@ -1594,7 +1594,6 @@ void l2tp_session_set_header_len(struct l2tp_session *session, int version) session->hdr_len +=4 ; } } -EXPORT_SYMBOL_GPL (l2tp_session_set_header_len);struct l2tp_session *l2tp_session_create (int priv_size,struct l2tp_tunnel *tunnel,u32 session_id,u32 peer_session_id,struct l2tp_session_cfg *cfg)
net/l2tp/l2tp_core.h +2 -3
@@ -79,7 +79,7 @@ struct l2tp_session {u8 peer_cookie[8 ];int peer_cookie_len;u16 l2specific_type; -u16 hdr_len; +u16 hdr_len;/* maximum L2TP header length */ u32 nr;/* session NR state (receive) */ u32 ns;/* session NR state (send) */ struct sk_buff_head reorder_q;/* receive reorder queue */
@@ -93,8 +93,8 @@ struct l2tp_session {char name[L2TP_SESSION_NAME_MAX ];/* for logging */ char ifname[IFNAMSIZ ]; +bool send_seq;/* send packets with sequence numbers? */ unsigned int recv_seq:1; /* expect receive packets with sequence numbers? */ - unsigned int send_seq:1; /* send packets with sequence numbers? */ unsigned int lns_mode:1; /* behave as LNS?* LAC enables sequence numbers under LNS control. */
@@ -261,7 +261,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,int l2tp_udp_encap_recv (struct sock *sk,struct sk_buff *skb);/* Transmit path helpers for sending packets over the tunnel socket. */ -void l2tp_session_set_header_len (struct l2tp_session *session,int version);int l2tp_xmit_skb (struct l2tp_session *session,struct sk_buff *skb);/* Pseudowire management.
net/l2tp/l2tp_debugfs.c +2 -2
@@ -185,12 +185,12 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) session->pwtype ==L2TP_PWTYPE_ETH ?"ETH" : session->pwtype ==L2TP_PWTYPE_PPP ?"PPP" : ""); -if (session->send_seq || session->recv_seq) +if (READ_ONCE (session->send_seq) || session->recv_seq)seq_printf (m," nr %hu, ns %hu\n" , session->nr, session->ns);seq_printf (m," refcnt %d\n" ,refcount_read (&session->ref_count));seq_printf (m," config 0/0/%c/%c/-/%s %08x %u\n" , session->recv_seq ?'R' :'-' , - session->send_seq ?'S' :'-' , +READ_ONCE (session->send_seq) ?'S' :'-' , session->lns_mode ?"LNS" :"LAC" ,0 ,jiffies_to_msecs (session->reorder_timeout));
net/l2tp/l2tp_netlink.c +4 -5
@@ -689,10 +689,9 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *infif (info->attrs[L2TP_ATTR_RECV_SEQ ]) session->recv_seq =nla_get_u8 (info->attrs[L2TP_ATTR_RECV_SEQ ]); -if (info->attrs[L2TP_ATTR_SEND_SEQ ]) { - session->send_seq =nla_get_u8 (info->attrs[L2TP_ATTR_SEND_SEQ ]); -l2tp_session_set_header_len (session, session->tunnel->version); - } +if (info->attrs[L2TP_ATTR_SEND_SEQ ]) +WRITE_ONCE (session->send_seq, +nla_get_u8 (info->attrs[L2TP_ATTR_SEND_SEQ ]) &1 );if (info->attrs[L2TP_ATTR_LNS_MODE ]) session->lns_mode =nla_get_u8 (info->attrs[L2TP_ATTR_LNS_MODE ]);
@@ -735,7 +734,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl (session->peer_cookie_len &&nla_put (skb,L2TP_ATTR_PEER_COOKIE , session->peer_cookie_len, session->peer_cookie)) ||nla_put_u8 (skb,L2TP_ATTR_RECV_SEQ , session->recv_seq) || -nla_put_u8 (skb,L2TP_ATTR_SEND_SEQ , session->send_seq) || +nla_put_u8 (skb,L2TP_ATTR_SEND_SEQ ,READ_ONCE (session->send_seq)) ||nla_put_u8 (skb,L2TP_ATTR_LNS_MODE , session->lns_mode) || (l2tp_tunnel_uses_xfrm (tunnel) && nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1)) ||
net/l2tp/l2tp_ppp.c +3 -4
@@ -1187,14 +1187,13 @@ static int pppol2tp_session_setsockopt(struct sock *sk, err = -EINVAL ;break ; } - session->send_seq = !!val; +WRITE_ONCE (session->send_seq, !!val); {struct pppox_sock *po =pppox_sk (sk); po->chan.hdrlen = val ?PPPOL2TP_L2TP_HDR_SIZE_SEQ :PPPOL2TP_L2TP_HDR_SIZE_NOSEQ ; } -l2tp_session_set_header_len (session, session->tunnel->version);break ;case PPPOL2TP_SO_LNSMODE :
@@ -1304,7 +1303,7 @@ static int pppol2tp_session_getsockopt(struct sock *sk,break ;case PPPOL2TP_SO_SENDSEQ : - *val = session->send_seq; + *val =READ_ONCE (session->send_seq);break ;case PPPOL2TP_SO_LNSMODE :
@@ -1550,7 +1549,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) state, user_data_ok);seq_printf (m," 0/0/%c/%c/%s %08x %u\n" , session->recv_seq ?'R' :'-' , - session->send_seq ?'S' :'-' , +READ_ONCE (session->send_seq) ?'S' :'-' , session->lns_mode ?"LNS" :"LAC" ,0 ,jiffies_to_msecs (session->reorder_timeout));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1264/2214 aio: fix NULL deref when a fault races ring truncation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit d53b5aa5cfae27e4d236fc0ab9581085d27f7d33 ]
The aio ring lives in a file on the aio pseudo filesystem and the ring VMA uses filemap_fault(). aio_ctx_aops doesn't have a ->read_folio because aio_setup_ring() puts all folios of the ring into the page cache. So a fault on the ring only works as long as it finds its folio in the page cache. If it doesn't, filemap_fault() calls ->read_folio without checking and we jump to NULL.
We already fixed this twice this year. A forked child could inherit the ring mapping, fixed by commit c03ce4173c7b ("fs: aio: set VMA_DONTCOPY_BIT in mmap to fix NULL-pointer-dereference error"). And a partial mremap() could leave part of the ring mapped, fixed by commit 3adf7ae18bf4 ("fs: aio: reject partial mremap to avoid Null-pointer-dereference error"). Both times a VMA outlived the ring and the ring file was truncated under it.
There's a third way to get there. kill_ioctx() and the error path of ioctx_alloc() unmap the ring with vm_munmap() and ignore the return value. If vm_munmap() has to wait for mmap_lock and a fatal signal is pending it returns -EINTR and the VMA stays. free_ioctx() then calls put_aio_ring_file() which truncates the ring file to zero. A fault that passed the i_size check in filemap_fault() before that doesn't find its folio anymore, allocates a new one and calls ->read_folio:
fault on the ring io_destroy() with SIGKILL pending
================= =================================
vm_munmap() returns -EINTR
filemap_fault()
i_size check passes
free_ioctx()
put_aio_ring_file()
truncate_setsize(inode, 0)
no folio, allocate a new one
filemap_read_folio()
->read_folio == NULL
All that's needed is a second process that shares the mm. If a CLONE_VM child calls io_destroy() and gets SIGKILLed while it waits for mmap_lock the ring stays mapped for the threads of the parent. Any user can do that.
Instead of plugging the routes one by one give the ring a ->read_folio that unlocks the folio and returns -EIO. All folios of a live ring are in the page cache so a fault can only end up there if the ring was truncated. The fault now gets SIGBUS. Nothing else reads the ring file and the aio filesystem uses noop_backing_dev_info so there's no readahead either.
Making vm_munmap() unkillable in those two places would only close this one route and bring back what commit ae7987835643 ("mm: make vm_munmap killable") fixed.
--- fs/aio.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/aio.c +11 -0
@@ -454,7 +454,18 @@ static int aio_migratepage(struct address_space *mapping, struct page *new, }#endif +/* +* filemap_fault() reads a page that it did not find in the page cache. All +* pages of a live ring are there, so the ring was truncated under the fault. +*/ +static int aio_readpage (struct file *file,struct page *page) +{ +unlock_page (page); +return -EIO ; +} +static const struct address_space_operations aio_ctx_aops = { + .readpage = aio_readpage, .set_page_dirty = __set_page_dirty_no_writeback, #if IS_ENABLED(CONFIG_MIGRATION) .migratepage = aio_migratepage,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1265/2214 mm/huge_memory: fix truncate racing with PMD zapping
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit e6a07d29b0a60f3a4cfe77fe34eeb4b3fb38d6c4 ]
zap_huge_pmd_folio() removes the rmap before calling folio_mark_dirty(). If this was the last mapping, truncation can skip unmapping the folio and proceed without waiting for the PMD lock, racing with dirtying.
ifs_set_range_dirty() can oops if MADV_DONTNEED races with ftruncate() on XFS, when we get the folio set dirty after it was found to not be mapped anymore.
Move folio_mark_dirty() and folio_mark_accessed() before rmap removal, matching the PTE zap path. This keeps the folio mapped while updating its state, so truncation must wait for the page table lock.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/huge_memory.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/huge_memory.c +6 -2
@@ -1622,8 +1622,6 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,if (pmd_present (orig_pmd)) { page =pmd_page (orig_pmd); -page_remove_rmap (page, true); -VM_BUG_ON_PAGE (page_mapcount (page) <0 , page);VM_BUG_ON_PAGE (!PageHead (page), page); }else if (thp_migration_supported ()) {swp_entry_t entry;
@@ -1647,6 +1645,12 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,set_page_dirty (page); } +/* Remove the rmap after transferring the dirty bit to the page. */ +if (pmd_present (orig_pmd)) { +page_remove_rmap (page, true); +VM_BUG_ON_PAGE (page_mapcount (page) <0 , page); + } +spin_unlock (ptl);if (flush_needed)tlb_remove_page_size (tlb, page,HPAGE_PMD_SIZE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1266/2214 udf: fix preallocation discarding before an empty allocation extent
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 0c52750caaaccee8b0e929450fe6538ec4985722 ]
udf_discard_prealloc() finds the last extent of a file by peeking at the next one with udf_next_aext() and stopping when that returns 0. The peek reads into eloc and elen, and the code then uses them as the last extent. But when udf_next_aext() returns 0 they hold no defined
value: if the extent list ends in a continuation descriptor that leads to an empty allocation extent, they describe that continuation, i.e. the block of the empty allocation extent, one block long.
The kernel creates such lists itself: when udf_delete_aext() removes the only descriptor of the last allocation extent in a list, it leaves that allocation extent empty and the continuation to it in place.
If the last extent is a preallocation, udf_discard_prealloc() deletes it with udf_delete_aext(), which finds the following allocation extent empty, so it also removes the continuation and frees that allocation extent's block. udf_discard_prealloc() then frees eloc and elen: that block a second time, instead of the preallocated blocks. On a space bitmap the preallocated blocks leak and the free block count drifts. On an unallocated space table the second free adds a second free extent for the same block, which is later handed out twice: fsx as run by generic/091 and generic/263 ends up with two parts of its test file in one block and reads back bad data.
Peek into separate variables, so that eloc and elen keep the last extent that udf_next_aext() returned with 1.
--- fs/udf/truncate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/udf/truncate.c +4 -3
@@ -122,8 +122,8 @@ void udf_discard_prealloc(struct inode *inode) {struct extent_position epos = {};struct extent_position prev_epos = {}; -struct kernel_lb_addr eloc; -uint32_t elen; +struct kernel_lb_addr eloc, tmpeloc; +uint32_t elen, tmpelen;uint64_t lbcount =0 ;int8_t etype =-1 , netype;struct udf_inode_info *iinfo =UDF_I (inode);
@@ -136,7 +136,8 @@ void udf_discard_prealloc(struct inode *inode) epos.block = iinfo->i_location;/* Find the last extent in the file */ -while ((netype =udf_next_aext (inode, &epos, &eloc, &elen,0 )) !=-1 ) { +while ((netype =udf_next_aext (inode, &epos, &tmpeloc, &tmpelen, +0 )) !=-1 ) {brelse (prev_epos.bh); prev_epos = epos;if (prev_epos.bh)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1267/2214 fbdev: kyro: Use devm_ioremap() for mmio registers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Di Santi <[email protected]>
[ Upstream commit e0bf12a43243e6afc5a03fc55c58ec48aba48088 ]
Replace the manual ioremap() call for the MMIO registers with the device-managed devm_ioremap() variant.
This simplifies the driver's resource management by ensuring the memory is automatically unmapped when the driver detaches from the device.
Stable-dep-of: d3bc005a6294 ("fbdev: kyro: Release WC setup on registration failure")
--- drivers/video/fbdev/kyro/fbdev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/video/fbdev/kyro/fbdev.c +3 -5
@@ -713,13 +713,14 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) kyro_fix.mmio_len =pci_resource_len (pdev,1 ); currentpar->regbase = deviceInfo.pSTGReg = -ioremap (kyro_fix.mmio_start, kyro_fix.mmio_len); +devm_ioremap (&pdev->dev, kyro_fix.mmio_start, + kyro_fix.mmio_len);if (!currentpar->regbase) goto out_free_fb; info->screen_base =pci_ioremap_wc_bar (pdev,0 );if (!info->screen_base) - goto out_unmap_regs; + goto out_free_fb;if (!nomtrr) currentpar->wc_cookie = arch_phys_wc_add(kyro_fix.smem_start,
@@ -768,8 +769,6 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) out_unmap:iounmap (info->screen_base); -out_unmap_regs: -iounmap (currentpar->regbase); out_free_fb:framebuffer_release (info);
@@ -792,7 +791,6 @@ static void kyrofb_remove(struct pci_dev *pdev) deviceInfo.ulOverlayOffset =0 ;iounmap (info->screen_base); -iounmap (par->regbase);arch_phys_wc_del (par->wc_cookie);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1268/2214 fbdev: kyro: Use devm_ioremap_wc() for screen mem
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Di Santi <[email protected]>
[ Upstream commit 32dfb6112ea3ca143636832cd34234f2be4830bb ]
Replace the manual pci_ioremap_wc() call for mapping screen memory with the device-managed devm_ioremap_wc() variant.
This simplifies the driver's resource management by ensuring the memory is automatically unmapped when the driver detaches from the device.
Stable-dep-of: d3bc005a6294 ("fbdev: kyro: Release WC setup on registration failure")
--- drivers/video/fbdev/kyro/fbdev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/video/fbdev/kyro/fbdev.c +3 -6
@@ -718,7 +718,8 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (!currentpar->regbase) goto out_free_fb; - info->screen_base =pci_ioremap_wc_bar (pdev,0 ); + info->screen_base =devm_ioremap_wc (&pdev->dev, kyro_fix.smem_start, + kyro_fix.smem_len);if (!info->screen_base) goto out_free_fb;
@@ -756,7 +757,7 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)fb_memset (info->screen_base,0 , size);if (register_framebuffer (info) <0 ) - goto out_unmap; + goto out_free_fb; fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n", info->fix.id,
@@ -767,8 +768,6 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; -out_unmap: -iounmap (info->screen_base); out_free_fb:framebuffer_release (info);
@@ -790,8 +789,6 @@ static void kyrofb_remove(struct pci_dev *pdev) deviceInfo.ulNextFreeVidMem =0 ; deviceInfo.ulOverlayOffset =0 ; -iounmap (info->screen_base); -arch_phys_wc_del (par->wc_cookie);unregister_framebuffer (info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1269/2214 fbdev: kyro: Release WC setup on registration failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit d3bc005a62945aec57059201092b12b7c955e5a7 ]
If register_framebuffer() fails, kyrofb_probe() frees the framebuffer without releasing its write-combining range. Release the range before freeing the framebuffer. Earlier failures still skip this cleanup.
The missing cleanup already exists in the initial Git import, before the conversion from mtrr_add() to arch_phys_wc_add().
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/video/fbdev/kyro/fbdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/kyro/fbdev.c +3 -1
@@ -757,7 +757,7 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)fb_memset (info->screen_base,0 , size);if (register_framebuffer (info) <0 ) - goto out_free_fb; + goto out_free_wc; fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n", info->fix.id,
@@ -768,6 +768,8 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; +out_free_wc: +arch_phys_wc_del (currentpar->wc_cookie); out_free_fb:framebuffer_release (info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1270/2214 hwmon: (coretemp) Fix 32-bit jiffies wraparound in show_temp()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 9a6aa085c94c7f2817c4d50a7264e6fb51286f40 ]
show_temp() rate-limits MSR reads by storing tdata->last_updated as an unsigned long and comparing it against jiffies using time_after(jiffies, tdata->last_updated + HZ).
time_after() relies on signed long subtraction, which only produces the expected result while the two timestamps are within LONG_MAX jiffies of each other. On 32-bit kernels, if tempX_input is not read for more than LONG_MAX jiffies (~24.85 days at HZ=1000), the signed difference flips sign and time_after() evaluates to false. Because tdata->last_updated is only refreshed when time_after() succeeds, subsequent reads remain blocked from refreshing for another ~24.85 days until jiffies wraps past tdata->last_updated + HZ again, returning either a stale cached temperature or -ENODATA if the sensor had never been read since initialization.
Store tdata->last_updated as a u64 and use get_jiffies_64() with time_after64(), which does not wrap in any practical uptime.
--- drivers/hwmon/coretemp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/hwmon/coretemp.c +4 -3
@@ -70,7 +70,7 @@ struct temp_data {int temp;int ttarget;int tjmax; -unsigned long last_updated; +u64 last_updated;unsigned int cpu;u32 cpu_core_id;u32 status_reg;
@@ -157,7 +157,8 @@ static ssize_t show_temp(struct device *dev,mutex_lock (&tdata->update_lock);/* Check whether the time interval has elapsed */ -if (!tdata->valid ||time_after (jiffies, tdata->last_updated +HZ )) { +if (!tdata->valid || +time_after64 (get_jiffies_64 (), tdata->last_updated +HZ )) {rdmsr_on_cpu (tdata->cpu, tdata->status_reg, &eax, &edx);/* * Ignore the valid bit. In all observed cases the register
@@ -167,7 +168,7 @@ static ssize_t show_temp(struct device *dev,*/ tdata->temp = tdata->tjmax - ((eax >>16 ) &0x7f ) *1000 ; tdata->valid =1 ; - tdata->last_updated = jiffies; + tdata->last_updated =get_jiffies_64 (); }mutex_unlock (&tdata->update_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1271/2214 hwmon: (tmp108) Fix initial conversion delay and wait until ready
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 7cd60538073e465310c94b2a2f0ea8d2f03768ef ]
In tmp108_common_probe(), the driver only adds the 30 ms conversion delay (TMP108_CONVERSION_TIME_MS) to ready_time if the sensor was previously in TMP108_MODE_SHUTDOWN. However, the TMP108 hardware defaults to continuous conversion mode (TMP108_MODE_CONTINUOUS) upon power-on reset, including immediately after enabling the vcc supply regulator during probe, while the temperature register retains its power-on reset value of 0x0000 (0°C) until the first conversion completes. Because the initial mode is not shutdown, the delay is bypassed and early reads via thermal zone registration or sysfs before the first conversion finishes return an uninitialized 0°C reading.
In addition, returning -EAGAIN from tmp108_read() while waiting for a conversion to complete after probe or resume can trigger an unnecessary tight retry loop in callers or fail initial reads.
Unconditionally set ready_time to TMP108_CONVERSION_TIME_MS ahead in tmp108_common_probe(), track ready_time as ktime_t, and wait for the remaining conversion time in tmp108_read() using usleep_range() instead of returning -EAGAIN.
--- drivers/hwmon/tmp108.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/hwmon/tmp108.c +11 -15
@@ -14,7 +14,7 @@#include <linux/of.h> #include <linux/i2c.h> #include <linux/init.h> -#include <linux/jiffies.h> +#include <linux/ktime.h> #include <linux/regmap.h> #include <linux/slab.h>
@@ -73,7 +73,7 @@struct tmp108 {struct regmap *regmap;u16 orig_config; -u64 ready_time; +ktime_t ready_time; };/* convert 12-bit TMP108 register value to milliCelsius */
@@ -94,6 +94,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,struct tmp108 *tmp108 =dev_get_drvdata (dev);unsigned int regval;int err, hyst; +s64 delay;if (type == hwmon_chip) {if (attr == hwmon_chip_update_interval) {
@@ -123,12 +124,10 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input: -/* Is it too early to return a conversion ? */ -if (time_before64 (get_jiffies_64 (), tmp108->ready_time)) { -dev_dbg (dev,"%s: Conversion not ready yet..\n" , - __func__); -return -EAGAIN ; - } +/* Wait if it is too early to return a conversion */ + delay =ktime_us_delta (tmp108->ready_time,ktime_get ()); +if (delay >0 ) +usleep_range (delay, delay +1000 ); err =regmap_read (tmp108->regmap,TMP108_REG_TEMP , ®val);if (err <0 )return err;
@@ -371,11 +370,8 @@ static int tmp108_probe(struct i2c_client *client)return err; } - tmp108->ready_time =get_jiffies_64 (); -if ((tmp108->orig_config &TMP108_CONF_MODE_MASK ) == -TMP108_MODE_SHUTDOWN ) - tmp108->ready_time += -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS ); err =devm_add_action_or_reset (dev, tmp108_restore_config, tmp108);if (err) {
@@ -405,8 +401,8 @@ static int __maybe_unused tmp108_resume(struct device *dev) err =regmap_update_bits (tmp108->regmap,TMP108_REG_CONF ,TMP108_CONF_MODE_MASK ,TMP108_MODE_CONTINUOUS ); - tmp108->ready_time =get_jiffies_64 () + -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1272/2214 drm/amdgpu: dont walk the CS chunks when allocating them failed
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit ade92d50aad6799a5a9d7e73cd1604fd0576e656 ]
amdgpu_cs_pass1() sets p->nchunks before allocating p->chunks, and the allocation failure path skips resetting it. amdgpu_cs_parser_fini() then frees the kdata of nchunks chunks from a NULL array. On navi48 with the chunk array allocation failed through failslab:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:amdgpu_cs_parser_fini+0x35d/0x710 [amdgpu] amdgpu_cs_ioctl+0xcae/0x7a20 [amdgpu] drm_ioctl_kernel+0x180/0x320 [drm]
Set nchunks once the array exists.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -2
@@ -139,13 +139,14 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs goto free_chunk; } - p->nchunks = cs->in.num_chunks; - p->chunks =kvmalloc_array (p->nchunks,sizeof (struct amdgpu_cs_chunk ), +/* parser_fini() walks nchunks chunks, set it once they exist */ + p->chunks =kvmalloc_array (cs->in.num_chunks,sizeof (struct amdgpu_cs_chunk ),GFP_KERNEL );if (!p->chunks) { ret = -ENOMEM ; goto free_chunk; } + p->nchunks = cs->in.num_chunks;for (i =0 ; i < p->nchunks; i++) {struct drm_amdgpu_cs_chunk __user *chunk_ptr =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1273/2214 nvme: unregister when pr_register() is given a zero new key
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit a9d431124fb2e58215daf0299d6fcf47bbc2d6b1 ]
The block layer PR API defines a zero new_key in pr_register() as unregistering old_key. nvme_pr_register() sends Replace Reservation Key with a zero NRKEY instead. The host stays registered with key 0, and its next registration with another key fails with Reservation Conflict.
The pNFS SCSI layout client unregisters this way at umount. A later mount cannot register and sends all I/O through the metadata server.
Send Unregister Reservation Key when new_key is zero.
--- drivers/nvme/host/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +6 -1
@@ -2089,7 +2089,12 @@ static int nvme_pr_register(struct block_device *bdev, u64 old,if (flags & ~PR_FL_IGNORE_KEY )return -EOPNOTSUPP ; - cdw10 = old ?2 :0 ; +if (!new) + cdw10 =1 ; +else if (old) + cdw10 =2 ; +else + cdw10 =0 ; cdw10 |= (flags &PR_FL_IGNORE_KEY ) ?1 <<3 :0 ; cdw10 |= (1 <<30 ) | (1 <<31 );/* PTPL=1 */ return nvme_pr_command (bdev, cdw10, old, new, nvme_cmd_resv_register);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1274/2214 mm/vma: dont leak the charge for stack growth
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit b1ee87802111156e27557e82acc31fa7dfc76e2a ]
acct_stack_growth() charges stack expansion even without VM_ACCOUNT. This can happen for read-only or MAP_NORESERVE mappings created with MAP_GROWSDOWN. Unmapping these VMAs does not release the charge, leaking Committed_AS.
Only check and charge growth for VM_ACCOUNT VMAs, matching mremap(). Unaccounted growth skips the overcommit check while remaining subject to the other stack-growth limits.
--- mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/mmap.c +2 -1
@@ -2373,7 +2373,8 @@ static int acct_stack_growth(struct vm_area_struct *vma,* Overcommit.. This must be the final test, as it will * update security statistics. */ -if (security_vm_enough_memory_mm (mm, grow)) +if ((vma->vm_flags &VM_ACCOUNT ) && +security_vm_enough_memory_mm (mm, grow))return -ENOMEM ;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1275/2214 ocfs2/heartbeat: serialize concurrent writes to a regions dev attribute
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eklavya Singh <[email protected]>
[ Upstream commit 0a8f258c0f012314c36b9e4818cdc0178c68f891 ]
o2hb_region_dev_store() checks reg->hr_bdev_file to see if the region is already started, but nothing stops two writers from doing that at the same time. configfs only serializes writes through the same open file, so two processes that each open the dev attribute can both get past the check:
A: hr_bdev_file is NULL, opens file A, sets hr_bdev_file = A
B: hr_bdev_file is NULL, opens file B, sets hr_bdev_file = B
A: start fails, fput(hr_bdev_file) drops B, sets it to NULL
B: start fails, fput(NULL)
Both calls also use the same hr_slots, hr_slot_data and hr_tmp_block, so the error paths can free the slot data twice.
syzbot hit the fput(NULL) with an unbound loop device, where every start fails with -EIO. With four threads doing the same thing on a KASAN kernel I get both crashes within a second:
BUG: KASAN: double-free in o2hb_unmap_slot_data+0x14d/0x2f0 BUG: kernel NULL pointer dereference, address: 0000000000000158
Add a mutex to the region and hold it in dev_store(), in the block_bytes, start_block and blocks stores, and in dev_show(), since they all look at hr_bdev_file. dev_store() cleans up with goto, so it takes the mutex in a small wrapper rather than with guard(). The mutex is dropped while dev_store() waits for the heartbeat to become steady, which takes seconds, so a read of dev doesn't stall behind a start. hr_bdev_file is already set at that point, so other writers still get -EINVAL, and the cleanup after the wait retakes the mutex.
With the patch the same test ran for 10 minutes with lockdep on and nothing was reported. So did a second one, with a working loop device, that interrupts starts during the wait while other threads read and write the attributes.
--- fs/ocfs2/cluster/heartbeat.c | 65 +++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 20 deletions(-)
fs/ocfs2/cluster/heartbeat.c +45 -20
@@ -266,6 +266,8 @@ struct o2hb_region {/* Message key for negotiate timeout message. */ unsigned int hr_key;struct list_head hr_handler_list; +/* Serializes the dev, block_bytes, start_block and blocks attributes. */ +struct mutex hr_dev_mutex;/* last hb status, 0 for success, other value for error. */ int hr_last_hb_status;
@@ -1599,22 +1601,25 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item, size_t count) {struct o2hb_region *reg =to_o2hb_region (item); -int status; +ssize_t status = -EINVAL ;unsigned long block_bytes;unsigned int block_bits; +mutex_lock (®->hr_dev_mutex);if (reg->hr_bdev) -return -EINVAL ; + goto out; status =o2hb_read_block_input (reg, page, &block_bytes, &block_bits);if (status) -return status; + goto out; reg->hr_block_bytes = (unsigned int )block_bytes; reg->hr_block_bits = block_bits; - -return count; + status = count; +out: +mutex_unlock (®->hr_dev_mutex); +return status; } static ssize_t o2hb_region_start_block_show(struct config_item *item,
@@ -1630,18 +1635,20 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item,struct o2hb_region *reg =to_o2hb_region (item);unsigned long long tmp;char *p = (char *)page; -ssize_t ret; +ssize_t ret = -EINVAL ; +mutex_lock (®->hr_dev_mutex);if (reg->hr_bdev) -return -EINVAL ; + goto out; - ret =kstrtoull (p,0 , &tmp); -if (ret) -return -EINVAL ; +if (kstrtoull (p,0 , &tmp)) + goto out; reg->hr_start_block = tmp; - -return count; + ret = count; +out: +mutex_unlock (®->hr_dev_mutex); +return ret; }static ssize_t o2hb_region_blocks_show (struct config_item *item,char *page)
@@ -1656,28 +1663,37 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,struct o2hb_region *reg =to_o2hb_region (item);unsigned long tmp;char *p = (char *)page; +ssize_t ret = -EINVAL ; +mutex_lock (®->hr_dev_mutex);if (reg->hr_bdev) -return -EINVAL ; + goto out; tmp =simple_strtoul (p, &p,0 );if (!p || (*p && (*p !='\n' ))) -return -EINVAL ; + goto out; -if (tmp >O2NM_MAX_NODES || tmp ==0 ) -return -ERANGE ; +if (tmp >O2NM_MAX_NODES || tmp ==0 ) { + ret = -ERANGE ; + goto out; + } reg->hr_blocks = (unsigned int )tmp; - -return count; + ret = count; +out: +mutex_unlock (®->hr_dev_mutex); +return ret; }static ssize_t o2hb_region_dev_show (struct config_item *item,char *page) { +struct o2hb_region *reg =to_o2hb_region (item);unsigned int ret =0 ; -if (to_o2hb_region (item)->hr_bdev) - ret =sprintf (page,"%s\n" ,to_o2hb_region (item)->hr_dev_name); +mutex_lock (®->hr_dev_mutex); +if (reg->hr_bdev) + ret =sprintf (page,"%s\n" , reg->hr_dev_name); +mutex_unlock (®->hr_dev_mutex);return ret; }
@@ -1800,6 +1816,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,ssize_t ret = -EINVAL ;int live_threshold; +mutex_lock (®->hr_dev_mutex);if (reg->hr_bdev) goto out;
@@ -1900,9 +1917,15 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, reg->hr_task = hb_task;spin_unlock (&o2hb_live_lock); +/* +* Don't hold hr_dev_mutex across the wait, which can take seconds. +* hr_bdev is already set, so other writers still get -EINVAL. +*/ +mutex_unlock (®->hr_dev_mutex); ret =wait_event_interruptible (o2hb_steady_queue,atomic_read (®->hr_steady_iterations) ==0 || reg->hr_node_deleted); +mutex_lock (®->hr_dev_mutex);if (ret) {atomic_set (®->hr_steady_iterations,0 ); reg->hr_aborted_start =1 ;
@@ -1942,6 +1965,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, out2:fdput (f); out: +mutex_unlock (®->hr_dev_mutex);return ret; }
@@ -2045,6 +2069,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g }INIT_LIST_HEAD (®->hr_all_item); +mutex_init (®->hr_dev_mutex);INIT_LIST_HEAD (®->hr_handler_list);config_item_init_type_name (®->hr_item, name, &o2hb_region_type);if (!config_item_name (®->hr_item)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1276/2214 mm/mempolicy: apply bind policies against the scoped allocation zone
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price (Meta) <[email protected]>
[ Upstream commit d4ea410ce4b8aa46a316476ea2624a357bf31fa9 ]
QEMU fails to start a guest with a VFIO device when guest RAM comes from a memory backend bound to a movable-only node:
vfio_container_dma_map(0x55b1b1317800, 0x0, 0x10000000,
0x7f39a2200000)
= -12 (Cannot allocate memory)
VFIO pins guest RAM when the device is realized, and the pin faults the pages in. io_uring fixed buffers fail the same way. Faulting the range in before pinning lets the same pin succeed, since resident pages are migrated off the node instead.
A long-term pin faults under memalloc_pin_save(). PF_MEMALLOC_PIN makes current_gfp_context() clear __GFP_MOVABLE, but policy_nodemask() tests apply_policy_zone() against the caller's gfp.
The bind keeps its movable-only nodemask, and the allocation finds no usable zone:
page allocation failure:
order:0,
mode:0x140dc2(GFP_HIGHUSER|__GFP_ZERO|__GFP_COMP),
nodemask=1,cpuset=/,mems_allowed=0-1Call Trace: warn_alloc+0x136/0x150 __alloc_frozen_pages_noprof+0xed8/0x1720 alloc_pages_mpol+0xaa/0x170 vma_alloc_folio_noprof+0x65/0xd0 __handle_mm_fault+0x137b/0x1ac0 handle_mm_fault+0xa0/0x270 __get_user_pages+0x250/0xfd0 __gup_longterm_locked+0x116/0x870 gup_fast_fallback+0xcfc/0xdf0 pin_user_pages_fast+0x47/0x60 io_pin_pages+0x9a/0x110
Base page faults fail with -ENOMEM.
hugetlb faults fail with -EFAULT.
Check the policy zone against current_gfp_context(gfp), so a pin-scoped fault falls back off the movable-only nodemask, like any other non-movable allocation under the same bind.
Tested in qemu with a dax/kmem movable-only node 1. io_uring and VFIO pins of unfaulted base pages and 2MB hugetlb pages now succeed and land on node 0 (correct). QEMU now starts with the same backend binding.
--- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mempolicy.c +1 -1
@@ -1766,7 +1766,7 @@ nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy)/* Lower zones don't get a nodemask applied for MPOL_BIND */ if (unlikely (mode ==MPOL_BIND ) && -apply_policy_zone (policy,gfp_zone (gfp)) && +apply_policy_zone (policy,gfp_zone (current_gfp_context (gfp))) &&cpuset_nodemask_valid_mems_allowed (&policy->nodes))return &policy->nodes;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1277/2214 mm: make swapoff interruptible when unusing mms/shmem
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Down <[email protected]>
[ Upstream commit 740128dd1a3f2bd81a80314d079b6b03c39ba3af ]
try_to_unuse() only checks for a pending signal between mms, and shmem_unuse() doesn't check at all. That means that once swapoff gets to a process or a shmem file with a lot swapped out, nothing can interrupt it until every last page of it has been read back in.
Just as one example of where this can concretely show up, freezing tasks for suspend or hibernation has to wait for swapoff to notice the freezer's fake signal, and gives up after freeze_timeout_msecs (20 seconds by default).
Here's a facetious example where one swaps out 2GiB of one process to a swap file on ext4, starts swapoff, and half a second later tries to freeze with pm_test=freezer. Writing to /sys/power/state then fails with EBUSY and this in dmesg:
Freezing user space processes failed after 20.003 seconds (1 tasks refusing to freeze, wq_busy=0):
task:swapoff state:D stack:0 pid:3175 tgid:3175 ppid:2955 task_flags:0x400100 flags:0x00000419
Call trace:
[...]
io_schedule+0x44/0x70
folio_wait_bit_common+0x1ec/0x3d0
__folio_lock+0x24/0x40
unuse_pte_range+0x2d0/0x348
unuse_vma+0x158/0x248
unuse_mm+0xfc/0x150
try_to_unuse+0x104/0x3f8
__do_sys_swapoff+0x220/0x5d8
[...]The same goes for anything else that wants swapoff to stop, like an admin hitting ^C in a panic, of course.
Prior to commit b56a2d8af914 ("mm: rid swapoff of quadratic complexity") try_to_unuse() was driven by find_next_to_unuse() which checks for a signal before every entry, so let's restore that behaviour.
Just as an example of the improvements, here's how long freezing takes in the same test while swapoff is happening on my computer:
before after
400MiB anon 8.925s 0.028s
400MiB shmem 1.639s 0.003s
2GiB anon failed after 20.003s 0.011s--- mm/shmem.c | 4 ++++ mm/swapfile.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
mm/shmem.c +4 -0
@@ -1285,6 +1285,10 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type, } } +if (signal_pending (current)) { + ret = -ERESTARTSYS ; +break ; + } start = indices[pvec.nr -1 ]; }while (true);
mm/swapfile.c +3 -1
@@ -2039,6 +2039,8 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, pmd =pmd_offset (pud, addr); do { cond_resched(); + if (signal_pending(current)) + return -ERESTARTSYS; next = pmd_addr_end(addr, end); if (pmd_none_or_trans_huge_or_clear_bad(pmd)) continue;
@@ -2275,7 +2277,7 @@ int try_to_unuse(unsigned int type, bool frontswap,if (READ_ONCE (si->inuse_pages)) {if (!signal_pending (current)) goto retry; - retval = -EINTR ; + retval = -ERESTARTSYS ; } out:return (retval ==FRONTSWAP_PAGES_UNUSED ) ?0 : retval;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1278/2214 mm/memory: reject remote COW faults on PFN mappings
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 8db6921cc07b74197a3866d62ed262b68aeadcf3 ]
When handling a COW fault without a normal source page (PFN mappings), __wp_page_copy_user() copies from the faulting user address. For remote faults, this accesses the wrong address space, resulting in wrong data getting copied.
For example, user_events updates an enable bit in the registering process's memory. If that memory needs to be faulted in, user_event_enabler_fault_fixup() calls fixup_user_fault() from a work item. Placing the enable bit in a private PFN mapping can trigger this remote COW path.
Reject these faults with VM_FAULT_SIGBUS when the target mm differs from current->mm: remote faults. Ordinary (non-PFN) mappings are not affected.
The user-address copy dates back to commit 6aab341e0a28 ("mm: re-architect the VM_UNPAGED logic"); likely, actual ways to get remote faults in there on COW PFN mappings appeared afterwards. But the fix is simple and straight forward.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/memory.c +9 -0
@@ -2808,6 +2808,13 @@ static inline int cow_user_page(struct page *dst, struct page *src,return 0 ; } +/* +* __copy_from_user_inatomic() only works as expected for local faults. +* Reject remote faults. +*/ +if (unlikely (mm != current->mm)) +return -EFAULT ; +/* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by
@@ -3071,6 +3078,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)if (old_page)put_page (old_page); +if (ret == -EFAULT ) +return VM_FAULT_SIGBUS ;return ret == -EHWPOISON ?VM_FAULT_HWPOISON :0 ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1279/2214 mm/mremap: use pudp_huge_get_and_clear() when moving huge PUDs
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit b4417d08034a7b4a3083e0e2d95429d4542524f2 ]
move_huge_pud() reads the old PUD and clears it in separate operations. Hardware accessed or dirty updates between those operations can be lost when the saved entry is installed at the new address.
The raw pud_clear() also bypasses page_table_check_pud_clear(), while set_pud_at() accounts for the destination mapping. This leaves the checker counts unbalanced for mappings tracked by page table checking.
To fix it, simply use pudp_huge_get_and_clear().
--- mm/mremap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/mremap.c +1 -2
@@ -368,8 +368,7 @@ static bool move_huge_pud(struct vm_area_struct *vma, unsigned long old_addr,spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );/* Clear the pud */ - pud = *old_pud; -pud_clear (old_pud); + pud =pudp_huge_get_and_clear (mm, old_addr, old_pud);VM_BUG_ON (!pud_none (*new_pud));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1280/2214 mm/userfaultfd: compare exact registration modes before skipping
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit 05f64f211a25f7d9771d4fde109aad97174a1cf3 ]
Changing registration from MISSING|WP to WP returns success but leaves MISSING enabled. The no-op check sees that WP is already set and skips the update, so later accesses to missing pages still wait for userspace.
Skip the update only when the current and requested UFFD modes match exactly.
--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/userfaultfd.c +1 -1
@@ -1435,7 +1435,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,* userfaultfd and with the right tracking mode too. */ if (vma->vm_userfaultfd_ctx.ctx == ctx && - (vma->vm_flags & vm_flags) == vm_flags) + (vma->vm_flags & __VM_UFFD_FLAGS) == vm_flags) goto skip;if (vma->vm_start > start)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1281/2214 apparmor: fix query_data() output overlapping the lookup key
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit d30844001360a403a511cf24fc75ecaa6a7a7544 ]
In query_data(), buf and query point into the same multi_transaction
buffer: buf at the start, query a few bytes in, and the lookup key right after the label string that query points to. Reusing the buffer is by design and is safe as long as the query is fully parsed before buf is written to, but the key is not: it is dereferenced on every iteration of label_for_each_confined(), after output has already been written. So when the label has more than one profile with a data table, the data of the first matching profile is written to buf while the key is still needed, and overwrites it if the data is large enough. The later lookups then run on a corrupted key. Besides, if the data has no NUL byte from the key's position to the end of the allocation, strhash() -> strlen() -> jhash() reads past the 4096-byte slab object, triggering an out-of-bound read:
BUG: KASAN: slab-out-of-bounds in jhash+0x595/0x5e0 Read of size 1 at addr ff1100001159d000 by task exploit/155 CPU: 0 UID: 1000 PID: 155 Comm: exploit Not tainted 7.3.0-rc7 #1 Call Trace: jhash+0x595/0x5e0 aa_write_access+0x880/0x1400 vfs_write+0x26f/0xd20 ksys_write+0x115/0x210
Writing to the .access file is unprivileged (0666), but triggering this requires loaded profiles that carry a data table, which needs CAP_MAC_ADMIN and is not the case on default distribution policies.
Fix by copying the key with kstrdup() before writing any output to buf, so the key stays valid across all loop iterations regardless of what gets written to the overlapping buffer.
--- security/apparmor/apparmorfs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
security/apparmor/apparmorfs.c +12 -3
@@ -739,7 +739,7 @@ static void profile_query_cb(struct aa_profile *profile, struct aa_perms *perms,static ssize_t query_data (char *buf,size_t buf_len,char *query,size_t query_len) { -char *out; +char *out, *keydup;const char *key;struct label_it i;struct aa_label *label, *curr;
@@ -760,11 +760,18 @@ static ssize_t query_data(char *buf, size_t buf_len,if (buf_len <sizeof (bytes) +sizeof (blocks))return -EINVAL ;/* not enough space */ +/* buf overlaps query, keep a copy of the key for the later lookups */ + keydup =kstrdup (key,GFP_KERNEL ); +if (!keydup) +return -ENOMEM ; + curr =begin_current_label_crit_section (); label =aa_label_parse (curr, query,GFP_KERNEL , false, false);end_current_label_crit_section (curr); -if (IS_ERR (label)) +if (IS_ERR (label)) { +kfree (keydup);return PTR_ERR (label); + }/* We are going to leave space for two numbers. The first is the total * number of bytes we are writing after the first number. This is so
@@ -782,13 +789,14 @@ static ssize_t query_data(char *buf, size_t buf_len,if (!profile->data)continue ; - data =rhashtable_lookup_fast (profile->data, &key, + data =rhashtable_lookup_fast (profile->data, &keydup, profile->data->p);if (data) {if (out +sizeof (outle32) + data->size > buf + buf_len) {aa_put_label (label); +kfree (keydup);return -EINVAL ;/* not enough space */ } outle32 =__cpu_to_le32 (data->size);
@@ -800,6 +808,7 @@ static ssize_t query_data(char *buf, size_t buf_len, } }aa_put_label (label); +kfree (keydup); outle32 =__cpu_to_le32 (out - buf -sizeof (bytes));memcpy (buf, &outle32,sizeof (outle32));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1282/2214 hwmon: (aquacomputer_d5next) reject short status reports
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit cf8f81babd2e96087dedbb74985bc1781c98f73d ]
The HID raw_event callback runs before HID core validates the received report length. aqc_raw_event() reads device-specific status fields at fixed offsets, including multi-byte values, without first ensuring that the received buffer contains every field. A truncated report can therefore cause out-of-bounds reads and update hwmon state with unrelated data.
The required length differs between supported devices and cannot be derived from the HID report descriptor. Define the minimum length needed by each asynchronous status format, select it while configuring the device, and reject reports that do not contain the last field accessed by that format. Keep the published length zero until probe configuration is complete, which also excludes legacy devices whose status is retrieved through feature reports.
--- drivers/hwmon/aquacomputer_d5next.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hwmon/aquacomputer_d5next.c +6 -0
@@ -43,6 +43,7 @@#define D5NEXT_PUMP_CURRENT 112#define D5NEXT_FAN_CURRENT 99 +#define D5NEXT_MIN_STATUS_REPORT_SIZE (D5NEXT_PUMP_SPEED + sizeof(u16))/* Labels for provided values */
@@ -86,6 +87,7 @@ struct d5next_data {struct hid_device *hdev;struct device *hwmon_dev;struct dentry *debugfs; +u16 min_report_size;s32 temp_input;u16 speed_input[2 ];u32 power_input[2 ];
@@ -189,6 +191,8 @@ static int d5next_raw_event(struct hid_device *hdev, struct hid_report *report,return 0 ; priv =hid_get_drvdata (hdev); +if (!priv->min_report_size || size < priv->min_report_size) +return 0 ;/* Info provided with every report */
@@ -298,6 +302,8 @@ static int d5next_probe(struct hid_device *hdev, const struct hid_device_id *id)if (ret) goto fail_and_stop; + priv->min_report_size =D5NEXT_MIN_STATUS_REPORT_SIZE ; + priv->hwmon_dev =hwmon_device_register_with_info (&hdev->dev,"d5next" , priv, &d5next_chip_info,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1283/2214 virtio_blk: use synchronous quiesce in virtblk_freeze_priv()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Zhang <[email protected]>
[ Upstream commit 6c6dec7883f8eb10b326bc9d109a4990c885d949 ]
blk_mq_run_work_fn() can call blk_mq_sched_dispatch_requests() through blk_mq_run_dispatch_ops(). The dispatcher checks QUEUE_FLAG_QUIESCED while the flag is clear. It can then be preempted before it gets a request. At that time, it has no queue usage reference, so blk_mq_freeze_queue() does not wait for it.
virtblk_freeze_priv() then calls blk_mq_quiesce_queue_nowait() and blk_mq_unfreeze_queue(). A new request can enter the queue. The old dispatcher can run again, use its old flag check, get the new request, and call virtio_queue_rq(). At the same time, virtblk_freeze_priv() can reset the device, delete the virtqueues, and free vblk->vqs. The old dispatcher can then use a deleted virtqueue or a NULL vblk->vqs, and the kernel can crash.
Fix this by using blk_mq_quiesce_queue(), which waits for dispatch code that was already running. Keep the existing freeze and unfreeze order. The queue remains quiesced until virtblk_restore_priv() calls blk_mq_unquiesce_queue().
--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/virtio_blk.c +1 -1
@@ -992,7 +992,7 @@ static int virtblk_freeze(struct virtio_device *vdev)/* Ensure no requests in virtqueues before deleting vqs. */ blk_mq_freeze_queue (q); -blk_mq_quiesce_queue_nowait (q); +blk_mq_quiesce_queue (q);blk_mq_unfreeze_queue (q);/* Ensure we don't receive any more interrupts */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1284/2214 mm/filemap: read mapping->a_ops->free_folio under i_lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit dc24e273244e9d712257d5a6c20a32c7f5ca84e6 ]
memory_failure() -> ... -> filemap_remove_folio() can read mapping->a_ops after the inode has been freed. Once the folio is deleted from the pagecache it no longer pins the mapping, so after i_lock is dropped e.g., a concurrent final iput() can evict and free the inode before filemap_free_folio() looks up mapping->a_ops->free_folio.
Most callers hold a reference on the inode, but not all.
Documentation/filesystems/vfs.rst explicitly states that ->free_folio() must not assume the original address_space mapping still exists.
Fix it by loading ->free_folio while i_lock is still held, similar to what folio_unmap_invalidate() does.
Inline filemap_free_folio() into its remaining caller such that delete_from_page_cache_batch() also just loads the callback before dropping the i_lock.
The bug was found by code inspection and has not been reproduced.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/filemap.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-)
mm/filemap.c +24 -20
@@ -232,23 +232,6 @@ void __delete_from_page_cache(struct page *page, void *shadow)page_cache_delete (mapping, page, shadow); } -static void page_cache_free_page (struct address_space *mapping, -struct page *page) -{ -void (*freepage)(struct page *); - - freepage = mapping->a_ops->freepage; -if (freepage) -freepage (page); - -if (PageTransHuge (page) && !PageHuge (page)) { -page_ref_sub (page,thp_nr_pages (page)); -VM_BUG_ON_PAGE (page_count (page) <=0 , page); - }else { -put_page (page); - } -} -/** * delete_from_page_cache - delete page from page cache * @page: the page which the kernel is trying to remove from page cache
@@ -260,13 +243,22 @@ static void page_cache_free_page(struct address_space *mapping,void delete_from_page_cache (struct page *page) {struct address_space *mapping =page_mapping (page); +void (*freepage)(struct page *page);BUG_ON (!PageLocked (page));xa_lock_irq (&mapping->i_pages);__delete_from_page_cache (page,NULL ); + freepage = mapping->a_ops->freepage;xa_unlock_irq (&mapping->i_pages); -page_cache_free_page (mapping, page); +if (freepage) +freepage (page); +if (PageTransHuge (page) && !PageHuge (page)) { +page_ref_sub (page,thp_nr_pages (page)); +VM_BUG_ON_PAGE (page_count (page) <=0 , page); + }else { +put_page (page); + } }EXPORT_SYMBOL (delete_from_page_cache);
@@ -335,6 +327,7 @@ static void page_cache_delete_batch(struct address_space *mapping,void delete_from_page_cache_batch (struct address_space *mapping,struct pagevec *pvec) { +void (*freepage)(struct page *page);int i;if (!pagevec_count (pvec))
@@ -347,10 +340,21 @@ void delete_from_page_cache_batch(struct address_space *mapping,unaccount_page_cache_page (mapping, pvec->pages[i]); }page_cache_delete_batch (mapping, pvec); + freepage = mapping->a_ops->freepage;xa_unlock_irq (&mapping->i_pages); -for (i =0 ; i <pagevec_count (pvec); i++) -page_cache_free_page (mapping, pvec->pages[i]); +for (i =0 ; i <pagevec_count (pvec); i++) { +struct page *page = pvec->pages[i]; + +if (freepage) +freepage (page); +if (PageTransHuge (page) && !PageHuge (page)) { +page_ref_sub (page,thp_nr_pages (page)); +VM_BUG_ON_PAGE (page_count (page) <=0 , page); + }else { +put_page (page); + } + } }int filemap_check_errors (struct address_space *mapping)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1285/2214 hwrng: virtio - prevent use-after-free after a failed restore
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 0f7bf47f5a0cc26320aa4b14f4504d03a07f4b74 ]
remove_common() frees the driver data during freeze, but does not clear vdev->priv, which points to freed memory. If probe_common() then fails during restore, a later remove or freeze can dereference the dangling pointer.
Clear vdev->priv on the probe_common() error cleanup path and before freeing the driver data in remove_common(). Also reset the device and return early from remove_common() if vdev->priv is already NULL for a safe teardown after a failed restore.
Message-ID: <[email protected]>
--- drivers/char/hw_random/virtio-rng.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/char/hw_random/virtio-rng.c +7 -0
@@ -186,6 +186,7 @@ static int probe_common(struct virtio_device *vdev) err_find:ida_simple_remove (&rng_index_ida, index); err_ida: + vdev->priv =NULL ;kfree (vi);return err; }
@@ -194,6 +195,11 @@ static void remove_common(struct virtio_device *vdev) {struct virtrng_info *vi = vdev->priv; +if (!vi) { + vdev->config->reset (vdev); +return ; + } + vi->hwrng_removed = true; vi->data_avail =0 ; vi->data_idx =0 ;
@@ -203,6 +209,7 @@ static void remove_common(struct virtio_device *vdev)hwrng_unregister (&vi->hwrng); vdev->config->del_vqs (vdev);ida_simple_remove (&rng_index_ida, vi->index); + vdev->priv =NULL ;kfree (vi); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1286/2214 mm/rmap: handle device-exclusive entries in folio_referenced_one()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit f3c493d2f42b5f44a5c134d8d7ea7f960caf5e2c ]
page_vma_mapped_walk() can return non-present device-exclusive entries, but folio_referenced_one() passes them to PTE young-bit accessors that require present PTEs.
We must neither call clear_flush_young_ptes_notify() nor folio_pte_batch() with non-present entries. For example, clearing the young bit on non-present PTEs can corrupt the entry: on arm64 PTE_AF overlaps the swap type, so clearing it turns a device-exclusive entry into an ordinary swap entry.
folio_pte_batch() will VM_WARN_ON_FOLIO.
Apply the same approach as the previous fixes to e.g., damon_ptep_mkold():
treat these entries as old from the CPU's perspective and obtain their young state through the MMU notifier.
Skip PTE batching and MGLRU look-around for non-present entries, and don't modify non-present PTEs.
--- mm/rmap.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
mm/rmap.c +13 -2
@@ -797,8 +797,19 @@ static bool page_referenced_one(struct page *page, struct vm_area_struct *vma, }if (pvmw.pte) { -if (ptep_clear_flush_young_notify (vma, address, - pvmw.pte)) { +pte_t pteval =ptep_get (pvmw.pte); +bool young = false; + +/* +* PFN swap PTEs, such as device-exclusive ones, that +* actually map pages are "old" from a CPU perspective. +* The MMU notifier takes care of any device aspects. +*/ +if (pte_present (pteval)) + young =ptep_clear_flush_young (vma, address, pvmw.pte); + young |=mmu_notifier_clear_flush_young (vma->vm_mm, address, + address +PAGE_SIZE ); +if (young) {/* * Don't treat a reference through * a sequentially read mapping as such.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1287/2214 fork: take mmap_lock before copying mm_struct
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit ef694e2d210111cc08c52fd25da9ab130170bfa3 ]
dup_mm() copies the parent's mm_struct before dup_mmap() takes the mmap_lock. A concurrent brk() can leave the child with a stale mm->brk and newer heap mappings, causing later brk() requests to fail.
Other operations (e.g., PR_SET_MM) on the parent's mm_struct can similarly cause inconsistencies.
As a simple and robust fix, grab the parent's mmap_lock earlier. This way we don't need to update individual mm fields in dup_mmap() and keep missing ones. Stop updating the 4 existing members (total_vm, data_vm, exec_vm, stack_vm), as that is now no longer required.
Keep releasing the parent's mmap_lock in dup_mmap(), before userfaultfd completion, to avoid moving the userfaultfd handling into the caller. This should get cleaned up later.
Move uprobe_start_dup_mmap() to preserve the lock ordering.
--- kernel/fork.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
kernel/fork.c +15 -14
@@ -501,11 +501,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,unsigned long charge;LIST_HEAD (uf); -uprobe_start_dup_mmap (); -if (mmap_write_lock_killable (oldmm)) { - retval = -EINTR ; - goto fail_uprobe_end; - } +mmap_assert_write_locked (oldmm);flush_cache_dup_mm (oldmm);uprobe_dup_mmap (oldmm, mm);/*
@@ -516,11 +512,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,/* No ordering required: file already has been exposed. */ dup_mm_exe_file (mm, oldmm); - mm->total_vm = oldmm->total_vm; - mm->data_vm = oldmm->data_vm; - mm->exec_vm = oldmm->exec_vm; - mm->stack_vm = oldmm->stack_vm; - rb_link = &mm->mm_rb.rb_node; rb_parent =NULL ; pprev = &mm->mmap;
@@ -628,7 +619,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,flush_tlb_mm (oldmm);mmap_write_unlock (oldmm);dup_userfaultfd_complete (&uf); -fail_uprobe_end:uprobe_end_dup_mmap ();return retval; fail_nomem_anon_vma_fork:
@@ -656,7 +646,7 @@ static inline void mm_free_pgd(struct mm_struct *mm)#else static int dup_mmap (struct mm_struct *mm,struct mm_struct *oldmm) { -mmap_write_lock (oldmm); +mmap_assert_write_locked (oldmm);dup_mm_exe_file (mm, oldmm);mmap_write_unlock (oldmm);return 0 ;
@@ -1467,10 +1457,18 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,if (!mm) goto fail_nomem; +uprobe_start_dup_mmap (); +if (mmap_write_lock_killable (oldmm)) { +free_mm (mm); + goto fail_uprobe; + } +memcpy (mm, oldmm,sizeof (*mm)); -if (!mm_init (mm, tsk, mm->user_ns)) - goto fail_nomem; +if (!mm_init (mm, tsk, mm->user_ns)) { +mmap_write_unlock (oldmm); + goto fail_uprobe; + } err =dup_mmap (mm, oldmm);if (err)
@@ -1489,7 +1487,10 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, mm->binfmt =NULL ;mm_init_owner (mm,NULL );mmput (mm); +return NULL ; +fail_uprobe: +uprobe_end_dup_mmap (); fail_nomem:return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1288/2214 hwmon: (coretemp) Check for NULL platform device in hotplug callbacks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 0f9c7ed3b5009a037e5533eac03a0d4d45ecf1f0 ]
coretemp_get_pdev() returns NULL when topology_logical_die_id(cpu) is negative (such as -ENODEV or -ERANGE from topology_get_logical_id() on a firmware/hardware APIC ID mismatch) or exceeds max_zones (for example, under asymmetric or anomalous ACPI die topologies where topology_max_packages() * topology_max_dies_per_package() is smaller than the logical die count).
Commit 6d03bbff456b ("hwmon: (coretemp) Simplify platform device handling") pre-allocated zone_devices[0 .. max_zones - 1] during module init and dropped the NULL checks on pdev in coretemp_cpu_online() and coretemp_cpu_offline(), passing pdev unconditionally to platform_get_drvdata(). When coretemp_get_pdev() returns NULL, platform_get_drvdata(pdev) dereferences &pdev->dev and triggers a kernel NULL pointer dereference.
Check for a NULL pdev and return 0 in both coretemp_cpu_online() and coretemp_cpu_offline() before calling platform_get_drvdata(). Returning 0 in coretemp_cpu_online() ignores the unmapped CPU without blocking CPU bringup or tearing down valid thermal zones on other dies.
--- drivers/hwmon/coretemp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hwmon/coretemp.c +6 -0
@@ -619,6 +619,9 @@ static int coretemp_cpu_online(unsigned int cpu)if (!cpu_has (c,X86_FEATURE_DTHERM ))return -ENODEV ; +if (!pdev) +return 0 ; + pdata =platform_get_drvdata (pdev);if (!pdata->hwmon_dev) {struct device *hwmon;
@@ -670,6 +673,9 @@ static int coretemp_cpu_offline(unsigned int cpu)return 0 ;/* If the physical CPU device does not exist, just return */ +if (!pdev) +return 0 ; + pd =platform_get_drvdata (pdev);if (!pd->hwmon_dev)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1289/2214 drm/amdgpu: Only enable HDMI audio if display supports it
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: renpanpan <[email protected]>
[ Upstream commit 0de95c96655c8a12df62e47871016f49e5cd8618 ]
The amdgpu legacy DCE audio path (dce_v6/v8/v10) unconditionally calls audio_enable(pin, true) at the end of afmt_setmode(), regardless of whether the connected display advertises audio support in its EDID.
This causes a phantom HDMI audio output to appear for displays that have no audio capability (no basic audio bit, no Audio Data Block in EDID), because the GPU sets the AUDIO_ENABLED register bit, which drives the HDA codec's ELDV pin sense, making the codec report the jack as audio-available.
The radeon, nouveau, and dw-hdmi drivers all gate audio enablement on display_info.has_audio. Apply the same check to amdgpu's DCE afmt_setmode functions.
--- drivers/gpu/drm/amd/amdgpu/dce_v10_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/dce_v6_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +3 -2
@@ -1738,8 +1738,9 @@ static void dce_v10_0_afmt_setmode(struct drm_encoder *encoder,WREG32 (mmAFMT_RAMP_CONTROL2 + dig->afmt->offset,0x00000001 );WREG32 (mmAFMT_RAMP_CONTROL3 + dig->afmt->offset,0x00000001 ); -/* enable audio after to setting up hw */ -dce_v10_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (drm_detect_monitor_audio (amdgpu_connector_edid (connector))) +dce_v10_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v10_0_afmt_enable (struct drm_encoder *encoder,bool enable)
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +3 -2
@@ -1702,8 +1702,9 @@ static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder,dce_v6_0_audio_dp_enable (encoder,1 ); } -/* enable audio after setting up hw */ -dce_v6_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (drm_detect_monitor_audio (amdgpu_connector_edid (connector))) +dce_v6_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v6_0_afmt_enable (struct drm_encoder *encoder,bool enable)
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +3 -2
@@ -1667,8 +1667,9 @@ static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder,WREG32 (mmAFMT_RAMP_CONTROL2 + offset,0x00000001 );WREG32 (mmAFMT_RAMP_CONTROL3 + offset,0x00000001 ); -/* enable audio after setting up hw */ -dce_v8_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (drm_detect_monitor_audio (amdgpu_connector_edid (connector))) +dce_v8_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v8_0_afmt_enable (struct drm_encoder *encoder,bool enable)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1290/2214 ocfs2: use the stored hash when checking xattr bucket collision
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit e39baff18b85cf8956aee138d7944b6581e8ba36 ]
ocfs2_check_xattr_bucket_collision() decides whether splitting a full bucket can make room for the entry being set by recomputing the hash of the name:
u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name)); if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash)) return 0;
For a new entry that is the hash it will be stored under, so comparing it is correct. An existing entry keeps the hash it already has: an update never rewrites xe_name_hash, since ocfs2_xa_add_entry() is the only writer of that field for a real entry and ocfs2_xa_prepare_entry() calls it only when loc->xl_entry is NULL.
An entry stored by a kernel that sign-extended the name bytes when hashing can still be updated, because ocfs2_xattr_find_entry() searches a non-indexed xattr block by memcmp on the name and never looks at xe_name_hash. Growing it past the space left in the block converts the block into a tree, ocfs2_cp_xattr_block_to_bucket() fills the bucket in stored hash order, and the update runs out of room in the bucket too. The collision check then compares the unsigned hash against the legacy hashes in the bucket and reports no collision.
ocfs2_xattr_set_entry_index_block() goes on to allocate a bucket that ocfs2_divide_xattr_bucket() cannot fill: a bucket whose entries all share one hash has no divide position, so all it does is append an empty bucket with a sentinel hash one above the last entry's.
The re-search that follows depends on where the unsigned hash sorts. Below the legacy ones, it comes back to the full bucket and the set fails with -ENOSPC, having grown the tree for nothing. Above them, it lands on the new empty bucket, which ocfs2_xattr_bucket_find() handles explicitly and ocfs2_find_xe_in_bucket() scans zero times, so the set stores a second copy of the entry under the unsigned hash and returns success. The original stays in the full bucket, listxattr reports the name twice and getxattr returns the new copy.
Pass the hash the entry is stored under instead: the stored one for an existing entry, the unsigned one for a new entry. A tree whose entries are all stored under the unsigned hash sees no change, since there the two are the same value.
Stable-dep-of: e8de099f2958 ("ocfs2: do not read the entry array of an empty xattr bucket")
--- fs/ocfs2/xattr.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +17 -10
@@ -5601,16 +5601,14 @@ static int ocfs2_rm_xattr_cluster(struct inode *inode,/* * check whether the xattr bucket is filled up with the same hash value. -* If we want to insert the xattr with the same hash, return -ENOSPC. -* If we want to insert a xattr with different hash value, go ahead -* and ocfs2_divide_xattr_bucket will handle this. +* If the entry being set carries that same hash, return -ENOSPC, since +* ocfs2_divide_xattr_bucket() has no divide position to work with. +* Otherwise go ahead and ocfs2_divide_xattr_bucket() will handle this. */ -static int ocfs2_check_xattr_bucket_collision (struct inode *inode, -struct ocfs2_xattr_bucket *bucket, -const char *name) +static int ocfs2_check_xattr_bucket_collision (struct ocfs2_xattr_bucket *bucket, +u32 name_hash) {struct ocfs2_xattr_header *xh =bucket_xh (bucket); -u32 name_hash =ocfs2_xattr_name_hash (inode, name,strlen (name));if (name_hash !=le32_to_cpu (xh->xh_entries[0 ].xe_name_hash))return 0 ;
@@ -5707,6 +5705,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { + u32 name_hash;int ret;trace_ocfs2_xattr_set_entry_index_block (xi->xi_name);
@@ -5726,10 +5725,18 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,* the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. +* +* An existing entry keeps the hash it was stored under, and that is +* the hash a split has to work with. A new entry is stored under the +* unsigned one, which is what ocfs2_xa_add_entry() will write. */ - ret =ocfs2_check_xattr_bucket_collision (inode, - xs->bucket, - xi->xi_name); +if (xs->not_found) + name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, + xi->xi_name_len); +else + name_hash =le32_to_cpu (xs->here->xe_name_hash); + + ret =ocfs2_check_xattr_bucket_collision (xs->bucket, name_hash);if (ret) {mlog_errno (ret); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1291/2214 ocfs2: do not read the entry array of an empty xattr bucket
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit e8de099f2958c84aa23186c5481e69f7ffd39355 ]
ocfs2_check_xattr_bucket_collision() decides whether splitting a bucket can make room by comparing the hash being inserted against the first and the last entry. xh_count comes off disk and is never checked, and a bucket is allowed to hold no entries: ocfs2_xa_remove_entry() keeps the last slot when it removes the only one, so that an empty bucket still carries the hash it is keyed by. xh_count then reads back as 0 while xh_entries[0] is still meaningful, and the second comparison indexes xh_entries[-1].
That is outside the __counted_by_le(xh_count) bounds of xh_entries[] and lands on the header. An entry is 16 bytes and xe_name_hash is its first field, so the value read is xh_count | xh_free_start << 16. It stays inside the block, but the answer is arbitrary, and for an empty bucket it says there is no collision, so a new bucket gets added on the strength of it.
An empty bucket holds no entries to collide with. Return before reading the array.
One way to reach the test with an empty bucket is a set that removes the bucket's only entry during cleanup and then fails for space again, since it is that second -ENOSPC which calls this. Growing a value past OCFS2_XATTR_INLINE_SIZE is the easy route: the cluster allocation fails, the "!orig_clusters" arm of ocfs2_xa_cleanup_value_truncate() removes the entry, and although the "growing" caller does set ctxt->set_abort, only ocfs2_xattr_block_set() and __ocfs2_xattr_set_handle() look at it, so ocfs2_xattr_set_entry_index_block() goes straight on to the collision check.
This sits on commit a9ea8b397864 ("ocfs2: use the stored hash when checking xattr bucket collision"), which gave the collision check its two argument form and is marked for 6.2 and later. The read fixed here is present in the three argument version too, but a tree without that commit needs the hunk adapted by hand.
--- fs/ocfs2/xattr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +10 -1
@@ -5609,11 +5609,20 @@ static int ocfs2_check_xattr_bucket_collision(struct ocfs2_xattr_bucket *bucket, u32 name_hash) {struct ocfs2_xattr_header *xh =bucket_xh (bucket); +u16 count =le16_to_cpu (xh->xh_count); + +/* +* An empty bucket keeps the hash of the entry that was removed in +* xh_entries[0] so that it can still be found, but it holds no +* entries to collide with. +*/ +if (!count) +return 0 ;if (name_hash !=le32_to_cpu (xh->xh_entries[0 ].xe_name_hash))return 0 ; -if (xh->xh_entries[le16_to_cpu (xh->xh_count) -1 ].xe_name_hash == +if (xh->xh_entries[count -1 ].xe_name_hash == xh->xh_entries[0 ].xe_name_hash) { mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, " "hash = %u\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1292/2214 ocfs2: read the xattr entry hash before defragmenting the bucket
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit f48151da595e74efdc23d83d8d6d142207b8c731 ]
Patch series "ocfs2: fix stale xattr entry pointers and empty header reads", v1.
Five defects in the ocfs2 extended attribute code, plus one robustness measure that belongs with them, all on the paths that move entries between a block, a bucket and an index tree. They fall into two groups.
Stale entry pointers (patches 1 to 3)
ocfs2_xa_set() writes through a pointer into xh_entries[] that two of its callers invalidate first. Defragmenting a bucket ends in a sort() on xe_name_hash, and lib/sort.c is an unstable heapsort, so entries that share a hash can trade slots. Copying a block into a bucket changes the order outright, since a block holds its entries in insertion order while a bucket holds them by hash, yet ocfs2_xattr_update_xattr_search() relocates the search by the index the entry had in the block. Neither path compares the entry's name with the one being set, so setxattr() can replace a neighbouring attribute's value and still report success, or trip ocfs2_xa_reuse_entry()'s BUG_ON. Patch 1 takes the hash before the sort; patches 2 and 3 look the entry up again afterwards.
Reads of an empty entry array (patches 4 to 6)
A block and a bucket may both hold no entries: ocfs2_xa_remove_entry() keeps the last slot when it removes the only one, so an empty bucket still carries the hash it is keyed by. Three sites index xh_entries[] without checking xh_count and so read xh_entries[-1], which lands on the header and comes back as xh_count | xh_free_start << 16. Nothing faults, but the value is acted on: the collision check reports no collision for an empty bucket, the divide commits a sentinel hash that hides part of the key space from ocfs2_xattr_bucket_find(), and the block to bucket copy claims storage the bucket does not hold. Patches 4 to 6 guard each site and keep the one read of xh_entries[0] that ocfs2_xa_remove_entry() documents as intentional.
This patch (of 6):
ocfs2_xattr_set_entry_index_block() takes the hash a bucket split has to work with out of xs->here, but only after ocfs2_xattr_set_entry_bucket() has tried and failed to fit the entry. That call defragments the bucket when it runs out of room, and ocfs2_defrag_xattr_bucket() finishes by sorting the entry array by name hash. lib/sort.c is not stable, so two entries sharing a hash may trade slots and xs->here is left naming an entry other than the one the search found.
The hash value itself survives the permutation -- the array is already sorted, so a slot can only exchange with an equal-hash neighbour -- but there is no reason to depend on that. Pick the hash up before the set, where xs->here is unambiguously the entry the search landed on.
No functional change intended.
--- fs/ocfs2/xattr.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +16 -10
@@ -5719,6 +5719,22 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,trace_ocfs2_xattr_set_entry_index_block (xi->xi_name); +/* +* An existing entry keeps the hash it was stored under, and that is +* the hash a split has to work with. A new entry is stored under the +* unsigned one, which is what ocfs2_xa_add_entry() will write. +* +* Read it before the set below. Filling the bucket may defragment it, +* and ocfs2_defrag_xattr_bucket() re-sorts the entry array, so +* afterwards xs->here only denotes whichever entry the sort left in +* that slot. +*/ +if (xs->not_found) + name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, + xi->xi_name_len); +else + name_hash =le32_to_cpu (xs->here->xe_name_hash); + ret =ocfs2_xattr_set_entry_bucket (inode, xi, xs, ctxt);if (!ret) goto out;
@@ -5734,17 +5750,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,* the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. -* -* An existing entry keeps the hash it was stored under, and that is -* the hash a split has to work with. A new entry is stored under the -* unsigned one, which is what ocfs2_xa_add_entry() will write. */ -if (xs->not_found) - name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, - xi->xi_name_len); -else - name_hash =le32_to_cpu (xs->here->xe_name_hash); - ret =ocfs2_check_xattr_bucket_collision (xs->bucket, name_hash);if (ret) {mlog_errno (ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1293/2214 drm/amd/display: Avoid closing unowned DDC pins
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Hung <[email protected]>
[ Upstream commit e7ba638b8116cb5f1a5690f543052371215f1626 ]
[WHY]dal_ddc_open() cleans up pins it acquires on later failures. If the data-pin open fails, this attempt acquired nothing. If opening the clock pin or configuring fails, dal_ddc_open() closes the pins it opened. An extra dal_ddc_close() is unnecessary and unsafe:GPIO_RESULT_ALREADY_OPENED can mean AUX owns the existing handles, and closing them here would disrupt AUX.
[HOW]
Remove the extra dal_ddc_close() from the failed-open path.
--- drivers/gpu/drm/amd/display/dc/core/dc_link.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -5
@@ -392,12 +392,8 @@ bool dc_link_is_dp_sink_present(struct dc_link *link)* which indicates we need additional delay */ -if (dal_ddc_open (ddc,GPIO_MODE_INPUT , -GPIO_DDC_CONFIG_TYPE_MODE_I2C ) !=GPIO_RESULT_OK ) { -dal_ddc_close (ddc); - +if (dal_ddc_open (ddc,GPIO_MODE_INPUT ,GPIO_DDC_CONFIG_TYPE_MODE_I2C ) !=GPIO_RESULT_OK )return present; - }/* * Read GPIO: DP sink is present if both clock and data pins are zero
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1294/2214 ALSA: hda/realtek: Fix internal speakers on Acer Aspire AL16-31P
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luis Gerardo Lopez Hernandez <[email protected]>
[ Upstream commit d933955c456e0573b40eae4f72a3af37ab1c15c3 ]
The Acer Aspire AL16-31P (Intel Alder Lake-N, Realtek ALC269VC, PCI/codec SSID 2782:1718) has its internal speakers wired to pin 0x1b, but the BIOS marks that pin as not connected (0x411111f0) and only exposes pin 0x14 as the speaker. As a result the internal speakers are silent while headphones, HDMI and Bluetooth work.
This is the same layout as the Infinix Y4 Max and MEDION E15433, which share the 0x2782 subsystem vendor. Reuse their fixup, which configures pin 0x1b as an internal speaker and limits the internal mic boost.
Tested by booting with snd-hda-intel model=2782:1705: the fixup is picked, pin 0x1b is used as a speaker output, the internal speakers work, and they are muted when headphones are plugged in.
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -9722,6 +9722,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x2782 ,0x1701 ,"Infinix Y4 Max" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1705 ,"MEDION E15433" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1707 ,"Vaio VJFE-ADL" ,ALC298_FIXUP_SPK_VOLUME ), +SND_PCI_QUIRK (0x2782 ,0x1718 ,"Acer Aspire AL16-31P" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x8086 ,0x2074 ,"Intel NUC 8" ,ALC233_FIXUP_INTEL_NUC8_DMIC ),SND_PCI_QUIRK (0x8086 ,0x2080 ,"Intel NUC 8 Rugged" ,ALC256_FIXUP_INTEL_NUC8_RUGGED ), SND_PCI_QUIRK(0x8086, 0x2081, "Intel NUC 10", ALC256_FIXUP_INTEL_NUC10),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1295/2214 vduse: fix VA/PA confusion in the coherent page fault path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: chenglong.ma <[email protected]>
[ Upstream commit bb2e6f166547838fd7c320b01c90918b736f76e2 ]
vduse_domain_get_coherent_page() assumes that iotlb entries above bounce_size were installed by vduse_domain_alloc_coherent(), so it treats map->addr as a physical address. But vduse registers with use_va = true, and when the device is bound to vhost_vdpa, vhost_vdpa_va_map() stores a userspace virtual address in map->addr, which vduse_domain_set_map() then copies into the same iotlb. A process holding the domain file descriptor across a rebind can therefore fault in an arbitrary physical page with read/write access, ignoring the entry permissions.
Additionally, since the domain file mmap lacks VM_IO, the domain file itself can be mapped and passed to vhost_vdpa_va_map(), producing self-referential entries that bypass the coherent path check.
To fix, only translate entries whose backing file is the domain file itself in vduse_domain_get_coherent_page(), reject such entries in vduse_domain_set_map() since only external mappings should be imported, and set VM_IO on the domain file mmap so vhost_vdpa_va_map() refuses to map it in the first place.
--- drivers/vdpa/vdpa_user/iova_domain.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_user/iova_domain.c +10 -1
@@ -70,6 +70,10 @@ int vduse_domain_set_map(struct vduse_iova_domain *domain,for (map =vhost_iotlb_itree_first (iotlb, start, last); map; map =vhost_iotlb_itree_next (map, start, last)) { map_file = (struct vdpa_map_file *)map->opaque; +if (!map_file || map_file->file == domain->file) { + ret = -EINVAL ; + goto err; + } ret = vduse_iotlb_add_range(domain, map->start, map->last, map->addr, map->perm, map_file->file,
@@ -216,6 +220,7 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova) {u64 start = iova &PAGE_MASK ;u64 last = start +PAGE_SIZE -1 ; +struct vdpa_map_file *map_file;struct vhost_iotlb_map *map;struct page *page =NULL ;
@@ -224,6 +229,10 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova)if (!map) goto out; + map_file = (struct vdpa_map_file *)map->opaque; +if (!map_file || map_file->file != domain->file) + goto out; + page =pfn_to_page ((map->addr + iova - map->start) >>PAGE_SHIFT );get_page (page); out:
@@ -461,7 +470,7 @@ static int vduse_domain_mmap(struct file *file, struct vm_area_struct *vma) {struct vduse_iova_domain *domain = file->private_data; - vma->vm_flags |=VM_DONTDUMP |VM_DONTEXPAND ; + vma->vm_flags |=VM_IO |VM_DONTDUMP |VM_DONTEXPAND ; vma->vm_private_data = domain; vma->vm_ops = &vduse_domain_mmap_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1296/2214 mm/filemap: finish fault cleanup before dropping the fault lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 97156a6c355c21f7122421915f05461bd11699a4 ]
On a retried fault, a fatal signal interrupting the folio lock wait makes lock_folio_maybe_drop_mmap() drop the fault lock without pinning the file. However, filemap_fault() may still need to release mapping->invalidate_lock. A concurrent munmap() can release the last file reference and free the mapping before that unlock.
Defer dropping the fault lock to filemap_fault()'s retry cleanup, after releasing invalidate_lock. If the fault lock was already dropped for I/O, release the existing file reference instead. Keep the fault lock held for FAULT_FLAG_RETRY_NOWAIT as before.
--- mm/filemap.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
mm/filemap.c +14 -22
@@ -2911,10 +2911,11 @@ loff_t mapping_seek_hole_data(struct address_space *mapping, loff_t start,* @page - the page to lock. * @fpin - the pointer to the file we may pin (or is already pinned). * -* This works similar to lock_page_or_retry in that it can drop the mmap_lock. -* It differs in that it actually returns the page locked if it returns 1 and 0 -* if it couldn't lock the page. If we did have to drop the mmap_lock then fpin -* will point to the pinned file and needs to be fput()'ed at a later point. +* Returns 1 with the page locked, or 0 if locking failed. +* +* On both entry and return, a non-NULL *fpin means the fault lock has +* already been dropped and the caller must eventually fput() the file. +* Otherwise the fault lock is still held, including on failure. */ static int lock_page_maybe_drop_mmap (struct vm_fault *vmf,struct page *page,struct file **fpin)
@@ -2931,20 +2932,10 @@ static int lock_page_maybe_drop_mmap(struct vm_fault *vmf, struct page *page,return 0 ; *fpin =maybe_unlock_mmap_for_io (vmf, *fpin); -if (vmf->flags &FAULT_FLAG_KILLABLE ) { -if (__lock_page_killable (page)) { -/* -* We didn't have the right flags to drop the mmap_lock, -* but all fault_handlers only check for fatal signals -* if we return VM_FAULT_RETRY, so we need to drop the -* mmap_lock here and return 0 if we don't have a fpin. -*/ -if (*fpin ==NULL ) -mmap_read_unlock (vmf->vma->vm_mm); -return 0 ; - } - }else -__lock_page (page); +if (vmf->flags &FAULT_FLAG_KILLABLE ) +return !__lock_page_killable (page); +__lock_page (page); +return 1 ; }
@@ -3044,7 +3035,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf,* vma->vm_mm->mmap_lock must be held on entry. * * If our return value has VM_FAULT_RETRY set, it's because the mmap_lock -* may be dropped before doing I/O or by lock_page_maybe_drop_mmap(). +* may be dropped before doing I/O or when aborting an interrupted wait. * * If our return value does not have VM_FAULT_RETRY set, the mmap_lock * has not been released.
@@ -3188,9 +3179,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) out_retry:/* -* We dropped the mmap_lock, we need to return to the fault handler to -* re-find the vma and come back and find our hopefully still populated -* page. +* With fpin set, the fault lock was already dropped. Otherwise it is +* still held. Release invalidate_lock before dropping either protection. */ if (page)put_page (page);
@@ -3198,6 +3188,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)filemap_invalidate_unlock_shared (mapping);if (fpin)fput (fpin); +else if (!(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) +mmap_read_unlock (vmf->vma->vm_mm);return ret |VM_FAULT_RETRY ; }EXPORT_SYMBOL (filemap_fault);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1297/2214 ipv6: raw: fix use-after-free in rawv6_send_hdrinc()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhou Qiuyue <[email protected]>
[ Upstream commit 66dfb2cacda7faae614d688943d85e75abf7f586 ]
rawv6_send_hdrinc() caches the route before handing the skb to l3mdev_ip6_out(). The VRF output path may replace skb->dst and release the original route, leaving the cached pointer stale.
The function later dereferences that pointer for statistics accounting and as the output device passed to NF_HOOK(). Its RCU read-side critical section starts after l3mdev_ip6_out(), so it cannot prevent the old route from being reclaimed in between.
Reload the route from the current skb destination after l3mdev_ip6_out() returns.
KASAN reports a slab-use-after-free in rawv6_sendmsg(), with the route allocated by ip6_dst_alloc(), freed by dst_destroy() from rcu_core(), and the related RCU callback queued from vrf_l3_out().
--- net/ipv6/raw.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/raw.c +3 -0
@@ -650,6 +650,9 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,if (unlikely (!skb))return 0 ; +/* l3mdev_ip6_out() may have replaced the skb dst. */ + rt = (struct rt6_info *)skb_dst (skb); +/* Acquire rcu_read_lock() in case we need to use rt->rt6i_idev * in the error path. Since skb has been freed, the dst could * have been queued for deletion.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1298/2214 mm/shmem: make shmem_file() check the files inode
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit d3710111839d11339e414b1bb3fea3d05ab83f6e ]
shmem_file() only checks if file->f_mapping is a shmem mapping. This mapping can belong to another file, however, as with a Coda file backed by a tmpfs container after mmap().
So it does not guarantee that the file inode is an actual shmem inode.
Seal handling and memfd preservation use this check before accessing shmem inode state, so they can access an inode of the wrong type.
Let's make shmem_file() check the inode's file operations instead, to identify shmem inodes reliably. This will identify regular shmem inodes, including memfds and ordinary tmpfs files, independently of wrapper file operations.
Use shmem_mapping() in collapse_file() instead to not change the behavior of collapse_file(): it operates on the page cache and uses mapping->host for shmem inode operations. Focusing on the file does not seem relevant.
--- include/linux/shmem_fs.h | 15 ++++++--------- mm/khugepaged.c | 2 +- mm/shmem.c | 5 +++++ 3 files changed, 12 insertions(+), 10 deletions(-)
include/linux/shmem_fs.h +6 -9
@@ -68,12 +68,18 @@ extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags);extern int shmem_lock (struct file *file,int lock,struct ucounts *ucounts);#ifdef CONFIG_SHMEM +bool shmem_file (struct file *file);extern const struct address_space_operations shmem_aops;static inline bool shmem_mapping (struct address_space *mapping) {return mapping->a_ops == &shmem_aops; }#else +static inline bool shmem_file (struct file *file) +{ +return false; +} +static inline bool shmem_mapping (struct address_space *mapping) {return false;
@@ -115,15 +121,6 @@ static inline struct page *shmem_read_mapping_page( mapping_gfp_mask(mapping)); } -static inline bool shmem_file (struct file *file) -{ -if (!IS_ENABLED (CONFIG_SHMEM )) -return false; -if (!file || !file->f_mapping) -return false; -return shmem_mapping (file->f_mapping); -} -/* * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages * beyond i_size's notion of EOF, which fallocate has committed to reserving:
mm/khugepaged.c +1 -1
@@ -1694,13 +1694,13 @@ static void collapse_file(struct mm_struct *mm, struct page **hpage, int node) {struct address_space *mapping = file->f_mapping; +const bool is_shmem =shmem_mapping (mapping);gfp_t gfp;struct page *new_page;pgoff_t index, end = start +HPAGE_PMD_NR ;LIST_HEAD (pagelist);XA_STATE_ORDER (xas, &mapping->i_pages, start,HPAGE_PMD_ORDER );int nr_none =0 , result =SCAN_SUCCEED ; -bool is_shmem =shmem_file (file);int nr;VM_BUG_ON (!IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !is_shmem);
mm/shmem.c +5 -0
@@ -250,6 +250,11 @@ static const struct inode_operations shmem_special_inode_operations;static const struct vm_operations_struct shmem_vm_ops;static struct file_system_type shmem_fs_type; +bool shmem_file (struct file *file) +{ +return file &&file_inode (file)->i_fop == &shmem_file_operations; +} +bool vma_is_shmem (struct vm_area_struct *vma) {return vma->vm_ops == &shmem_vm_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1299/2214 nvmet: reject keep-alive timeouts that would overflow
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingjie Wang <[email protected]>
[ Upstream commit 96ae13f40ce5930cd58c43128e385131476f2a66 ]
nvmet_set_feat_kato() and nvmet_alloc_ctrl() convert the 32-bit millisecond KATO from the host to seconds with DIV_ROUND_UP(kato, 1000). The addition in DIV_ROUND_UP() is done in 32 bits, so any KATO above 4294966296 ms wraps around and rounds to 0 seconds. A Set Features command with KATO 0xffffffff then succeeds but disables the keep-alive
timer: Get Features returns 0 and Keep Alive fails with Keep Alive Timeout Invalid. A Connect command with such a KATO creates a controller without a keep-alive timer.
The converted value has more consumers that can overflow. Get Features multiplies it by 1000, and the timer paths multiply it by HZ in 32 bits and arm a delay that must not exceed MAX_JIFFY_OFFSET.
Reject a KATO whose rounded value does not fit all of these. Return Keep Alive Timeout Invalid from both Set Features and Connect. Validate Set Features before stopping the current timer so a failed update leaves its timeout unchanged. Round in 64 bits. A KATO of 0 keeps its current meaning.
--- drivers/nvme/target/admin-cmd.c | 7 ++++++- drivers/nvme/target/core.c | 7 ++++++- drivers/nvme/target/nvmet.h | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +6 -1
@@ -808,8 +808,13 @@ u16 nvmet_set_feat_kato(struct nvmet_req *req) {u32 val32 =le32_to_cpu (req->cmd->common.cdw11); +if (val32 >NVMET_MAX_KATO *MSEC_PER_SEC ) { + req->error_loc = offsetof(struct nvme_common_command , cdw11); +return NVME_SC_KA_TIMEOUT_INVALID |NVME_STATUS_DNR ; + } +nvmet_stop_keep_alive_timer (req->sq->ctrl); - req->sq->ctrl->kato =DIV_ROUND_UP (val32,1000 ); + req->sq->ctrl->kato =DIV_ROUND_UP_ULL (val32,MSEC_PER_SEC );nvmet_start_keep_alive_timer (req->sq->ctrl);nvmet_set_result (req, req->sq->ctrl->kato);
drivers/nvme/target/core.c +6 -1
@@ -1355,6 +1355,11 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,int ret;u16 status; +if (kato >NVMET_MAX_KATO *MSEC_PER_SEC ) { + req->error_loc = offsetof(struct nvmf_connect_command , kato); +return NVME_SC_KA_TIMEOUT_INVALID |NVME_STATUS_DNR ; + } + status =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; subsys =nvmet_find_get_subsys (req->port, subsysnqn);if (!subsys) {
@@ -1432,7 +1437,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, kato =NVMET_DISC_KATO_MS ;/* keep-alive timeout in seconds */ - ctrl->kato =DIV_ROUND_UP (kato,1000 ); + ctrl->kato =DIV_ROUND_UP_ULL (kato,MSEC_PER_SEC ); ctrl->err_counter =0 ;spin_lock_init (&ctrl->error_lock);
drivers/nvme/target/nvmet.h +8 -0
@@ -7,6 +7,7 @@#define _NVMET_H#include <linux/dma-mapping.h> +#include <linux/jiffies.h> #include <linux/types.h> #include <linux/device.h> #include <linux/kref.h>
@@ -519,6 +520,13 @@ void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type,#define NVMET_KAS 10#define NVMET_DISC_KATO_MS 120000 +/* +* Largest keep-alive timeout in seconds that can be reported back in +* milliseconds and converted to jiffies without overflowing. +*/ +#define NVMET_MAX_KATO \ + min3(U32_MAX / MSEC_PER_SEC, U32_MAX / HZ, MAX_JIFFY_OFFSET / HZ) +int __init nvmet_init_configfs (void ); void __exit nvmet_exit_configfs(void);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1300/2214 KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit)
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit e4558c3d7198ed9a0adc3304681f561f4e4d80e1 ]
When potentially reusing a shadow page, zap the shadow page if its number of parent PTEs exceeds KVM's (mostly) arbitrary rmap recycling threshold. Letting the guest create a (mostly) unbounded number of parent PTEs allows the guest to coerce KVM into creating lists containing millions of PTEs, effectively bounded only by the maximum number of shadow pages.
Because PTE lists are simple singly linked lists, removal is O(n). Even worse, if a list is constructed just so, teardown can be O(n^2), e.g. if SPTEs are built such that zapping child SPTEs always zaps the last entry in the list. To cap things off, all paths that walk PTE lists do so while holding mmu_lock, without conditionally rescheduling.
Using a doubly linked list would not address the issue, as removal would remain O(n) since KVM still wouldn't know where in the list to remove from. Removal could be made O(1) by storing a per-SPTE pointer, but that would largely defeat the purpose of reusing SPs, and would penalize well-behaved guests, especially for nested TDP where aliasing page tables is uncommon.
So, cap the maximum number of parent PTEs at the rmap limit. In practice, well-behaved guests will likely never run afoul of the limit. E.g. when running Linux as L1 with TDP, the number of parent PTEs for a single SP tops out at under 200 (though undoubtedly obscure workloads can push it higher). Deliberately use a "greater than or equal" as opposed to rmap's strictly "greater than", as the rmap code checks the threshold immediately *after* inserting into the list, i.e. the limit is 1000 for rmaps, KVM just very briefly blows past it.
Apply the check to both indirect and direct SPs, because while a fully direct MMU naturally limits the number of parent PTEs to '1', direct SPs in indirect MMUs have no such constraint. E.g. if the guest maps a huge PTE into many locations in its page tables, and KVM is backing the hugepage with a direct SP, i.e. with a series of smaller pages, then KVM could end up with a direct SP with many parents.
Note, shadow_mmu_try_split_huge_pages() always restarts the rmap walk or bails entirely if it gets to the point where it tries to grab a SP, i.e. there is *no* pre-existing bug that would be tripped by zapping a SP and thus rmaps when getting a SP.
Message-ID: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kvm/mmu/mmu.c +10 -0
@@ -2087,6 +2087,16 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, gfn_t gfn,continue ; } +/* +* Note! Unlike fully direct MMUs, direct SPs in indirect MMUs +* can have an arbitrary number of parents, e.g if the guest is +* mapping a huge PTE at many points in its page tables. +*/ +if (pte_list_count (&sp->parent_ptes) >=RMAP_RECYCLE_THRESHOLD ) { +kvm_mmu_prepare_zap_page (vcpu->kvm, sp, &invalid_list); +break ; + } +if (direct_mmu) goto trace_get_page;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1301/2214 mm: document mmu_notifier_invalidate_range_start_nonblock()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
[ Upstream commit 7ced098fcfe596feab3cea4f40128b0119c7bf1a ]
Document what mmu_notifier_invalidate_range_start_nonblock() is for. Also add a __must_check annotation to signal that callers must bail out if a notifier vetoes the operation.
Stable-dep-of: 6d65925777ec ("mm/mmu_notifier: finish non-blocking interval invalidation on error")
--- include/linux/mmu_notifier.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
include/linux/mmu_notifier.h +8 -1
@@ -461,7 +461,14 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)lock_map_release (&__mmu_notifier_invalidate_range_start_map); } -static inline int +/* +* This version of mmu_notifier_invalidate_range_start() avoids blocking, but it +* can return an error if a notifier can't proceed without blocking, in which +* case you're not allowed to modify PTEs in the specified range. +* +* This is mainly intended for OOM handling. +*/ +static inline int __must_check mmu_notifier_invalidate_range_start_nonblock (struct mmu_notifier_range *range) {int ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1302/2214 mm/mmu_notifier: finish non-blocking interval invalidation on error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6d65925777ecae9d7a571a327e41c63f3940a0c7 ]
When an ordinary MMU notifier rejects a non-blocking invalidation, the interval invalidation started beforehand is left unfinished: the caller skips mmu_notifier_invalidate_range_end(). Subsequent interval notifier operations can then wait forever.
The only in-tree trigger is nouveau SVM, which uses both notifier types and rejects non-blocking invalidations. Reaping via the OOM reaper or process_mrelease() can therefore leave the GPU fault worker stuck, holding a reference that prevents the dying process's address space and memory from being freed.
End the interval invalidation when an ordinary notifier fails a non-blocking invalidation, like mn_itree_invalidate() already does when an interval notifier fails. Make that handling clearer in the documentation of mmu_notifier_invalidate_range_start_nonblock().
Fix generated by an LLM and sent by Josef Bacik in private.
--- include/linux/mmu_notifier.h | 3 ++- mm/mmu_notifier.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-)
include/linux/mmu_notifier.h +2 -1
@@ -464,7 +464,8 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)/* * This version of mmu_notifier_invalidate_range_start() avoids blocking, but it * can return an error if a notifier can't proceed without blocking, in which -* case you're not allowed to modify PTEs in the specified range. +* case you're not allowed to modify PTEs in the specified range or call +* mmu_notifier_invalidate_range_end(). * * This is mainly intended for OOM handling. */
mm/mmu_notifier.c +13 -4
@@ -537,16 +537,25 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) {struct mmu_notifier_subscriptions *subscriptions = range->mm->notifier_subscriptions; -int ret; +const bool has_itree = subscriptions->has_itree; +int ret =0 ; -if (subscriptions->has_itree) { +if (has_itree) { ret =mn_itree_invalidate (subscriptions, range);if (ret)return ret; }if (!hlist_empty (&subscriptions->list)) -return mn_hlist_invalidate_range_start (subscriptions, range); -return 0 ; + ret =mn_hlist_invalidate_range_start (subscriptions, range); + +/* +* On error, the non-blocking caller is not allowed to call +* invalidate_range_end(), as in mn_itree_invalidate(). +*/ +if (ret && has_itree && !mmu_notifier_range_blockable (range)) +mn_itree_inv_end (subscriptions); + +return ret; } static void
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1303/2214 blk-iocost: Simplify ioc_rqos_done()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 62c159a03da92121b1b909fd8039028de97885fc ]
Leave out the superfluous "& REQ_OP_MASK" code. The definition of req_op() shows that that code is superfluous:
#define req_op(req) ((req)->cmd_flags & REQ_OP_MASK)
Compile-tested only.
Stable-dep-of: e9804489e27d ("blk-iocost: account flush sequence latency only once")
--- block/blk-iocost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-iocost.c +1 -1
@@ -2808,7 +2808,7 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq)if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns)return ; -switch (req_op (rq) &REQ_OP_MASK ) { +switch (req_op (rq)) {case REQ_OP_READ : pidx =QOS_RLAT ; rw =READ ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1304/2214 blk-iocost: account flush sequence latency only once
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhe Liu <[email protected]>
[ Upstream commit e9804489e27dd6e33aec5511fe3780ff3009f57f ]
A flush sequence with a DATA phase can complete its original request twice. Both completions invoke ioc_rqos_done(), causing the request to contribute two latency samples and adding the same queue wait time twice. This gives such requests disproportionate weight compared to ordinary writes, distorting the device-wide latency and queue wait feedback used to adjust iocost's virtual time rate.
Skip requests marked RQF_FLUSH_SEQ in ioc_rqos_done(). The flag is set when the request enters the flush machinery and is still set when the data phase completes; blk_flush_restore_request() clears it before the final completion, so accounting happens only once, after the whole sequence finishes. The remaining sample covers the request's lifetime through any postflush, and its queue wait time is accumulated only once.
--- block/blk-iocost.c | 3 +++ 1 file changed, 3 insertions(+)
block/blk-iocost.c +3 -0
@@ -2808,6 +2808,9 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq)if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns)return ; +if (unlikely (rq->rq_flags &RQF_FLUSH_SEQ )) +return ; +switch (req_op (rq)) {case REQ_OP_READ : pidx =QOS_RLAT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1305/2214 xfrm: Drop unused argument
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongbin Wang <[email protected]>
[ Upstream commit 0de1978852dff8643a80f20a8f44cef3f16c2db0 ]
Drop unused argument from xfrm_policy_match, __xfrm_policy_eval_candidates and xfrm_policy_eval_candidates. No functional changes intended.
Stable-dep-of: 868f63c8bfaf ("xfrm: retry inexact policy lookup after node reinsertion")
--- net/xfrm/xfrm_policy.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
net/xfrm/xfrm_policy.c +7 -8
@@ -1908,7 +1908,7 @@ EXPORT_SYMBOL(xfrm_policy_walk_done);*/ static int xfrm_policy_match (const struct xfrm_policy *pol,const struct flowi *fl, -u8 type,u16 family,int dir,u32 if_id) +u8 type,u16 family,u32 if_id) {const struct xfrm_selector *sel = &pol->selector;int ret = -ESRCH ;
@@ -2033,7 +2033,7 @@ static struct xfrm_policy * __xfrm_policy_eval_candidates(struct hlist_head *chain, struct xfrm_policy *prefer, const struct flowi *fl, - u8 type, u16 family, int dir, u32 if_id) + u8 type, u16 family, u32 if_id) { u32 priority = prefer ? prefer->priority : ~0u;struct xfrm_policy *pol;
@@ -2047,7 +2047,7 @@ __xfrm_policy_eval_candidates(struct hlist_head *chain,if (pol->priority > priority)break ; - err =xfrm_policy_match (pol, fl, type, family, dir, if_id); + err =xfrm_policy_match (pol, fl, type, family, if_id);if (err) {if (err != -ESRCH )return ERR_PTR (err);
@@ -2072,7 +2072,7 @@ static struct xfrm_policy * xfrm_policy_eval_candidates(struct xfrm_pol_inexact_candidates *cand, struct xfrm_policy *prefer, const struct flowi *fl, - u8 type, u16 family, int dir, u32 if_id) + u8 type, u16 family, u32 if_id) { struct xfrm_policy *tmp;int i;
@@ -2080,8 +2080,7 @@ xfrm_policy_eval_candidates(struct xfrm_pol_inexact_candidates *cand,for (i =0 ; i <ARRAY_SIZE (cand->res); i++) { tmp =__xfrm_policy_eval_candidates (cand->res[i], prefer, - fl, type, family, dir, - if_id); + fl, type, family, if_id);if (!tmp)continue ;
@@ -2120,7 +2119,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, ret =NULL ;hlist_for_each_entry_rcu (pol, chain, bydst) { - err =xfrm_policy_match (pol, fl, type, family, dir, if_id); + err =xfrm_policy_match (pol, fl, type, family, if_id);if (err) {if (err == -ESRCH )continue ;
@@ -2139,7 +2138,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, goto skip_inexact; pol =xfrm_policy_eval_candidates (&cand, ret, fl, type, - family, dir, if_id); + family, if_id);if (pol) { ret = pol;if (IS_ERR (pol))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1306/2214 xfrm: retry inexact policy lookup after node reinsertion
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit 868f63c8bfafa9b827168c9126f85264c39c02ec ]
An inexact policy lookup first records pointers to candidate hlist heads and then traverses the lists. A concurrent policy insertion can merge inexact tree nodes between those operations:
lookup policy insertion
------ ----------------
find inexact candidates
save obsolete hlist head
write_seqcount_begin(&bin->count)
merge inexact tree nodes
hlist_del_rcu(&policy->bydst)
reinsert policy->bydst in survivor
write_seqcount_end(&bin->count) evaluate saved candidate list
miss the moved policy
The merge immediately reinserts the same hlist node into the surviving tree node. RCU keeps the policy alive, but it does not provide a consistent view while its list node is moved. A lookup that selected the obsolete list can observe it empty. A lookup already traversing a moved policy can instead follow the next pointer rewritten by the reinsertion. Either case can return an incorrect IPsec policy result.
The per-bin sequence counter already brackets calls to xfrm_policy_inexact_insert_node(), including node merges. The read side, however, currently validates the counter only while searching an individual rb-tree. A successful search returns without validation, and the later candidate-list traversal is outside that read-side section.
Snapshot the per-bin sequence before discovering candidate heads and
validate it after evaluating all candidate lists. Retry the lookup if
the inexact policy tree changes while it is being searched.
--- net/xfrm/xfrm_policy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/xfrm/xfrm_policy.c +9 -2
@@ -2102,6 +2102,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,struct xfrm_pol_inexact_bin *bin;struct xfrm_policy *pol, *ret;struct hlist_head *chain; +unsigned int inexact_sequence;unsigned int sequence;int err;
@@ -2133,12 +2134,18 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, } } bin =xfrm_policy_inexact_lookup_rcu (net, type, family, dir, if_id); -if (!bin || !xfrm_policy_find_inexact_candidates (&cand, bin, saddr, - daddr)) +if (!bin) + goto skip_inexact; + + inexact_sequence =read_seqcount_begin (&bin->count); +if (!xfrm_policy_find_inexact_candidates (&cand, bin, saddr, daddr)) goto skip_inexact; pol =xfrm_policy_eval_candidates (&cand, ret, fl, type, family, if_id); +if (read_seqcount_retry (&bin->count, inexact_sequence)) + goto retry; +if (pol) { ret = pol;if (IS_ERR (pol))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1307/2214 drm/vc4: hdmi: enable scrambling before the TMDS clock starts
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lucas Tanure <[email protected]>
[ Upstream commit 81383bd290a18f06ccf9b0bfb29e1a3ef73d9357 ]
HDMI 2.0 requires a source to suspend the TMDS clock, write the TMDS_Bit_Clock_Ratio bit in the sink's SCDC registers, wait at least 1 ms and only then resume the clock. vc4 does the opposite: the PHY starts at the new rate first, and the SCDC bits are written tens of milliseconds later, at the very end of the enable sequence, together with the source side scrambler. On disable the bits are cleared while the clock is still running.
Some sinks sample the bit only when the clock appears. One HDMI 2.0 sink we tested then sets up its receiver for a 1/10 clock and never
recovers: a Raspberry Pi 5 at 3840x2160@60 shows no picture, while 1080p60 and 4K30 work and other sources work at 4K60 on the same sink. Writing the bit by hand before enabling the output makes the same mode lock every time.
Enable scrambling, on the sink and in the controller, before the PHY is started, and disable it only after the PHY has been stopped. The SCDC helper already waits the required time after writing the ratio bit.
--- drivers/gpu/drm/vc4/vc4_hdmi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +4 -2
@@ -622,7 +622,6 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,HDMI_WRITE (HDMI_VID_CTL ,HDMI_READ (HDMI_VID_CTL ) & ~VC4_HD_VID_CTL_ENABLE ); -vc4_hdmi_disable_scrambling (encoder); } static void vc4_hdmi_encoder_post_crtc_powerdown(struct drm_encoder *encoder,
@@ -637,6 +636,8 @@ static void vc4_hdmi_encoder_post_crtc_powerdown(struct drm_encoder *encoder,if (vc4_hdmi->variant->phy_disable) vc4_hdmi->variant->phy_disable (vc4_hdmi); +vc4_hdmi_disable_scrambling (encoder); +clk_disable_unprepare (vc4_hdmi->pixel_bvb_clock);clk_disable_unprepare (vc4_hdmi->pixel_clock);
@@ -976,6 +977,8 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder, goto err_disable_pixel_clock; } +vc4_hdmi_enable_scrambling (encoder); +if (vc4_hdmi->variant->phy_init) vc4_hdmi->variant->phy_init (vc4_hdmi, vc4_conn_state);
@@ -1078,7 +1081,6 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, }vc4_hdmi_recenter_fifo (vc4_hdmi); -vc4_hdmi_enable_scrambling (encoder); }static void vc4_hdmi_encoder_enable (struct drm_encoder *encoder)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1308/2214 mm/filemap: dont lose a folio lock wakeup to a signal
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 8ccb6ded6a47b59b4907ed4f8c293cf8122de889 ]
An exclusive waiter in folio_wait_bit_common() can leave the wait loop because of a fatal signal, then be woken by folio_unlock() before finish_wait(). If the waker did not hand over the lock, the waiter returns -EINTR without trying to acquire it.
folio_wake_bit() stops after waking the first exclusive waiter, so this loses the wakeup and can leave other waiters asleep indefinitely on an unlocked folio.
After finish_wait(), let a waiter woken without a lock handoff try once more to acquire the lock. If successful, return success so the caller's eventual unlock wakes the next waiter. Otherwise, the current lock owner will do so.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/filemap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
mm/filemap.c +15 -3
@@ -1407,10 +1407,22 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,* return value based on that state without races. * * Also note that WQ_FLAG_WOKEN is sufficient for a non-exclusive -* waiter, but an exclusive one requires WQ_FLAG_DONE. +* waiter, but an exclusive one must also acquire the bit. */ -if (behavior ==EXCLUSIVE ) -return wait->flags &WQ_FLAG_DONE ?0 : -EINTR ; +if (behavior ==EXCLUSIVE ) { +if (wait->flags &WQ_FLAG_DONE ) +return 0 ; +/* +* We might have just been woken up and the waker will not +* wake up anybody else. If we ignore that now, the remaining +* waiters may not get woken up: take the bit now if it is +* still free. +*/ +if ((wait->flags &WQ_FLAG_WOKEN ) && + !test_and_set_bit (bit_nr, &page->flags)) +return 0 ; +return -EINTR ; + }return wait->flags &WQ_FLAG_WOKEN ?0 : -EINTR ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1309/2214 xfs: mark the inode preallocated for pNFS write layouts past EOF
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 8b8e265991556d99b6d721697f148975a7c68767 ]
xfs_fs_map_blocks() marks the inode XFS_DIFLAG_PREALLOC only when it allocates blocks for a write layout. A write layout past EOF can also hand out allocated blocks, such as speculative preallocation. blockgc then frees them under the layout, and another file may get them.
Mark the inode whenever a write mapping ends past EOF.
--- fs/xfs/xfs_pnfs.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
fs/xfs/xfs_pnfs.c +18 -3
@@ -91,6 +91,7 @@ xfs_fs_map_blocks(int nimaps =1 ;uint lock_flags;int error =0 ; +bool update_inode = false;if (xfs_is_shutdown (mp))return -EIO ;
@@ -157,7 +158,24 @@ xfs_fs_map_blocks( end_fsb - offset_fsb, &imap);if (error) goto out_unlock; + update_inode = true; + }else { +xfs_iunlock (ip, lock_flags); +/* +* Blocks past EOF that were allocated for buffered writes, such +* as speculative preallocation, can be freed by +* xfs_free_eofblocks() without breaking the layout unless the +* inode is marked as preallocated. Mark it before handing them +* out for writing, as for blocks allocated above. +*/ +if (!error && write && !(ip->i_diflags &XFS_DIFLAG_PREALLOC ) && + imap.br_startoff + imap.br_blockcount > +XFS_B_TO_FSB (mp,XFS_ISIZE (ip))) + update_inode = true; + } + +if (update_inode) {/* * Ensure the next transaction is committed synchronously so * that the blocks allocated and handed out to the client are
@@ -168,9 +186,6 @@ xfs_fs_map_blocks( error =xfs_log_force_inode (ip);if (error) goto out_unlock; - - }else { -xfs_iunlock (ip, lock_flags); }xfs_iunlock (ip,XFS_IOLOCK_EXCL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1310/2214 xfs: cap the block count of xfs_iomap_write_direct() at one extent
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 66d1ce09ebd72709f8d739630c39f440445173fd ]
xfs_iomap_write_direct() reserves blocks for the whole count in an unsigned int. For a pNFS layout the client chooses that count, and an RW LAYOUTGET for 16 TiB wraps the reservation and shuts XFS down.
xfs_bmapi_write() maps at most XFS_MAX_BMBT_EXTLEN blocks here, so cap the count at that. nfsd asks again for the rest. The other callers get the same mapping as before.
--- fs/xfs/xfs_iomap.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/xfs/xfs_iomap.c +8 -0
@@ -202,6 +202,14 @@ xfs_iomap_write_direct(ASSERT (count_fsb >0 ); +/* +* xfs_bmapi_write() maps at most MAXEXTLEN blocks in one +* mapping, so don't reserve blocks for more. A pNFS layout range +* comes from a client, and its block count may not even fit the +* 32-bit reservation. The caller maps the rest with a later call. +*/ + count_fsb =min_t (xfs_filblks_t, count_fsb,MAXEXTLEN ); + resaligned =xfs_aligned_fsb_count (offset_fsb, count_fsb,xfs_get_extsz_hint (ip));if (unlikely (XFS_IS_REALTIME_INODE (ip))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1311/2214 selinux: prevent KMSAN warning in selinux_inet_conn_request()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Kanner <[email protected]>
commit 1df83cbf23a27174aee6ea5e52462f03f7e48a10 upstream.
KMSAN reports the following issue:
[ 81.822503] ===================================================== [ 81.823222] BUG: KMSAN: uninit-value in selinux_inet_conn_request+0x2c8/0x4b0 [ 81.823891] selinux_inet_conn_request+0x2c8/0x4b0 [ 81.824385] security_inet_conn_request+0xc0/0x160 [ 81.824886] tcp_v4_route_req+0x30e/0x490 [ 81.825343] tcp_conn_request+0xdc8/0x3400 [ 81.825813] tcp_v4_conn_request+0x134/0x190 [ 81.826292] tcp_rcv_state_process+0x1f4/0x3b40 [ 81.826797] tcp_v4_do_rcv+0x9ca/0xc30 [ 81.827236] tcp_v4_rcv+0x3bf5/0x4180 [ 81.827670] ip_protocol_deliver_rcu+0x822/0x1230 [ 81.828174] ip_local_deliver_finish+0x259/0x370 [ 81.828667] ip_local_deliver+0x1c0/0x450 [ 81.829105] ip_sublist_rcv+0xdc1/0xf50 [ 81.829534] ip_list_rcv+0x72e/0x790 [ 81.829941] __netif_receive_skb_list_core+0x10d5/0x1180 [ 81.830499] netif_receive_skb_list_internal+0xc41/0x1190 [ 81.831064] napi_complete_done+0x2c4/0x8b0 [ 81.831532] e1000_clean+0x12bf/0x4d90 [ 81.831983] __napi_poll+0xa6/0x760 [ 81.832391] net_rx_action+0x84c/0x1550 [ 81.832831] __do_softirq+0x272/0xa6c [ 81.833239] __irq_exit_rcu+0xb7/0x1a0 [ 81.833654] irq_exit_rcu+0x17/0x40 [ 81.834044] common_interrupt+0x8d/0xa0 [ 81.834494] asm_common_interrupt+0x2b/0x40 [ 81.834949] default_idle+0x17/0x20 [ 81.835356] arch_cpu_idle+0xd/0x20 [ 81.835766] default_idle_call+0x43/0x70 [ 81.836210] do_idle+0x258/0x800 [ 81.836581] cpu_startup_entry+0x26/0x30 [ 81.837002] __pfx_ap_starting+0x0/0x10 [ 81.837444] secondary_startup_64_no_verify+0x17a/0x17b [ 81.837979] [ 81.838166] Local variable nlbl_type.i created at: [ 81.838596] selinux_inet_conn_request+0xe3/0x4b0 [ 81.839078] security_inet_conn_request+0xc0/0x160
KMSAN warning is reproducible with:
* netlabel_mgmt_protocount is 0 (e.g. netlbl_enabled() returns 0)
* CONFIG_SECURITY_NETWORK_XFRM may be set or not
* CONFIG_KMSAN=y
* ssh USER@HOSTNAME /bin/date
selinux_skb_peerlbl_sid() will call selinux_xfrm_skb_sid(), then fall to selinux_netlbl_skbuff_getsid() which will not initialize nlbl_type, but it will be passed to:
err = security_net_peersid_resolve(nlbl_sid,
nlbl_type, xfrm_sid, sid);
and checked by KMSAN, although it will not be used inside security_net_peersid_resolve() (at least now), since this function will check either (xfrm_sid == SECSID_NULL) or (nlbl_sid == SECSID_NULL) first and return before using uninitialized nlbl_type.
--- security/selinux/netlabel.c | 1 + 1 file changed, 1 insertion(+)
security/selinux/netlabel.c +1 -0
@@ -195,6 +195,7 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb,struct netlbl_lsm_secattr secattr;if (!netlbl_enabled ()) { + *type =NETLBL_NLTYPE_NONE ; *sid =SECSID_NULL ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1312/2214 ovl: inherit FMODE_NONOTIFY when reading directory layers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 9ff338af0e002fe217cfa16b1289b76f6b21fc72 ]
Listing a merged or impure overlay directory opens the real layer directories from ovl_dir_read(), when the readdir cache is filled. Those opens use plain ovl_path_open(), so when the directory fd is one that fanotify created for a permission event, they can still raise FS_OPEN_PERM. A listener that also marks the backing filesystem and calls getdents() on the event fd before answering then deadlocks the same way as with the directory open fixed by the previous commit.
Store the overlay user file in struct ovl_readdir_data and pass it to ovl_path_open_realfile() from ovl_dir_read(), for both the merged and the impure cache. Internal readers such as ovl_check_empty_dir() and the mount-time workdir cleanup still pass no user file.
A note about severity and real world impact: The FAN_OPEN_PERM event is traditionally used by anti-malware protection agents and security/audit agents. The scope that is often used in those use cases is FAN_MARK_MOUNT and agents typically monitor multiple mounts in a mount namespace. FAN_OPEN_PERM from directory open requires user opt-in with FAN_ONDIR. It is often not the case that anti-malware agents monitor open of directories. Security/audit engines are more likely to opt-into FAN_OPEN_PERM on directories, but are less likely to list the content of a directory within the scope of FAN_OPEN_PERM event, so the real world impact of this bug is likely not significant.
--- fs/overlayfs/readdir.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
fs/overlayfs/readdir.c +20 -11
@@ -37,6 +37,7 @@ struct ovl_dir_cache {struct ovl_readdir_data {struct dir_context ctx; +const struct file *user_file;struct dentry *dentry;bool is_lowest;struct rb_root *root;
@@ -295,9 +296,13 @@ static inline int ovl_dir_read(struct path *realpath, struct ovl_readdir_data *rdd) {struct file *realfile; +int flags =O_RDONLY |O_LARGEFILE ;int err; - realfile =ovl_path_open (realpath,O_RDONLY |O_LARGEFILE ); +if (rdd->user_file && (rdd->user_file->f_mode &FMODE_NONOTIFY )) + flags |= __FMODE_NONOTIFY; + + realfile =ovl_path_open (realpath, flags);if (IS_ERR (realfile))return PTR_ERR (realfile);
@@ -341,12 +346,13 @@ static void ovl_dir_reset(struct file *file) }static int ovl_dir_read_merged (struct dentry *dentry,struct list_head *list, -struct rb_root *root) +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_merge, + .user_file = user_file, .dentry = dentry, .list = list, .root = root,
@@ -390,9 +396,10 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos) od->cursor = p; } -static struct ovl_dir_cache *ovl_cache_get (struct dentry *dentry) +static struct ovl_dir_cache *ovl_dir_cache_get (struct file *file) {int res; +struct dentry *dentry = file->f_path.dentry;struct ovl_dir_cache *cache; cache =ovl_dir_cache (d_inode (dentry));
@@ -411,7 +418,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)INIT_LIST_HEAD (&cache->entries); cache->root =RB_ROOT ; - res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root); + res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -547,14 +554,15 @@ static int ovl_fill_plain(struct dir_context *ctx, const char *name,return 0 ; } -static int ovl_dir_read_impure (struct path *path,struct list_head *list, -struct rb_root *root) +static int ovl_dir_read_impure (struct path *path,struct list_head *list, +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;struct ovl_cache_entry *p, *n;struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_plain, + .user_file = user_file, .list = list, .root = root, };
@@ -592,9 +600,10 @@ static int ovl_dir_read_impure(struct path *path, struct list_head *list,return 0 ; } -static struct ovl_dir_cache *ovl_cache_get_impure (struct path *path) +static struct ovl_dir_cache *ovl_cache_get_impure (struct file *file) {int res; +struct path *path = &file->f_path;struct dentry *dentry = path->dentry;struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct ovl_dir_cache *cache;
@@ -611,7 +620,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(struct path *path)if (!cache)return ERR_PTR (-ENOMEM ); - res =ovl_dir_read_impure (path, &cache->entries, &cache->root); + res =ovl_dir_read_impure (path, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -726,7 +735,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)dput (parent);if (ovl_is_impure_dir (file)) { - rdt.cache =ovl_cache_get_impure (&file->f_path); + rdt.cache =ovl_cache_get_impure (file);if (IS_ERR (rdt.cache))return PTR_ERR (rdt.cache); }
@@ -773,7 +782,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)if (!od->cache) {struct ovl_dir_cache *cache; - cache =ovl_cache_get (dentry); + cache =ovl_dir_cache_get (file); err =PTR_ERR (cache);if (IS_ERR (cache)) goto out;
@@ -987,7 +996,7 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)const struct cred *old_cred; old_cred =ovl_override_creds (dentry->d_sb); - err =ovl_dir_read_merged (dentry, list, &root); + err =ovl_dir_read_merged (dentry, list, &root,NULL );revert_creds (old_cred);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1313/2214 comedi: addi_apci_3xxx: fix subdevice count underallocation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Zi <[email protected]>
[ Upstream commit 3de5aa458dede472a253266d02902bd95af8e849 ]
In apci3xxx_auto_attach(), the number of subdevices is computed with
n_subdevices = (board->ai_n_chan ? 0 : 1) + board->has_ao + ...
The ternary is inverted: when the board has analog input channels (ai_n_chan != 0), it counts 0 instead of 1, so the AI subdevice that is actually created is not accounted for. As a result comedi_alloc_subdevices() allocates one entry too few, and the later subdevice initialization (notably the TTL Digital I/O subdevice, which is populated last) writes past the end of the allocated array, causing a slab out-of-bounds write.
Flip the ternary to count 1 when ai_n_chan is non-zero and 0 otherwise, matching the subdevice creation order in the function.
--- drivers/comedi/drivers/addi_apci_3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/addi_apci_3xxx.c +1 -1
@@ -788,7 +788,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - n_subdevices = (board->ai_n_chan ?0 :1 ) + board->has_ao + + n_subdevices = (board->ai_n_chan ?1 :0 ) + board->has_ao + board->has_dig_in + board->has_dig_out + board->has_ttl_io; ret =comedi_alloc_subdevices (dev, n_subdevices);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1314/2214 SUNRPC: Copy the deferred RPC Call from the head buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit 2192a56b0686599358909c3e12e9a366f5b5d452 upstream.
svc_defer() snapshots the RPC Call for replay once a pending cache upcall resolves. It copies the Call starting (rq_arg.len - head[0].iov_len) bytes before head[0].iov_base, a back-up that once covered a transport header. No transport has had one since commit 983084b2672c ("SUNRPC: Remove svc_rqst::rq_xprt_hlen"), so the two lengths are meant to be equal.
An RPCSEC_GSS Call breaks that assumption. Unwrapping the integrity service truncates rq_arg.len by the length of the trailing checksum, and unwrapping the privacy service leaves rq_arg.len short by an amount the client sets with trailing bytes after the wrap token. Neither adjusts head[0].iov_len. Both lengths are size_t, so the subtraction underflows and the copy starts past head[0].iov_base. Every deferred integrity Call replays a shifted snapshot.
A deferred replay skips GSS verification, so a shifted snapshot runs as an authenticated Call. With the privacy service the offset is client-chosen. A forged Call placed in that window, naming another user's GSS context handle, runs under that identity.
Copy the Call from head[0].iov_base. Refuse to defer a Call whose length runs past the head buffer, so the copy cannot read out of bounds.
[doebel: 5.15 backport. In this tree the RPC Call header is parsed
with svc_getnl(), which advances rq_arg.head[0].iov_base while rq_arg.len keeps measuring from the start of the receive buffer, so len > head[0].iov_len for every Call at svc_defer() time and the upstream guard and copy-from-iov_base cannot apply; keep the skip-based snapshot that svc_deferred_recv() expects. A GSS privacy unwrap breaks the len - iov_len invariant by resetting rq_arg.len (gss_unwrap_kerberos_v2()); refuse to defer after a GSS integrity/privacy unwrap (rq_auth_slack != 0) or when len < head[0].iov_len.]
--- net/sunrpc/svc_xprt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/sunrpc/svc_xprt.c +14 -0
@@ -1224,6 +1224,20 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req) }else {size_t skip;size_t size; + +/* +* A GSS integrity/privacy unwrap can reset rq_arg.len so +* it no longer measures from the start of the receive +* buffer (see gss_unwrap_kerberos_v2()). In that state +* len - iov_len does not locate the buffer start, and a +* snapshot taken here would be replayed without GSS +* verification. Refuse to defer; the caller fails the +* request and the client retries. +*/ +if (rqstp->rq_auth_slack || + rqstp->rq_arg.len < rqstp->rq_arg.head[0 ].iov_len) +return NULL ; +/* FIXME maybe discard if size too large */ size =sizeof (struct svc_deferred_req ) + rqstp->rq_arg.len; dr =kmalloc (size,GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1315/2214 comedi: dt2811: fix shift-out-of-bounds in IRQ check
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit 471ce96a9c415b8a67bd5081ac2089a458cacc2f ]
The IRQ number passed via comedi_devconfig->options[1] is a signed int that comes from userspace. The check it->options[1] <= 7 does not reject negative values, so a negative IRQ number reaches BIT(it->options[1]), which is undefined behavior and triggers a UBSAN shift-out-of-bounds warning:
UBSAN: shift-out-of-bounds in drivers/comedi/drivers/dt2811.c:570:31 shift exponent -251 is negative
Add an explicit lower bound check (it->options[1] >= 0) so that only valid IRQ numbers 0..7 are accepted before the shift.
--- drivers/comedi/drivers/dt2811.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/dt2811.c +1 -1
@@ -567,7 +567,7 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)dt2811_reset (dev);/* IRQ's 2,3,5,7 are valid for async command support */ -if (it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { +if (it->options[1 ] >=0 && it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { ret =request_irq (it->options[1 ], dt2811_interrupt,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1316/2214 drm/amdgpu: parse CS IBs at the BO offset their VA mapping starts at
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 63a59637517682a920f86da1a189a3e639dd4fb3 ]
For rings which parse or patch the IBs on the CPU, like JPEG and VCN, the CS looks the IB up through its VA mapping and maps the BO, but ignores the offset in the BO the mapping starts at. It then parses other data than the GPU executes. On navi31, an IB of JPEG NOPs in the second page of a BO, mapped with offset_in_bo 4096, is parsed from the zeros in the first page and rejected:
amdgpu 0000:03:00.0: Invalid packet [0x00000000]!
while the same IB submitted through a mapping of the whole BO works.
Add the mapping offset when locating the IB in the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -773,7 +773,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p) } offset = m->start *AMDGPU_GPU_PAGE_SIZE ; - kptr += va_start - offset; + kptr += va_start - offset + m->offset;if (ring->funcs->parse_cs) {memcpy (ib->ptr, kptr, chunk_ib->ib_bytes);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1317/2214 ocfs2: validate move extents against a stable EOF
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 84db6619cb702c37cf848b450c21b9c9706b0775 ]
The move-extents range must be bounded by the inode size used for extent movement. ocfs2_ioctl_move_extents() checks and clamps the request before taking the local inode and cluster locks in ocfs2_move_extents(). It also uses separate i_size_read() calls for the range check and subtraction.
A concurrent truncate can invalidate the first check and make the later unsigned subtraction underflow:
Move-extents ioctl Truncate
------------------ --------
check me_start <= i_size
take inode and cluster locks shrink EOF below me_start release locks
compare me_start + me_len with EOF
set me_len = EOF - me_start
[unsigned underflow]
acquire inode and cluster locks
select extents using the bad range
A truncate after clamping can also leave the range extending beyond EOF. Conversely, the cached size may be smaller than the size refreshed when the cluster inode lock is acquired. Early validation can then reject a valid start or permanently shorten the requested length and threshold. The me_start + me_len comparison can also wrap for a large input length.
Validate and adjust the original request once, after inode_lock(), the exclusive rw lock and ocfs2_inode_lock() have stabilized and refreshed the size. Read EOF once, reject a start beyond it, and bound the length by EOF minus start. Normalize the threshold using the same EOF snapshot. This keeps zero as the default-threshold sentinel until validation uses the size that will govern extent movement.
Move goal validation after range adjustment as well. Its allocation-group capacity check uses me_len and must see the EOF-clamped length. Both validation failures use the existing inode-lock unwind path before any extent movement or transaction starts.
Range errors now reach the ioctl's normal copyout path, as goal errors already did. Unlike the old early rejection, a failed copyout can therefore override -EINVAL with -EFAULT.
--- fs/ocfs2/move_extents.c | 62 ++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
fs/ocfs2/move_extents.c +31 -31
@@ -906,8 +906,10 @@ static int __ocfs2_move_extents_range(struct buffer_head *di_bh,static int ocfs2_move_extents (struct ocfs2_move_extents_context *context) {int status; +u64 i_size;handle_t *handle;struct inode *inode = context->inode; +struct ocfs2_move_extents *range = context->range;struct ocfs2_dinode *di;struct buffer_head *di_bh =NULL ;struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);
@@ -932,6 +934,35 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context) goto out_rw_unlock; } + i_size =i_size_read (inode); +if (range->me_start > i_size) { + status = -EINVAL ; +mlog_errno (status); + goto out_inode_unlock; + } + +if (range->me_len > i_size - range->me_start) + range->me_len = i_size - range->me_start; + +/* +* The default threshold for defragmentation is 1 MiB, which +* matches the maximum OCFS2 cluster size. +*/ +if (!range->me_threshold) + range->me_threshold =1024 *1024 ; + +if (range->me_threshold > i_size) + range->me_threshold = i_size; + +/* The goal check depends on the adjusted range length. */ +if (!context->auto_defrag) { + status =ocfs2_validate_and_adjust_move_goal (inode, context->range); +if (status) { +mlog_errno (status); + goto out_inode_unlock; + } + } +/* * rememer ip_xattr_sem also needs to be held if necessary */
@@ -1024,49 +1055,18 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) goto out_free; } -if (range.me_start >i_size_read (inode)) { - status = -EINVAL ; - goto out_free; - } - -if (range.me_start + range.me_len >i_size_read (inode)) - range.me_len =i_size_read (inode) - range.me_start; - context->range = ⦥ -/* -* ok, the default theshold for the defragmentation -* is 1M, since our maximum clustersize was 1M also. -* any thought? -*/ -if (!range.me_threshold) - range.me_threshold =1024 *1024 ; - -if (range.me_threshold >i_size_read (inode)) - range.me_threshold =i_size_read (inode); -if (range.me_flags &OCFS2_MOVE_EXT_FL_AUTO_DEFRAG ) { context->auto_defrag =1 ;if (range.me_flags &OCFS2_MOVE_EXT_FL_PART_DEFRAG ) context->partial =1 ; - }else { -/* -* first best-effort attempt to validate and adjust the goal -* (physical address in block), while it can't guarantee later -* operation can succeed all the time since global_bitmap may -* change a bit over time. -*/ - - status =ocfs2_validate_and_adjust_move_goal (inode, &range); -if (status) - goto out_copy; } status =ocfs2_move_extents (context);if (status)mlog_errno (status); -out_copy:/* * movement/defragmentation may end up being partially completed, * that's the reason why we need to return userspace the finished
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1318/2214 xfs: add a flag to convert unwritten extents without allocating blocks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit f3ca3498dfe624f9b604c934263538a3acd55af5 ]
xfs_bmapi_write() with XFS_BMAPI_CONVERT also allocates blocks for holes and delalloc extents in the range. Add XFS_BMAPI_CONVERT_ONLY for callers that may only convert already allocated blocks. It stops at a hole or delalloc extent, and returns -ENOSR if it stops before mapping anything.
Marked for stable because "xfs: refuse a pNFS LAYOUTCOMMIT of a range without blocks" needs it.
--- fs/xfs/libxfs/xfs_bmap.c | 12 ++++++++++++ fs/xfs/libxfs/xfs_bmap.h | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_bmap.c +12 -0
@@ -4355,6 +4355,8 @@ xfs_bmapi_finish(* extent state if necessary. Details behaviour is controlled by the flags * parameter. Only allocates blocks from a single allocation group, to avoid * locking problems. +* With XFS_BMAPI_CONVERT_ONLY, it stops at a hole or a delalloc extent instead +* of allocating blocks, and returns -ENOSR if it stops before mapping anything. */ int xfs_bmapi_write(
@@ -4414,6 +4416,8 @@ xfs_bmapi_write(*/ ASSERT ((flags & (XFS_BMAPI_PREALLOC |XFS_BMAPI_ZERO )) != (XFS_BMAPI_PREALLOC |XFS_BMAPI_ZERO )); +ASSERT (!(flags &XFS_BMAPI_CONVERT_ONLY ) || + (flags &XFS_BMAPI_CONVERT ));if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) {
@@ -4461,6 +4465,9 @@ xfs_bmapi_write(* that we found, if any. */ if (need_alloc || wasdelay) { +if (flags &XFS_BMAPI_CONVERT_ONLY ) +break ; + bma.eof = eof; bma.conv = !!(flags &XFS_BMAPI_CONVERT ); bma.wasdel = wasdelay;
@@ -4535,6 +4542,11 @@ xfs_bmapi_write(xfs_bmapi_finish (&bma, whichfork,0 );xfs_bmap_validate_ret (orig_bno, orig_len, orig_flags, orig_mval, orig_nmap, *nmap); + +if (!n && (flags &XFS_BMAPI_CONVERT_ONLY )) { +ASSERT (bma.nallocs ==0 ); +return -ENOSR ; + }return 0 ; error0:xfs_bmapi_finish (&bma, whichfork, error);
fs/xfs/libxfs/xfs_bmap.h +9 -1
@@ -101,6 +101,13 @@ struct xfs_extent_free_item/* Do not update the rmap btree. Used for reconstructing bmbt from rmapbt. */ #define XFS_BMAPI_NORMAP 0x2000 +/* +* Use with XFS_BMAPI_CONVERT to convert unwritten extents without allocating +* blocks. Stop at a hole or a delalloc extent: return the mappings found so +* far, or -ENOSR if there are none. +*/ +#define XFS_BMAPI_CONVERT_ONLY 0x4000 +#define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \ { XFS_BMAPI_METADATA, "METADATA" }, \
@@ -112,7 +119,8 @@ struct xfs_extent_free_item { XFS_BMAPI_REMAP, "REMAP" }, \ { XFS_BMAPI_COWFORK, "COWFORK" }, \ { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ - { XFS_BMAPI_NORMAP, "NORMAP" } + { XFS_BMAPI_NORMAP, "NORMAP" }, \ + { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" } static inline int xfs_bmapi_aflag(int w)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1319/2214 udf: dont use eloc after the end of the unallocated space table
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 94401199df90e1c2a50c6e4b73618ac5a4ba83ba ]
When udf_next_aext() returns 0, its eloc, elen and etype outputs hold no defined value. Two walks of the unallocated space table still use eloc after the walk has reached the end of the table.
udf_table_prealloc_blocks() looks for a free extent starting at first_block and decides whether it found one by comparing eloc with first_block after the walk. If the table's list ends in a continuation descriptor that leads to an empty allocation extent, eloc is then the block of that allocation extent, which is in use, and if that is first_block, the block is handed out as preallocation. Once udf_discard_prealloc() no longer frees the wrong block, this is what still makes fsx in generic/091 and generic/263 read back bad data on a table, in about one run in four. Only take the extent if the walk stopped at it.
When udf_table_free_blocks() cannot merge the freed blocks into an existing extent, it appends a new one and sets only its block number, so the partition reference comes from whatever eloc held after the walk, and with long allocation descriptors it is written to disk. For a table without extents, eloc was never set. Take the partition reference from the freed blocks instead. Short allocation descriptors do not store the partition reference, which is why this half remains a latent long-descriptor fix rather than a reproduced failure.
--- fs/udf/balloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/udf/balloc.c +2 -1
@@ -473,6 +473,7 @@ static void udf_table_free_blocks(struct super_block *sb,int adsize; + eloc.partitionReferenceNum = bloc->partitionReferenceNum; eloc.logicalBlockNum = start; elen =EXT_RECORDED_ALLOCATED | (count << sb->s_blocksize_bits);
@@ -545,7 +546,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb, ;/* empty loop body */ } -if (first_block == eloc.logicalBlockNum) { +if (etype !=-1 && first_block == eloc.logicalBlockNum) { epos.offset -= adsize; alloc_count = (elen >> sb->s_blocksize_bits);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1320/2214 drm/amdgpu: publish IH enabled before PSP programs IH_RB_CNTL
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Milan Milicevic <[email protected]>
[ Upstream commit 9d550dd1a3b4b96da49f3560a84b5c2413a88cd3 ]
On SR-IOV, programming IH_RB_CNTL through PSP is slow enough for the first MSI to arrive before ih->enabled is set. amdgpu_ih_process() then drops the interrupt, rptr stays at 0, and RPTR_REARM never generates another edge, so every ring hits the fence fallback timer.
Set ih->enabled before psp_reg_program() on the indirect IH path for Navi10 and IH v6.0, and clear it if programming fails.
--- drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +12 -1
@@ -194,8 +194,19 @@ static int navi10_ih_toggle_ring_interrupts(struct amdgpu_device *adev, tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,ENABLE_INTR , (enable ?1 :0 ));if (amdgpu_sriov_vf (adev) &&amdgpu_sriov_reg_indirect_ih (adev)) { -if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) +/* +* PSP programming of IH_RB_CNTL is slow enough for MSI to +* arrive before this call returns. Publish ih->enabled first +* so amdgpu_ih_process() consumes that IV and rearms. +*/ +if (enable) { + ih->enabled = true; +smp_wmb (); + } +if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) { + ih->enabled = false;return -ETIMEDOUT ; + } }else {WREG32 (ih_regs->ih_rb_cntl, tmp); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1321/2214 KVM: x86: Unconditionally reset MMU context when emulating INIT
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit c7c288d178cb0b78d3464a616b16b1aa0b316049 ]
Force an MMU reset when emulating an INIT even if paging was already disabled, as the MMU page role includes guest_mode (L2), i.e. an INIT while L2 is running with CR0.PG=0 will result in KVM running L1 with a stale MMU context.
Alternatively, the reset could be scoped strictly to paging being enabled or L2 being active, but SMM is also encoded in the page role. Even though it _should_ be impossible for the vCPU to be INIT'd while SMM is active, there's zero value in not handling SMM. At that point, the only scenario where KVM _doesn't_ need to reset the MMU context is on an INIT with the vCPU running in Real Mode or Unpaged Protect Mode, and while INIT in those modes is somewhat common, it's far from a hot path and re-initializing the MMU is not expensive, especially when the role isn't changing (KVM elides most of the re-configuration in that case).
Note, like the Fixes commit, this bug only affects nested SVM as INIT is an unconditional intercept on VMX, i.e. it's impossible to emulate INIT while L2 is active.
Temporarily keep the guest TLB flush when CR0.PG is being cleared even though it is fully redundant with the flush that is emitted on all INIT events (KVM itself only does RESET when a vCPU is being created, i.e. when CR0.PG must be '0').
Message-ID: <[email protected]>
--- arch/x86/kvm/x86.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
arch/x86/kvm/x86.c +12 -8
@@ -11374,15 +11374,19 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)static_call (kvm_x86_update_exception_bitmap)(vcpu);/* -* Reset the MMU context if paging was enabled prior to INIT (which is -* implied if CR0.PG=1 as CR0 will be '0' prior to RESET). Unlike the -* standard CR0/CR4/EFER modification paths, only CR0.PG needs to be -* checked because it is unconditionally cleared on INIT and all other -* paging related bits are ignored if paging is disabled, i.e. CR0.WP, -* CR4, and EFER changes are all irrelevant if CR0.PG was '0'. +* Unconditionally reset the MMU, even though super strictly speaking, +* a MMU reset is only necessary if and only one of the page role bits +* is changing. All of the CR0/CR4/EFER bits effectively get covered +* by checking CR0.PG=1, as CR0.WP and the paging-related bits in CR4 +* and EFER are irrelevant if CR0.PG was '0'. Subtly, if the vCPU was +* in guest mode (L2) or SMM (although emulating INIT in SMM _should_ +* be impossible), an MMU reset is also necessary as "guest mode" and +* "smm" are both encoded in the shadow page role. As a result, the +* only scenarios where an MMU reset is *not* needed is if the vCPU is +* in Real Mode or Unpaged Protected Mode, and micro-optimizing those +* paths are not worth the risk of running with a stale MMU context. */ -if (old_cr0 &X86_CR0_PG ) -kvm_mmu_reset_context (vcpu); +kvm_mmu_reset_context (vcpu);/* * Intel's SDM states that all TLB entries are flushed on INIT. AMD's
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1322/2214 sign-file,extract-cert: move common SSL helper functions to a header
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Stancek <[email protected]>
commit 300e6d4116f956b035281ec94297dc4dc8d4e1d3 upstream.
Couple error handling helpers are repeated in both tools, so move them to a common header.
--- MAINTAINERS | 1 + scripts/extract-cert.c | 37 ++----------------------------------- scripts/sign-file.c | 37 ++----------------------------------- scripts/ssl-common.h | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 70 deletions(-)
MAINTAINERS +1 -0
@@ -4347,6 +4347,7 @@ F: Documentation/admin-guide/module-sign F: certs/ F: scripts/extract-cert.c F: scripts/sign-file.c +F: scripts/ssl-common.h CFAG12864B LCD DRIVER M: Miguel Ojeda <[email protected]>
scripts/extract-cert.c +2 -35
@@ -23,6 +23,8 @@#include <openssl/err.h> #include <openssl/engine.h> +#include "ssl-common.h" +/* * OpenSSL 3.0 deprecates the OpenSSL's ENGINE API. *
@@ -40,41 +42,6 @@ void format(void)exit (2 ); } -static void display_openssl_errors (int l) -{ -const char *file; -char buf[120 ]; -int e, line; - -if (ERR_peek_error () ==0 ) -return ; -fprintf (stderr,"At main.c:%d:\n" , l); - -while ((e =ERR_get_error_line (&file, &line))) { -ERR_error_string (e, buf); -fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); - } -} - -static void drain_openssl_errors (void ) -{ -const char *file; -int line; - -if (ERR_peek_error () ==0 ) -return ; -while (ERR_get_error_line (&file, &line)) {} -} - -#define ERR (cond, fmt, ...) \ - do { \ - bool __cond = (cond); \ - display_openssl_errors(__LINE__); \ - if (__cond) { \ - err(1, fmt, ## __VA_ARGS__); \ - } \ - } while(0) -static const char *key_pass;static BIO *wb;static char *cert_dst;
scripts/sign-file.c +2 -35
@@ -29,6 +29,8 @@#include <openssl/err.h> #include <openssl/engine.h> +#include "ssl-common.h" +/* * OpenSSL 3.0 deprecates the OpenSSL's ENGINE API. *
@@ -83,41 +85,6 @@ void format(void)exit (2 ); } -static void display_openssl_errors (int l) -{ -const char *file; -char buf[120 ]; -int e, line; - -if (ERR_peek_error () ==0 ) -return ; -fprintf (stderr,"At main.c:%d:\n" , l); - -while ((e =ERR_get_error_line (&file, &line))) { -ERR_error_string (e, buf); -fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); - } -} - -static void drain_openssl_errors (void ) -{ -const char *file; -int line; - -if (ERR_peek_error () ==0 ) -return ; -while (ERR_get_error_line (&file, &line)) {} -} - -#define ERR (cond, fmt, ...) \ - do { \ - bool __cond = (cond); \ - display_openssl_errors(__LINE__); \ - if (__cond) { \ - err(1, fmt, ## __VA_ARGS__); \ - } \ - } while(0) -static const char *key_pass;static int pem_pw_cb (char *buf,int len,int w,void *v)
scripts/ssl-common.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* +* SSL helper functions shared by sign-file and extract-cert. +*/ + +static void display_openssl_errors (int l) +{ +const char *file; +char buf[120 ]; +int e, line; + +if (ERR_peek_error () ==0 ) +return ; +fprintf (stderr,"At main.c:%d:\n" , l); + +while ((e =ERR_get_error_line (&file, &line))) { +ERR_error_string (e, buf); +fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); + } +} + +static void drain_openssl_errors (void ) +{ +const char *file; +int line; + +if (ERR_peek_error () ==0 ) +return ; +while (ERR_get_error_line (&file, &line)) {} +} + +#define ERR (cond, fmt, ...) \ + do { \ + bool __cond = (cond); \ + display_openssl_errors(__LINE__); \ + if (__cond) { \ + errx(1, fmt, ## __VA_ARGS__); \ + } \ + } while (0)
Greg Kroah-Hartman
maintainerPATCH 1323/2214 sign-file,extract-cert: avoid using deprecated ERR_get_error_line()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Stancek <[email protected]>
commit 467d60eddf55588add232feda325da7215ddaf30 upstream.
ERR_get_error_line() is deprecated since OpenSSL 3.0.
Use ERR_peek_error_line() instead, and combine display_openssl_errors() and drain_openssl_errors() to a single function where parameter decides if it should consume errors silently.
--- scripts/extract-cert.c | 4 ++-- scripts/sign-file.c | 6 +++--- scripts/ssl-common.h | 23 ++++++++--------------- 3 files changed, 13 insertions(+), 20 deletions(-)
scripts/extract-cert.c +2 -2
@@ -96,11 +96,11 @@ int main(int argc, char **argv) parms.cert =NULL ;ENGINE_load_builtin_engines (); -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 ); e =ENGINE_by_id ("pkcs11" );ERR (!e,"Load PKCS#11 ENGINE" );if (ENGINE_init (e)) -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 );else ERR (1 ,"ENGINE_init" );if (key_pass)
scripts/sign-file.c +3 -3
@@ -114,11 +114,11 @@ static EVP_PKEY *read_private_key(constENGINE *e;ENGINE_load_builtin_engines (); -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 ); e =ENGINE_by_id ("pkcs11" );ERR (!e,"Load PKCS#11 ENGINE" );if (ENGINE_init (e)) -drain_openssl_errors (); +drain_openssl_errors (__LINE__,1 );else ERR (1 ,"ENGINE_init" );if (key_pass)
@@ -273,7 +273,7 @@ int main(int argc, char **argv)/* Digest the module data. */ OpenSSL_add_all_digests (); -display_openssl_errors (__LINE__); +drain_openssl_errors (__LINE__,0 ); digest_algo =EVP_get_digestbyname (hash_algo);ERR (!digest_algo,"EVP_get_digestbyname" );
scripts/ssl-common.h +8 -15
@@ -3,7 +3,7 @@* SSL helper functions shared by sign-file and extract-cert. */ -static void display_openssl_errors (int l) +static void drain_openssl_errors (int l,int silent) {const char *file;char buf[120 ];
@@ -11,28 +11,21 @@ static void display_openssl_errors(int lif (ERR_peek_error () ==0 )return ; -fprintf (stderr,"At main.c:%d:\n" , l); +if (!silent) +fprintf (stderr,"At main.c:%d:\n" , l); -while ((e =ERR_get_error_line (&file, &line))) { +while ((e =ERR_peek_error_line (&file, &line))) {ERR_error_string (e, buf); -fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); +if (!silent) +fprintf (stderr,"- SSL %s: %s:%d\n" , buf, file, line); +ERR_get_error (); } } -static void drain_openssl_errors (void ) -{ -const char *file; -int line; - -if (ERR_peek_error () ==0 ) -return ; -while (ERR_get_error_line (&file, &line)) {} -} -#define ERR (cond, fmt, ...) \ do { \ bool __cond = (cond); \ - display_openssl_errors(__LINE__); \ + drain_openssl_errors(__LINE__, 0); \ if (__cond) { \ errx(1, fmt, ## __VA_ARGS__); \ } \
Greg Kroah-Hartman
maintainerPATCH 1324/2214 sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Stancek <[email protected]>
commit 558bdc45dfb2669e1741384a0c80be9c82fa052c upstream.
ENGINE API has been deprecated since OpenSSL version 3.0 [1]. Distros have started dropping support from headers and in future it will likely disappear also from library.
It has been superseded by the PROVIDER API, so use it instead for OPENSSL MAJOR >= 3.
[1] https://github.com/openssl/openssl/blob/master/README-ENGINES.md
[jarkko: fixed up alignment issues reported by checkpatch.pl --strict]
--- scripts/extract-cert.c | 103 ++++++++++++++++++++++++++++++++++--------------- scripts/sign-file.c | 95 +++++++++++++++++++++++++++++++-------------- 2 files changed, 139 insertions(+), 59 deletions(-)
scripts/extract-cert.c +73 -30
@@ -21,17 +21,18 @@#include <openssl/bio.h> #include <openssl/pem.h> #include <openssl/err.h> -#include <openssl/engine.h> - +#if OPENSSL_VERSION_MAJOR >=3 +# define USE_PKCS11_PROVIDER +# include <openssl/provider.h> +# include <openssl/store.h> +#else +# if !defined(OPENSSL_NO_ENGINE ) && !defined(OPENSSL_NO_DEPRECATED_3_0 ) +# define USE_PKCS11_ENGINE +# include <openssl/engine.h> +# endif +#endif #include "ssl-common.h" -/* -* OpenSSL 3.0 deprecates the OpenSSL's ENGINE API. -* -* Remove this if/when that API is no longer used -*/ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#define PKEY_ID_PKCS7 2 static __attribute__((noreturn))
@@ -61,6 +62,66 @@ static void write_cert(X509 *x509)fprintf (stderr,"Extracted cert: %s\n" , buf); } +static X509 *load_cert_pkcs11 (const char *cert_src) +{ +X509 *cert =NULL ; +#ifdef USE_PKCS11_PROVIDER +OSSL_STORE_CTX *store; + +if (!OSSL_PROVIDER_try_load (NULL ,"pkcs11" , true)) +ERR (1 ,"OSSL_PROVIDER_try_load(pkcs11)" ); +if (!OSSL_PROVIDER_try_load (NULL ,"default" , true)) +ERR (1 ,"OSSL_PROVIDER_try_load(default)" ); + + store =OSSL_STORE_open (cert_src,NULL ,NULL ,NULL ,NULL ); +ERR (!store,"OSSL_STORE_open" ); + +while (!OSSL_STORE_eof (store)) { +OSSL_STORE_INFO *info =OSSL_STORE_load (store); + +if (!info) { +drain_openssl_errors (__LINE__,0 ); +continue ; + } +if (OSSL_STORE_INFO_get_type (info) ==OSSL_STORE_INFO_CERT ) { + cert =OSSL_STORE_INFO_get1_CERT (info); +ERR (!cert,"OSSL_STORE_INFO_get1_CERT" ); + } +OSSL_STORE_INFO_free (info); +if (cert) +break ; + } +OSSL_STORE_close (store); +#elif defined(USE_PKCS11_ENGINE ) +ENGINE *e; +struct { +const char *cert_id; +X509 *cert; + } parms; + + parms.cert_id = cert_src; + parms.cert =NULL ; + +ENGINE_load_builtin_engines (); +drain_openssl_errors (__LINE__,1 ); + e =ENGINE_by_id ("pkcs11" ); +ERR (!e,"Load PKCS#11 ENGINE" ); +if (ENGINE_init (e)) +drain_openssl_errors (__LINE__,1 ); +else +ERR (1 ,"ENGINE_init" ); +if (key_pass) +ERR (!ENGINE_ctrl_cmd_string (e,"PIN" , key_pass,0 ),"Set PKCS#11 PIN" ); +ENGINE_ctrl_cmd (e,"LOAD_CERT_CTRL" ,0 , &parms,NULL ,1 ); +ERR (!parms.cert,"Get X.509 from PKCS#11" ); + cert = parms.cert; +#else +fprintf (stderr,"no pkcs11 engine/provider available\n" ); +exit (1 ); +#endif +return cert; +} +int main (int argc,char **argv) {char *cert_src;
@@ -86,28 +147,10 @@ int main(int argc, char **argv)fclose (f);exit (0 ); }else if (!strncmp (cert_src,"pkcs11:" ,7 )) { -ENGINE *e; -struct { -const char *cert_id; -X509 *cert; - } parms; - - parms.cert_id = cert_src; - parms.cert =NULL ; +X509 *cert =load_cert_pkcs11 (cert_src); -ENGINE_load_builtin_engines (); -drain_openssl_errors (__LINE__,1 ); - e =ENGINE_by_id ("pkcs11" ); -ERR (!e,"Load PKCS#11 ENGINE" ); -if (ENGINE_init (e)) -drain_openssl_errors (__LINE__,1 ); -else -ERR (1 ,"ENGINE_init" ); -if (key_pass) -ERR (!ENGINE_ctrl_cmd_string (e,"PIN" , key_pass,0 ),"Set PKCS#11 PIN" ); -ENGINE_ctrl_cmd (e,"LOAD_CERT_CTRL" ,0 , &parms,NULL ,1 ); -ERR (!parms.cert,"Get X.509 from PKCS#11" ); -write_cert (parms.cert); +ERR (!cert,"load_cert_pkcs11 failed" ); +write_cert (cert); }else {BIO *b;X509 *x509;
scripts/sign-file.c +66 -29
121 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 1325/2214 extract-cert: Wrap key_pass with #ifdef USE_PKCS11_ENGINE
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 4f96b7c68a9904e01049ef610d701b382dca9574 upstream.
A recent strengthening of -Wunused-but-set-variable (enabled with -Wall) in clang under a new subwarning, -Wunused-but-set-global, points out an unused static global variable in certs/extract-cert.c:
certs/extract-cert.c:46:20: error: variable 'key_pass' set but not used [-Werror,-Wunused-but-set-global]
46 | static const char *key_pass;
| ^After commit 558bdc45dfb2 ("sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3"), key_pass is only used with the OpenSSL engine API, not the new provider API. Wrap key_pass's declaration and assignment with '#ifdef USE_PKCS11_ENGINE' so that it is only included with its use to clear up the warning. While this is a little uglier than just marking key_pass with the unused attribute, this will make it easier to clean up all code associated with the use of the engine API if it were ever removed in the future. While in the area, use a tab for the key_pass assignment line to match the rest of the file.
--- scripts/extract-cert.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/extract-cert.c +5 -1
@@ -43,7 +43,9 @@ void format(void)exit (2 ); } +#ifdef USE_PKCS11_ENGINE static const char *key_pass; +#endif static BIO *wb;static char *cert_dst;static int kbuild_verbose;
@@ -132,7 +134,9 @@ int main(int argc, char **argv) kbuild_verbose =atoi (getenv ("KBUILD_VERBOSE" )?:"0" ); - key_pass =getenv ("KBUILD_SIGN_PIN" ); +#ifdef USE_PKCS11_ENGINE + key_pass =getenv ("KBUILD_SIGN_PIN" ); +#endif if (argc !=3 )format ();
Greg Kroah-Hartman
maintainerPATCH 1326/2214 drm/komeda: Fix bits parsing of GLB_CORE_ID
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raveendra Talabattula <[email protected]>
[ Upstream commit ec902de0221747094f9ccbb61454e9633fbf282f ]
GLB_CORE_ID contains the product and version information returned by the hardware. The current macros parses VERSION_MINOR as a 4-bit field and VERSION_STATUS as an 8-bit field, which does not match the register layout. As a result, the driver reports an incorrect version number.
Fix the parsing macros to match the hardware specification:
- VERSION_MINOR is 8 bits at [11:4]
- VERSION_STATUS is 4 bits at [3:0]
--- drivers/gpu/drm/arm/display/include/malidp_product.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/arm/display/include/malidp_product.h +7 -3
@@ -8,14 +8,18 @@#define _MALIDP_PRODUCT_H_/* Product identification */ +/* GLB_CORE_ID fields as per HW specification: +* MINOR is 8 bits ([11:4]) and STATUS is 4 bits ([3:0]). +* Update masks/shifts accordingly. +*/ #define MALIDP_CORE_ID (__product, __major, __minor, __status) \ ((((__product) & 0xFFFF) << 16) | (((__major) & 0xF) << 12) | \ - (((__minor) & 0xF) << 8) | ((__status) & 0xFF)) + (((__minor) & 0xFF) << 4) | ((__status) & 0xF))#define MALIDP_CORE_ID_PRODUCT_ID (__core_id) ((__u32)(__core_id) >> 16)#define MALIDP_CORE_ID_MAJOR (__core_id) (((__u32)(__core_id) >> 12) & 0xF) -#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 8) & 0xF) -#define MALIDP_CORE_ID_STATUS (__core_id) (((__u32)(__core_id)) & 0xFF) +#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 4) & 0xFF) +#define MALIDP_CORE_ID_STATUS (__core_id) ((__u32)(__core_id) & 0xF)/* Mali-display product IDs */ #define MALIDP_D71_PRODUCT_ID 0x0071
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1327/2214 drm/panfrost: Prevent division by 0
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit fd4227f03546c323b5b21568f727233e9792d298 ]
When updating and debug-printing devfreq stats, in the very unlikely off-chance that total device time is less than 100 ns, division by 0 would happen. Fix the divisor when relevant and rearrange operands.
--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_devfreq.c +1 -1
@@ -69,7 +69,7 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,dev_dbg (pfdev->dev,"busy %lu total %lu %lu %% freq %lu MHz\n" , status->busy_time, status->total_time, - status->busy_time / (status->total_time /100 ), + status->busy_time *100 /MAX (status->total_time,1 ), status->current_frequency /1000 /1000 );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1328/2214 drm/omap: dsi: avoid sending bta sync all the time in writes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andreas Kemnade <[email protected]>
[ Upstream commit 20207f78382ff339f3a7f7c5db2c0219b157d32a ]
Some chips need configuration commands to be sent first, before they can send data. TC358762 for example needs PPI_LPTXTIMECNT configured and PPI_STARTPPI set to 1 to be able to transmit anything. To be able to configure such chips, do not send bta sync during writes if no acks are requested. Instead just wait for the packet to be sent to avoid FIFO overflows. There might be more to do about acks, but there seem to be virtually no users of that flag.
This came to light when fiddling with the Epson Moverio BT-200 display which consists of 2 TC358762 bridges with SPI funneled through to the unknown display chip. With that patch the bridge can be accessed, Reading back registers works, when the above-mentioned registers are set.
In Command-Mode update, there was a nop sent, apparently the most relevant part was the bta sync to actually force low power mode.
Video mode panel at OMAP4 (BT-200) and video mode at OMAP5 was tested.
--- drivers/gpu/drm/omapdrm/dss/dsi.c | 63 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 32 deletions(-)
drivers/gpu/drm/omapdrm/dss/dsi.c +31 -32
@@ -58,9 +58,6 @@ static void dsi_uninit_dispc(struct dsi_data *dsi);static int dsi_vc_send_null (struct dsi_data *dsi,int vc,int channel); -static ssize_t _omap_dsi_host_transfer (struct dsi_data *dsi,int vc, -const struct mipi_dsi_msg *msg); -#ifdef DSI_PERF_MEASURE static bool dsi_perf;module_param (dsi_perf, bool,0644 );
@@ -2189,28 +2186,45 @@ static int dsi_vc_send_null(struct dsi_data *dsi, int vc, int channel)static int dsi_vc_write_common (struct omap_dss_device *dssdev,int vc,const struct mipi_dsi_msg *msg) { +DECLARE_COMPLETION_ONSTACK (completion);struct dsi_data *dsi =to_dsi_data (dssdev); +u32 err;int r; +/* wait for IRQ for packet transmission confirmation */ + r =dsi_register_isr_vc (dsi, vc, dsi_completion_handler, + &completion,DSI_VC_IRQ_PACKET_SENT ); +if (r) +return r; +if (mipi_dsi_packet_format_is_short (msg->type)) r =dsi_vc_send_short (dsi, vc, msg);else r =dsi_vc_send_long (dsi, vc, msg); -if (r <0 ) +if ((!r) &&wait_for_completion_timeout (&completion, +msecs_to_jiffies (500 )) ==0 ) + r = -EIO ; + +dsi_unregister_isr_vc (dsi, vc, dsi_completion_handler, + &completion,DSI_VC_IRQ_PACKET_SENT ); +if (r)return r; -/* -* TODO: we do not always have to do the BTA sync, for example -* we can improve performance by setting the update window -* information without sending BTA sync between the commands. -* In that case we can return early. -*/ +/* TODO: find out if more needs to be done for MIPI_DSI_MSG_REQ_ACK */ - r =dsi_vc_send_bta_sync (dssdev, vc); -if (r) { -DSSERR ("bta sync failed\n" ); -return r; +if (msg->flags &MIPI_DSI_MSG_REQ_ACK ) { + r =dsi_vc_send_bta_sync (dssdev, vc); +if (r) { +DSSERR ("bta sync failed\n" ); +return r; + } + }else { + err =dsi_get_errors (dsi); +if (err) { +DSSERR ("Error while sending: %x\n" , err); +return -EIO ; + } }/* RX_FIFO_NOT_EMPTY */
@@ -3228,21 +3242,6 @@ static int _dsi_update(struct dsi_data *dsi)return 0 ; } -static int _dsi_send_nop (struct dsi_data *dsi,int vc,int channel) -{ -const u8 payload[] = {MIPI_DCS_NOP }; -const struct mipi_dsi_msg msg = { - .channel = channel, - .type =MIPI_DSI_DCS_SHORT_WRITE , - .tx_len =1 , - .tx_buf = payload, - }; - -WARN_ON (!dsi_bus_is_locked (dsi)); - -return _omap_dsi_host_transfer (dsi, vc, &msg); -} -static int dsi_update_channel (struct omap_dss_device *dssdev,int vc) {struct dsi_data *dsi =to_dsi_data (dssdev);
@@ -3263,13 +3262,13 @@ static int dsi_update_channel(struct omap_dss_device *dssdev, int vc)DSSDBG ("dsi_update_channel: %d" , vc);/* -* Send NOP between the frames. If we don't send something here, the +* Transition to LP here. If we don't send something here, the * updates stop working. This is probably related to DSI spec stating * that the DSI host should transition to LP at least once per frame. */ - r =_dsi_send_nop (dsi,VC_CMD , dsi->dsidev->channel); + r =dsi_vc_send_bta_sync (dssdev,VC_CMD );if (r <0 ) { -DSSWARN ("failed to send nop between frames: %d\n" , r); +DSSWARN ("failed to send bta sync between frames: %d\n" , r); goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1329/2214 bpftool: Fix spurious batch file read error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 713c02b59e21840f623a3e31c43d967026c75181 ]
do_batch() checks errno after the read loop to detect read failures, but fgets() does not clear errno on success, so a stale errno left by a previously executed command (e.g. map dump's EBADF from a double close) makes bpftool report a batch file read failure and exit with an error even though every command succeeded.
Clear errno before each fgets() call, so the post-loop check only sees the outcome of the last read: zero on success or EOF, E2BIG for an overlong line, and a genuine errno when fgets() fails.
Since errno is now reset before every read in batch mode, drop the USE_LIBCAP errno reset in main() that existed only to keep errno clean for the batch mode.
--- tools/bpf/bpftool/main.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
tools/bpf/bpftool/main.c +5 -11
@@ -304,7 +304,11 @@ static int do_batch(int argc, char **argv)if (json_output)jsonw_start_array (json_wtr); -while (fgets (buf,sizeof (buf), fp)) { +for (;;) { + errno =0 ; +if (!fgets (buf,sizeof (buf), fp)) +break ; + cp =strchr (buf,'#' );if (cp) *cp ='\0' ;
@@ -404,16 +408,6 @@ int main(int argc, char **argv)setlinebuf (stdout); -#ifdef USE_LIBCAP -/* Libcap < 2.63 hooks before main() to compute the number of -* capabilities of the running kernel, and doing so it calls prctl() -* which may fail and set errno to non-zero. -* Let's reset errno to make sure this does not interfere with the -* batch mode. -*/ - errno =0 ; -#endif - last_do_help = do_help; pretty_output = false; json_output = false;
Signature · 1 line
2.53.0