5.15.226-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 685/2214 alpha: determine tininess after rounding in the FP emulation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Turner <[email protected]>
[ Upstream commit b74843b38da8f1186fd7d447646c835b47096a15 ]
IEEE 754 lets an architecture determine tininess of a floating-point result either before or after rounding, but requires the same choice for every operation. Alpha determines it after rounding, and stdlib's tst-tininess confirms the hardware does so for the results it produces itself.
The soft-fp emulation has no notion of the distinction and always determines tininess before rounding, so a result that the hardware would not consider tiny is reported as underflowing whenever the instruction happens to trap for software completion. The two paths then disagree on the same machine. A multiply of the largest subnormal double by 1 + 2^-52 rounds up to the smallest normal and raises no underflow when the operands are normal, but raises it when an operand is subnormal and the instruction traps:
glibc math testsuite, test-float32x-float64-mul:
Failure: mul_double (0x3.ffffffffffffcp-1024, 0x1.0000000000001p+0):
Exception "Underflow" set
Add _FP_TININESS_AFTER_ROUNDING, as glibc's copy of soft-fp has, and set it for alpha. It determines tininess by rounding a copy of the result as if the exponent range were unbounded, which is what the definition asks for. A plain check of whether the rounded result came out normal is not
equivalent: it differs for values that are still tiny once rounded with an unbounded exponent range but reach the smallest normal on the coarser subnormal grid. That plain check is what the hardware itself does (it decides tininess from the delivered result), and it is why a divide such as -0x4p-128 / 0x1.000002p+0 in FE_DOWNWARD delivers -0x1p-126 and raises nothing although the result is tiny after rounding. Such cases do not trap, so the emulation never sees them; where it does get control, it follows the definition rather than reproducing that deviation, which is what glibc's soft-fp does as well.
The macro defaults to zero, so powerpc, sh and sparc keep determining tininess before rounding as they do now.
--- arch/alpha/include/asm/sfp-machine.h | 4 ++++ include/math-emu/op-common.h | 23 +++++++++++++++++++++-- include/math-emu/soft-fp.h | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-)
arch/alpha/include/asm/sfp-machine.h +4 -0
@@ -59,6 +59,10 @@ R##_c = FP_CLS_NAN; \ }while (0 ) +/* Alpha determines tininess after rounding, so the emulation must do the + same as the hardware does for the results it produces itself. */ +#define _FP_TININESS_AFTER_ROUNDING 1 +/* Obtain the current rounding mode. */ #define FP_ROUNDMODE mode#define FP_RND_NEAREST (FPCR_DYN_NORMAL >> FPCR_DYN_SHIFT)
include/math-emu/op-common.h +21 -2
@@ -135,6 +135,24 @@ do { \ else \ { \/* we've got a denormalized number */ \ +int _FP_PACK_CANONICAL_is_tiny =1 ; \ + if (_FP_TININESS_AFTER_ROUNDING && X##_e == 0) \ + { \ +/* Architectures that detect tininess after rounding \ +only signal underflow if the result is still \ +subnormal once rounded as if the exponent range \ +were unbounded. Round a copy to find out. */ \ + FP_DECL_##fs(_FP_PACK_CANONICAL_T); \ + /* The class field is not used by the rounding below, \ +and is unused entirely where this block is dead. */ \ + (void)_FP_PACK_CANONICAL_T##_c; \ + _FP_FRAC_COPY_##wc(_FP_PACK_CANONICAL_T, X); \ + _FP_PACK_CANONICAL_T##_s = X##_s; \ + _FP_PACK_CANONICAL_T##_e = X##_e; \ + _FP_ROUND(wc, _FP_PACK_CANONICAL_T); \ + if (_FP_FRAC_OVERP_##wc(fs, _FP_PACK_CANONICAL_T)) \ + _FP_PACK_CANONICAL_is_tiny = 0; \ + } \ X##_e = -X##_e + 1; \ if (X##_e <= _FP_WFRACBITS_##fs) \ { \
@@ -161,8 +179,9 @@ do { \ _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \ } \ } \ - if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) || \ - (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW)) \ + if (_FP_PACK_CANONICAL_is_tiny \ + && ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) || \ + (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW))) \ FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \ } \ else \
include/math-emu/soft-fp.h +8 -0
@@ -31,6 +31,14 @@#include <endian.h> #endif +/* Whether the architecture determines tininess of a floating-point +result after rounding rather than before it. IEEE 754 permits either +but requires the same choice for every operation, so this has to agree +with what the hardware does for the results it produces itself. */ +#ifndef _FP_TININESS_AFTER_ROUNDING +#define _FP_TININESS_AFTER_ROUNDING 0 +#endif +#define _FP_WORKBITS 3#define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)#define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 686/2214 ocfs2: reserve metadata for a new xattr block and its value tree
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 8ad5fa0c11246d260d7b12c9672e604b1f431b2e ]
Patch series "ocfs2: fix metadata reservation for xattr value trees".
ocfs2_calc_xattr_set_need() reserves too little metadata for a new xattr value's extent tree on three paths. The reservation cannot be topped up once the transaction has started, so ocfs2_add_clusters_in_btree() gives up with RESTART_META when the value root fills and nothing is left. ocfs2_xattr_extend_allocation() turns that into -ENOSPC, after ocfs2_xa_cleanup_value_truncate() has dropped the entry and leaked the clusters already handed out; before commit 0cdc7dde00ec ("ocfs2: fix missing metadata reservation for large xattrs") it was a BUG_ON() instead. It takes a fragmented cluster allocator to get there, since the first extent always fits in the root.
Patch 1 fixes the create side of meta_guess: commit 3ed2be719eb9 ("ocfs2:
allow for more than one data extent when creating xattr") replaced the block reserved for the new xattr block with the two the value tree needs instead of adding them together.
Patch 2 fixes the arm that moves an xattr back into the inode, which charges credits for a value tree but no metadata for one.
Patch 3 drops a second copy of the same reservation on the path that falls through to meta_guess. That one is cleanup rather than a fix and is not for stable, and it must not be backported without patch 1: the duplicate it removes is what currently covers the shortfall patch 1 fixes.
This patch (of 3):
The create side of meta_guess in ocfs2_calc_xattr_set_need() reserves metadata for the new value's extent tree and nothing for the xattr block that will hold it:
} else {
credits += OCFS2_XATTR_BLOCK_CREATE_CREDITS;
if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
struct ocfs2_extent_list *el = &def_xv.xv.xr_list;
meta_add += ocfs2_extend_meta_needed(el);
...Commit 3ed2be719eb9 ("ocfs2: allow for more than one data extent when creating xattr") meant to add that tree on top of the meta_add += 1 the branch already had, but it moved the 1 into the else arm instead, so the external-value case lost it. The 1 is not optional: it is what ocfs2_create_xattr_block() takes from meta_ac through ocfs2_claim_metadata(), and it is spent before the value tree exists.
ocfs2_extend_meta_needed() on the empty def_xv list returns 2, so the branch reserves 2 where 3 are needed. The xattr block consumes one, and when the cluster allocator is fragmented enough that the value needs more than one extent, ocfs2_add_clusters_in_btree() comes back around with a full value root and ocfs2_alloc_context_bits_left() of 1 against a threshold of 2. It answers RESTART_META, which ocfs2_xattr_extend_allocation() turns into a BUG_ON(). Commit 0cdc7dde00ec ("ocfs2: fix missing metadata reservation for large xattrs") downgraded that to -ENOSPC, at the cost of leaking the clusters already handed out: ocfs2_xa_cleanup_value_truncate() takes its !orig_clusters arm, drops the entry and leaves the clusters for fsck.ocfs2 to reclaim.
Reserve for the block and the tree separately.
--- fs/ocfs2/xattr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +7 -1
@@ -3247,7 +3247,13 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, credits +=OCFS2_XATTR_BLOCK_CREATE_CREDITS ;if (xi->xi_value_len >OCFS2_XATTR_INLINE_SIZE ) {struct ocfs2_extent_list *el = &def_xv.xv.xr_list; - meta_add +=ocfs2_extend_meta_needed (el); +/* +* One block for the xattr block we may have to +* allocate, the rest for growing the value tree it +* would hold. If ocfs2_xattr_ibody_set() succeeds +* instead, that first block goes unused. +*/ + meta_add +=1 +ocfs2_extend_meta_needed (el); credits +=ocfs2_calc_extend_credits (inode->i_sb, el); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 687/2214 ocfs2: reserve value tree metadata when moving an xattr into the inode
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 f5aee8ae5f85f8dfa78160e5c4963494319cdd64 ]
ocfs2_calc_xattr_set_need() charges no metadata for the case where an xattr living in an xattr block or bucket moves back into the inode:
if (old_in_xb) {
if (ocfs2_xattr_can_be_in_inode(inode, xi, xis)) {
clusters_add += new_clusters;
credits += ...;
if (!ocfs2_xattr_is_local(xe))
credits += ocfs2_calc_extend_credits(...);
goto out;
}
}The credits for extending a value tree are there but the matching blocks are not, so meta_add stays 0, ocfs2_init_xattr_set_ctxt() skips ocfs2_reserve_new_metadata_blocks() and ctxt->meta_ac is left NULL.
This is the shape commit 0cdc7dde00ec ("ocfs2: fix missing metadata reservation for large xattrs") fixed for the xattr block case, and it is reached the same way: namevalue_size() charges a value larger than OCFS2_XATTR_INLINE_SIZE as only OCFS2_XATTR_ROOT_SIZE, so ocfs2_xattr_can_be_in_inode() accepts a new value that will be stored outside. ocfs2_xa_prepare_entry() installs a value root from def_xv and grows it, and once the cluster allocator is fragmented enough to need a second extent ocfs2_add_clusters_in_btree() finds the root full with no meta_ac at all and answers RESTART_META. ocfs2_xattr_extend_allocation() turns that into -ENOSPC, or into a BUG_ON() without that commit, and ocfs2_xa_cleanup_value_truncate() takes its !orig_clusters arm, dropping the entry and leaking the clusters already handed out until fsck.ocfs2 reclaims them.
Reserve for the value tree here too. The entry moves back into the inode rather than into a new xattr block, so unlike the create side of meta_guess this needs no block of its own.
--- fs/ocfs2/xattr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ocfs2/xattr.c +8 -0
@@ -3147,6 +3147,14 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, credits +=ocfs2_calc_extend_credits ( inode->i_sb, &def_xv.xv.xr_list); +/* +* A value too big to stay inline is only charged as +* OCFS2_XATTR_ROOT_SIZE above, so it can still need a +* value tree of its own. No xattr block is allocated +* on this path, so the tree is all we reserve for. +*/ +if (xi->xi_value_len >OCFS2_XATTR_INLINE_SIZE ) + meta_add +=ocfs2_extend_meta_needed (&def_xv.xv.xr_list); goto out; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 688/2214 writeback: reset dirtied_when when switching wbs
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit 13b9a606dd0a6cf9bac12894c97b9546d22a7425 ]
When switching a dirty inode to another wb, inode_do_switch_wbs() puts it at the newest end of the target b_dirty list instead of searching for its sorted position. This requires updating dirtied_when, which move_expired_inodes() uses to decide where to stop scanning.
However, the switch updates dirtied_time_when instead. This leaves b_dirty out of order and can make the scan stop before reaching older inodes. It also resets the lazytime expiration timestamp, potentially delaying timestamp writeback.
Update dirtied_when instead, preserving both the constant-time insertion and the lazytime expiration timestamp. Correct the field name in the comment and document the distinction between the two inode timestamps.
--- fs/fs-writeback.c | 6 +++--- include/linux/fs.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-)
fs/fs-writeback.c +3 -3
@@ -427,12 +427,12 @@ static bool inode_do_switch_wbs(struct inode *inode,if (inode->i_state &I_DIRTY_ALL ) {/* * We need to keep b_dirty list sorted by -* dirtied_time_when. However properly sorting the +* dirtied_when. However properly sorting the * inode in the list gets too expensive when switching * many inodes. So just attach inode at the end of the -* dirty list and clobber the dirtied_time_when. +* dirty list and clobber the dirtied_when. */ - inode->dirtied_time_when = jiffies; + inode->dirtied_when = jiffies;inode_io_list_move_locked (inode, new_wb, &new_wb->b_dirty); }else {
include/linux/fs.h +3 -1
@@ -679,7 +679,9 @@ struct inode {unsigned long i_state;struct rw_semaphore i_rwsem; -unsigned long dirtied_when;/* jiffies of first dirtying */ +/* Timestamp for writeback list ordering and age checks (jiffies). */ +unsigned long dirtied_when; +/* Start time for deciding when lazytime updates need writeback (jiffies). */ unsigned long dirtied_time_when;struct hlist_node i_hash;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 689/2214 writeback: clear old wb dirty state after inode switches
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit a396fe9f74ea367ae3fab2dcb70b24e83db9f0cb ]
Switching an inode to another wb updates the target wb's dirty-I/O state, but no longer checks whether the source wb's dirty-I/O lists became empty. The check was lost when inode_io_list_del_locked(inode, old_wb) was removed to support tracking clean attached inodes.
If the last dirty inode is moved, WB_has_dirty_io remains set on the old wb and its bandwidth contribution remains in bdi->tot_write_bandwidth. This can keep an empty wb scheduled for periodic writeback and overstate the total bandwidth used to distribute writeback work.
Call wb_io_lists_depopulated() on the old wb after the batch of inode switches, while its list_lock is still held. This clears the flag and removes the bandwidth contribution if its dirty-I/O lists are empty.
--- fs/fs-writeback.c | 1 + 1 file changed, 1 insertion(+)
fs/fs-writeback.c +1 -0
@@ -509,6 +509,7 @@ static void inode_switch_wbs_work_fn(struct work_struct *work) } } +wb_io_lists_depopulated (old_wb);spin_unlock (&new_wb->list_lock);spin_unlock (&old_wb->list_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 690/2214 sh: maple: Use the matching IRQ cookie when invoking free_irq()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit e3ef44e77b40e3cecfb34757ff3c15ecceea0309 ]
The Maple DMA and VBLANK handlers are registered with &maple_unsupported_device as their dev_id. Passing NULL to free_irq() cannot find either action, so the handlers remain registered and the IRQ core warns.
Use the same cookie when freeing both handlers on the error paths.
--- drivers/sh/maple/maple.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/sh/maple/maple.c +2 -2
@@ -870,10 +870,10 @@ static int __init maple_bus_init(void)kmem_cache_destroy (maple_queue_cache); cleanup_bothirqs: -free_irq (HW_EVENT_VSYNC ,0 ); +free_irq (HW_EVENT_VSYNC , &maple_unsupported_device); cleanup_irq: -free_irq (HW_EVENT_MAPLE_DMA ,0 ); +free_irq (HW_EVENT_MAPLE_DMA , &maple_unsupported_device); cleanup_dma:free_pages ((unsigned long ) maple_sendbuf,MAPLE_DMA_PAGES );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 691/2214 net: wwan: iosm: validate msg_head before indexing msg_ring
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Chao <[email protected]>
[ Upstream commit 46cbf85155e5451b6682ea0c17bc62ec564aec36 ]
ipc_protocol_free_msg_get() reads msg_head from shared memory and uses it directly as an index into msg_ring[]. If the head is out of range, the subsequent memset() writes beyond the message ring.
Validate head against IPC_MEM_MSG_ENTRIES before using it as an index. The ring is a circular buffer, so a value outside the valid range indicates a corrupted head pointer; report the error and fail the allocation instead of writing out of bounds.
--- drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c +5 -0
@@ -14,6 +14,11 @@ ipc_protocol_free_msg_get(struct iosm_protocol *ipc_protocol, int *index)u32 new_head = (head +1 ) %IPC_MEM_MSG_ENTRIES ;union ipc_mem_msg_entry *msg; +if (head >=IPC_MEM_MSG_ENTRIES ) { +dev_err (ipc_protocol->dev,"invalid message head %u" , head); +return NULL ; + } +if (new_head ==le32_to_cpu (ipc_protocol->p_ap_shm->msg_tail)) {dev_err (ipc_protocol->dev,"message ring is full" );return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 692/2214 tipc: fix broadcast sender hang on last acker departure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Martin <[email protected]>
[ Upstream commit f4377bf85887f57b59abb5479f7660a81ffe4449 ]
TIPC group broadcast senders are blocked while a replicast still has outstanding member acks: tipc_group_bc_cong() returns true as long as grp->bc_ackers is non-zero, and clears *grp->open, which is what tipc_poll() uses to report EPOLLOUT (via tsk->group_is_open).
When the last outstanding acker departs before acking, tipc_group_delete_member() decrements grp->bc_ackers to zero but never restores *grp->open. As a result poll(EPOLLOUT) never fires again. A writer blocked in sendmsg() is only released if some other wakeup happens after the deletion: with TIPC_GROUP_MEMBER_EVTS the leave event delivery calls sk_data_ready() and wakes it, but without member events nothing does and it sleeps indefinitely, since the default send timeout is MAX_SCHEDULE_TIMEOUT.
Commit 99cc2a62e07a ("tipc: reject invalid and unexpected GRP_ACK_MSG to prevent bc_ackers underflow") already calls this out in its changelog as a pre-existing issue.
Restore the open state exactly on the 1->0 transition in the delete path, mirroring the GRP_ACK_MSG completion path, and invoke sk->sk_write_space() from tipc_sk_filter_rcv() when the group just became writable again.
Also make the ack accounting precise. The delete path used to test less(m->bc_acked, grp->bc_snd_nxt - 1), which also matches members that were never counted for the current replicast (JOINING/LEAVING members keep a stale bc_acked), and the GRP_ACK_MSG handler accepted an ack from any member whose bc_acked differed from the expected value. Either could zero bc_ackers on behalf of a member that owes nothing and silently void an ack still owed by a real acker. Track whether a member owes an ack for the current replicast in a new per-member bc_pending flag, set when the member is counted and cleared when its ack arrives, and use it both to accept an ack and to decide on deletion. bc_acked has no remaining user and is removed. Suggested by Tung Quang Nguyen.
This issue was discovered by Tencent CodeBuddy Security.
--- net/tipc/group.c | 19 ++++++++++--------- net/tipc/socket.c | 12 +++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-)
net/tipc/group.c +10 -9
@@ -74,7 +74,7 @@ struct tipc_member {u16 window;u16 bc_rcv_nxt;u16 bc_syncpt; -u16 bc_acked; +bool bc_pending; };struct tipc_group {
@@ -316,7 +316,6 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp, m->node = node; m->port = port; m->instance = instance; - m->bc_acked = grp->bc_snd_nxt -1 ; ret =tipc_group_add_to_tree (grp, m);if (ret <0 ) {kfree (m);
@@ -340,9 +339,12 @@ static void tipc_group_delete_member(struct tipc_group *grp,rb_erase (&m->tree_node, &grp->members); grp->member_cnt--; -/* Check if we were waiting for replicast ack from this member */ -if (grp->bc_ackers &&less (m->bc_acked, grp->bc_snd_nxt -1 )) - grp->bc_ackers--; +/* If this member owed an ack for the current replicast and it +* was the last one, restore the open state so blocked broadcast +* senders can proceed. +*/ +if (grp->bc_ackers && m->bc_pending && !--grp->bc_ackers) + *grp->open = true;list_del_init (&m->list);list_del_init (&m->small_win);
@@ -394,7 +396,6 @@ void tipc_group_update_member(struct tipc_member *m, int len)void tipc_group_update_bc_members (struct tipc_group *grp,int len,bool ack) { -u16 prev = grp->bc_snd_nxt -1 ;struct tipc_member *m;struct rb_node *n;u16 ackers =0 ;
@@ -403,8 +404,8 @@ void tipc_group_update_bc_members(struct tipc_group *grp, int len, bool ack) m = container_of(n, struct tipc_member, tree_node);if (tipc_group_is_receiver (m)) {tipc_group_update_member (m, len); - m->bc_acked = prev; ackers++; + m->bc_pending = ack; } }
@@ -800,9 +801,9 @@ void tipc_group_proto_rcv(struct tipc_group *grp, bool *usr_wakeup,if (!m || !grp->bc_ackers)return ; acked =msg_grp_bc_acked (hdr); -if (acked != grp->bc_snd_nxt || m->bc_acked == acked) +if (acked != grp->bc_snd_nxt || !m->bc_pending)return ; - m->bc_acked = acked; + m->bc_pending = false;if (--grp->bc_ackers)return ;list_del_init (&m->small_win);
net/tipc/socket.c +11 -1
@@ -2357,8 +2357,18 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb,if (unlikely (!msg_isdata (hdr)))tipc_sk_proto_rcv (sk, &inputq, xmitq); -if (unlikely (grp)) +if (unlikely (grp)) { +bool was_open = tsk->group_is_open; +tipc_group_filter_msg (grp, &inputq, xmitq); +/* A departing member may have held the last outstanding +* replicast ack, which can restore the open state inside +* tipc_group_filter_msg(); wake up senders blocked in +* poll()/write() if the group just became writable. +*/ +if (!was_open && tsk->group_is_open) + sk->sk_write_space (sk); + }if (unlikely (!grp) && mtyp ==TIPC_MCAST_MSG )tipc_mcast_filter_msg (net, &tsk->mc_method.deferredq, &inputq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 693/2214 i2c: designware: queue only one read command for block reads
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Navon John Lukose <[email protected]>
[ Upstream commit 73dae605cad7921800677d982bfaeb81cc930dec ]
i2c_dw_xfer_msg() pre-queues up to rx_fifo_depth read commands based on the initial msg.len. For I2C_M_RECV_LEN transfers the real length is unknown until the first byte arrives and i2c_dw_recv_len() runs. When a large initial length is passed, the surplus pre-queued reads leave rx_outstanding non-zero after i2c_dw_recv_len() adjusts msg.len, so the completion condition is never met and the transfer times out. In a loop, this repeatedly times out the controller and disrupts unrelated driver-bound devices on the same adapter.
Queue only one read command while I2C_M_RECV_LEN is pending. i2c_dw_recv_len() re-enables TX_EMPTY, and the rest are queued once the device-reported length is known.
--- drivers/i2c/busses/i2c-designware-master.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/i2c/busses/i2c-designware-master.c +8 -0
@@ -441,6 +441,14 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)if (dev->rx_outstanding >= dev->rx_fifo_depth)break ; +/* +* For block reads, queue only the length +* byte until i2c_dw_recv_len() runs. +*/ +if ((flags &I2C_M_RECV_LEN ) && + buf_len < msgs[dev->msg_write_idx].len) +break ; +regmap_write (dev->map,DW_IC_DATA_CMD , cmd |0x100 ); rx_limit--;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 694/2214 tpm: tpm_nsc: fix NULL pointer dereference on init failure
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 1900449684cf71427a51e0bb1d7914c0c8b39152 ]
tpm_nsc_remove() is used as the release callback of the hand-created platform device and dereferences the chip drvdata unconditionally. If init fails before tpmm_chip_alloc() (e.g. request_region() cannot claim the ports), the error path drops the last device reference and the release callback runs with chip == NULL, crashing module init.
Return early when the chip has not been created yet.
--- drivers/char/tpm/tpm_nsc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_nsc.c +6 -1
@@ -258,7 +258,12 @@ static struct platform_device *pdev = NULL;static void tpm_nsc_remove (struct device *dev) {struct tpm_chip *chip =dev_get_drvdata (dev); -struct tpm_nsc_priv *priv =dev_get_drvdata (&chip->dev); +struct tpm_nsc_priv *priv; + +if (!chip) +return ; + + priv =dev_get_drvdata (&chip->dev);tpm_chip_unregister (chip);release_region (priv->base,2 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 695/2214 tpm: tpm_nsc: stop using the cleanup callback as dev.release
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 df0ef271087623439a1e900f323ed2a57204706d ]
tpm_nsc_remove() is called explicitly from cleanup_nsc() and also runs as the platform device release callback on the final platform_device_put(), so the cleanup executes twice on module exit; the second invocation operates on a chip that has already been freed by the devm cleanup, and the I/O region is released twice.
Overwriting the release callback installed by platform_device_alloc() also keeps platform_device_release() from running, leaking the platform object allocation.
Leave the default release callback in place; the explicit call in cleanup_nsc() remains the single cleanup point.
--- drivers/char/tpm/tpm_nsc.c | 1 - 1 file changed, 1 deletion(-)
drivers/char/tpm/tpm_nsc.c +0 -1
@@ -326,7 +326,6 @@ static int __init init_nsc(void) pdev->num_resources =0 ; pdev->dev.driver = &nsc_drv.driver; - pdev->dev.release = tpm_nsc_remove;if ((rc =platform_device_add (pdev)) <0 ) goto err_put_dev;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 696/2214 tpm: fix zero-length read discarding the pending response
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 6fc1b05077b8ac7c3193616f0bc419f6185988c6 ]
POSIX requires that a read() with a count of zero returns zero and has no other effects. tpm_common_read() treats such a call as a consumed response: it marks the pending response as read and drops it, so the response can never be retrieved; subsequent reads return zero and the next write() is allowed to overwrite the response buffer, silently breaking the command/response pairing of the TPM character devices.
Return early when the caller passes a zero count, leaving any pending response untouched for the next read. A zero-length read will not report a deferred asynchronous error; POSIX permits read() to skip error detection for a zero count.
--- drivers/char/tpm/tpm-dev-common.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/char/tpm/tpm-dev-common.c +3 -0
@@ -131,6 +131,9 @@ ssize_t tpm_common_read(struct file *file, char __user *buf,ssize_t ret_size =0 ;int rc; +if (!size) +return 0 ; +mutex_lock (&priv->buffer_mutex);if (priv->response_length) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 697/2214 parisc: eisa_enumerator: Fix out-of-bounds reads of the EEPROM buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jean Delu <[email protected]>
[ Upstream commit c0a3e153804f0c14f4159ddbd2b73483c9cb3577 ]
eisa_enumerator() trusts the contents of the EISA EEPROM. The number of slots is read from the EEPROM header and used to access the slot records at HPEE_SLOT_INFO(i) = 20 + 48*i within the fixed-size eeprom_buf (HPEE_MAX_LENGTH, 8192 bytes) without any bound check. As struct eeprom_eisa_slot_info is 48 bytes, only 170 records fit into the buffer, but num_slots is a u8 and may be up to 255, so a corrupted EEPROM makes the code read up to about 4 kB past the end of the buffer (e.g. record 254 is accessed at offset 20 + 48*254 = 12212).
parse_slot_config() has the same kind of problem: it clamps config_data_length against HPEE_MAX_LENGTH but does not take config_data_offset into account, so the parser can walk past the end of the buffer even when the offset itself is valid.
Clamp the number of slots so that all slot records fit into the buffer, and hand the number of bytes actually available to parse_slot_config() and bound the parse by it.
--- drivers/parisc/eisa_enumerator.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/parisc/eisa_enumerator.c +12 -3
@@ -311,6 +311,7 @@ static int configure_function(const unsigned char *buf, int *more)static int parse_slot_config (int slot,const unsigned char *buf, +unsigned int buflen,struct eeprom_eisa_slot_info *es,struct resource *io_parent,struct resource *mem_parent)
@@ -333,8 +334,8 @@ static int parse_slot_config(int slot,printk (KERN_INFO "EISA slot %d: %s %s " , slot, board, es->flags&HPEE_FLAG_BOARD_IS_ISA ?"ISA" :"EISA" ); - maxlen = es->config_data_length <HPEE_MAX_LENGTH ? - es->config_data_length :HPEE_MAX_LENGTH ; +/* never parse beyond the data that is actually in the buffer */ + maxlen = min_t(unsigned int, es->config_data_length, buflen);while ((pos < maxlen) && (num_func <= es->num_functions)) { pos+=configure_function (buf+pos, &function_len);
@@ -491,6 +492,13 @@ int eisa_enumerator(unsigned long eeprom_addr,printk (KERN_INFO "Enumerating EISA bus\n" ); eh = (struct eeprom_header *)(eeprom_buf); +/* +* The EEPROM contents are not to be trusted: clamp the number of +* slots so that all slot records fit into eeprom_buf. +*/ + eh->num_slots =min_t (u8, eh->num_slots, + (HPEE_MAX_LENGTH -sizeof (*eh)) / +sizeof (struct eeprom_eisa_slot_info ));for (i=0 ;i<eh->num_slots;i++) {struct eeprom_eisa_slot_info *es;
@@ -503,7 +511,8 @@ int eisa_enumerator(unsigned long eeprom_addr,if (es->config_data_offset <HPEE_MAX_LENGTH ) {if (parse_slot_config (i+1 , &eeprom_buf[es->config_data_offset], - es, io_parent, mem_parent)) { +HPEE_MAX_LENGTH - es->config_data_offset, + es, io_parent, mem_parent)) {return -1 ; } }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 698/2214 i2c: mt7621: fix copying uninitialized kernel stack with reduced page_len
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Marangi <[email protected]>
[ Upstream commit b7fd977fec0d3f2bdd4f13bb59949c817a365652 ]
When a page_len is less than 5 bytes in mtk_i2c_xfer, uninitialized kernel stack data is copied and written to REG_SM0D1_REG. Equally on the read part, an unnecessary read is done.
Guard these extra copy/write and read for the page_len to fix leaking uninitialized stack memory.
--- drivers/i2c/busses/i2c-mt7621.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-mt7621.c +6 -3
@@ -143,7 +143,6 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,u16 addr;int i, j, ret, len, page_len;u32 cmd; -u32 data[2 ]; i2c =i2c_get_adapdata (adap);
@@ -189,6 +188,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,/* transfer data */ for (len = pmsg->len, j =0 ; len >0 ; len -=8 , j +=8 ) { +u32 data[2 ] = { }; + page_len = (len >=8 ) ?8 : len;if (pmsg->flags &I2C_M_RD ) {
@@ -197,7 +198,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, }else {memcpy (data, &pmsg->buf[j], page_len);iowrite32 (data[0 ], i2c->base +REG_SM0D0_REG ); -iowrite32 (data[1 ], i2c->base +REG_SM0D1_REG ); +if (page_len >4 ) +iowrite32 (data[1 ], i2c->base +REG_SM0D1_REG ); cmd =SM0CTL1_WRITE ; }
@@ -207,7 +209,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,if (pmsg->flags &I2C_M_RD ) { data[0 ] =ioread32 (i2c->base +REG_SM0D0_REG ); - data[1 ] =ioread32 (i2c->base +REG_SM0D1_REG ); +if (page_len >4 ) + data[1 ] =ioread32 (i2c->base +REG_SM0D1_REG );memcpy (&pmsg->buf[j], data, page_len); }else {if (!(pmsg->flags &I2C_M_IGNORE_NAK )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 699/2214 posix-cpu-timers: Fix pid refcount leak in do_cpu_nanosleep() signal path
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 8ccd731b63a0183ca2b0e18f3ca15864b3f37eda ]
do_cpu_nanosleep() sleeps on a temporary k_itimer whose reference on the target's struct pid is taken by posix_cpu_timer_create() and dropped by posix_cpu_timer_del(). When a signal ends the sleep, the timer is disarmed with posix_cpu_timer_set(), but posix_cpu_timer_del() is only called for a result of 0 or TIMER_RETRY. If the target thread or process has exited in the meantime, timer_lock_sighand() finds no task, posix_cpu_timer_set() returns -ESRCH and the pid reference is leaked.
An unprivileged user can trigger this: sleep on the CPU clock of a thread, let that thread exit, then signal the sleeper. Each round leaks one struct pid. Repeating it exhausts unreclaimable slab memory within minutes:
Out of memory: Killed process 150 (poc) total-vm:789292kB, anon-rss:484kB
Kernel panic - not syncing: System is deadlocked on memory
Fix this by also calling posix_cpu_timer_del() on -ESRCH. With the target gone, the deletion is safe. It finds no task either and only drops the pid reference.
--- kernel/time/posix-cpu-timers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/posix-cpu-timers.c +2 -2
@@ -1601,8 +1601,8 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,*/ expires =cpu_timer_getexpires (&timer.it.cpu); error =posix_cpu_timer_set (&timer,0 , &zero_it, &it); -if (!error) { -/* Timer is now unarmed, deletion can not fail. */ +if (error !=TIMER_RETRY ) { +/* Unarmed or target gone (-ESRCH), deletion can not fail. */ posix_cpu_timer_del (&timer); }else {while (error ==TIMER_RETRY ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 700/2214 timekeeping: Update offsets on sequence counter retry in ktime_get_update_offsets_now()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh (Schneider Electric) <[email protected]>
[ Upstream commit 6541fbc942f3b63bb8bd44e34eee6223e0abe719 ]
The sequence counter of the cwsseq target is modified during the sequence counter loop. If the loop retries, cwsseq will now match but the offsets contain the values from the previous loop iteration. These are not guaranteed to be consistent in themselves or with the current loops "now.
Save the target's original sequence counter value so that the update also happens on loop retries.
--- kernel/time/timekeeping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/timekeeping.c +2 -1
@@ -2298,6 +2298,7 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, ktime_t *offs_boot, ktime_t *offs_tai) {struct timekeeper *tk = &tk_core.timekeeper; +u32 cwsseq_orig = *cwsseq;unsigned int seq;ktime_t base;u64 nsecs;
@@ -2309,7 +2310,7 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, nsecs =timekeeping_get_ns (&tk->tkr_mono); base =ktime_add_ns (base, nsecs); -if (*cwsseq != tk->clock_was_set_seq) { +if (cwsseq_orig != tk->clock_was_set_seq) { *cwsseq = tk->clock_was_set_seq; *offs_real = tk->offs_real; *offs_boot = tk->offs_boot;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 701/2214 cgroup: dont kill migrated processes through their exiting threads
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 5f4a3f743acc96987ae5c2e966947942c34ba56c ]
Since commit da13e0e72a73 ("cgroup: fix cgroup.kill for exited thread group leader"), __cgroup_kill() visits every thread in the cgroup and sends SIGKILL with PIDTYPE_TGID, so each visited thread takes down its whole thread group.
A thread that has started exiting can stay in a cgroup after its process has been moved out of it. cgroup_migrate_add_task() skips PF_EXITING tasks, and the thread is only unlinked by cgroup_task_dead() after its final context switch. mm_release() clears the thread's clear_child_tid word and wakes the joiner well before that, so pthread_join() can return while the thread is still in the old cgroup.
If cgroup.kill is written in that window, __cgroup_kill() finds the exiting thread and complete_signal() passes the group-wide SIGKILL on to a live thread, killing a process that already left the cgroup. The cgroup selftest test_stress.sh runs into this: test_cgcore_proc_migration() joins its threads, moves itself back to the root cgroup, and cg_destroy() falls back to cgroup.kill on the old cgroup when rmdir() fails with EBUSY, so test_core kills itself. KernelCI has been reporting "with_stress.sh: line 94: ... Killed" on several arm64 boards since the commit reached linux-next.
Keep visiting every thread, but go back to sending SIGKILL to the thread that was found. A SIGKILL sent to a live thread still kills its whole thread group, so both cases fixed by that commit stay fixed, and task_can_queue_signal() drops one sent to a thread that is already exiting.
--- kernel/cgroup/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup/cgroup.c +1 -1
@@ -3855,7 +3855,7 @@ static void __cgroup_kill(struct cgroup *cgrp)if (__fatal_signal_pending (task))continue ; -do_send_sig_info (SIGKILL ,SEND_SIG_NOINFO , task,PIDTYPE_TGID ); +send_sig (SIGKILL , task,0 ); }css_task_iter_end (&it); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 702/2214 scsi: ufs: core: Clear stale UIC result byte before peer DME retries
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 e4a9b7640914b248eb7537d4507aa42db080586a ]
Peer DME get and set retry a failed attempt with the same struct uic_command. UIC completion ORs the ConfigResultCode into argument2[7:0], and nothing clears it before the next attempt. Once an attempt fails, every retry keeps reporting that error code, even when the device returns success, so a transient failure becomes a hard failure after three retries. Each such retry also triggers the WARN_ON_ONCE() in ufshcd_dispatch_uic_cmd(). In ufshcd_dme_set_attr(), ufshcd_uic_cmd_compl() also overwrites argument3 with the register readback before the next attempt.
Clear the result byte and restore argument3 in ufshcd_dme_set_attr() when an attempt fails.
--- drivers/scsi/ufs/ufshcd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +7 -2
@@ -3835,9 +3835,12 @@ int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,do {/* for peer attributes we retry upon failure */ ret =ufshcd_send_uic_cmd (hba, &uic_cmd); -if (ret) +if (ret) {dev_dbg (hba->dev,"%s: attr-id 0x%x val 0x%x error code %d\n" , set,UIC_GET_ATTR_ID (attr_sel), mib_val, ret); + uic_cmd.argument2 &= ~MASK_UIC_COMMAND_RESULT ; + uic_cmd.argument3 = mib_val; + } }while (ret && peer && --retries);if (ret)
@@ -3902,9 +3905,11 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,do {/* for peer attributes we retry upon failure */ ret =ufshcd_send_uic_cmd (hba, &uic_cmd); -if (ret) +if (ret) {dev_dbg (hba->dev,"%s: attr-id 0x%x error code %d\n" , get,UIC_GET_ATTR_ID (attr_sel), ret); + uic_cmd.argument2 &= ~MASK_UIC_COMMAND_RESULT ; + } }while (ret && peer && --retries);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 703/2214 scsi: libiscsi_tcp: Prevent R2T range check overflow
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratnaker Gautam <[email protected]>
[ Upstream commit eb7aa7fd673fdc1582223cd133bcc5f54e7af19f ]
An iSCSI target controls the R2T data offset and length as 32-bit values. Adding them before comparing the result with the SCSI data buffer length can wrap. An R2T with offset 1 and length U32_MAX then passes the check for a 4096-byte write.
The transmit path treats the wrapped range as valid, exhausts the command scatterlist, and dereferences the NULL next entry in iscsi_tcp_segment_done().
Check the offset first, then compare the length with the remaining bytes in the data buffer.
--- drivers/scsi/libiscsi_tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/libiscsi_tcp.c +2 -1
@@ -608,7 +608,8 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr) data_length, session->max_burst); data_offset =be32_to_cpu (rhdr->data_offset); -if (data_offset + data_length > task->sc->sdb.length) { +if (data_offset > task->sc->sdb.length || + data_length > task->sc->sdb.length - data_offset) { iscsi_conn_printk(KERN_ERR, conn, "invalid R2T with data len %u at offset %u " "and total length %d\n", data_length,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 704/2214 compat: avoid double rounding in times()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 6b30c39a5e333cfb1475acf0f73de6ef954eea8a ]
do_sys_times() already converts CPU time to USER_HZ ticks. The compat path converts each value back to jiffies before converting it to COMPAT_USER_HZ. This round trip can lose precision even when the two userspace rates match.
With HZ=250 and USER_HZ=COMPAT_USER_HZ=100, one user tick becomes two jiffies and then zero compat ticks. Every odd tick count loses one tick, so any of the four tms fields can underreport CPU time by an additional 10 ms.
Return the value directly when the native and compat units match. Keep the existing conversion for differing rates.
--- kernel/sys.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/sys.c +3 -0
@@ -1021,6 +1021,9 @@ SYSCALL_DEFINE1(times, struct tms __user *, tbuf)#ifdef CONFIG_COMPAT static compat_clock_t clock_t_to_compat_clock_t (clock_t x) { +if (USER_HZ ==COMPAT_USER_HZ ) +return x; +return compat_jiffies_to_clock_t (clock_t_to_jiffies (x)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 705/2214 ocfs2: snapshot the dentry name while tracing file release
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 5898987d4a92b70ae73fd8355cc3a388b4dfa4e6 ]
ocfs2_file_release() passes the live dentry name and length to a trace event while holding oi->ip_lock. This lock protects the open count and delays RCU reclamation of external names, but it does not serialize name changes during rename. The dentry can switch between inline and external names, and a separately loaded length can describe a different name.
The ocfs2__file_ops event sizes and copies its __string separately. A concurrently rewritten inline name need not remain consistent between those operations. External names can also be selected at this call site; the existing spinlock critical section protects their allocation lifetime, while a snapshot additionally pairs a stable name with its length.
Take a name snapshot before acquiring oi->ip_lock and release it after dropping the lock. Keep the trace call and open-count argument inside the original critical section. Cache the event-enabled check so the snapshot stays paired even if tracing is toggled meanwhile.
--- fs/ocfs2/file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
fs/ocfs2/file.c +13 -5
@@ -140,18 +140,26 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)static int ocfs2_file_release (struct inode *inode,struct file *file) {struct ocfs2_inode_info *oi =OCFS2_I (inode); +struct dentry *dentry = file->f_path.dentry; +struct name_snapshot name; +bool trace_enabled =trace_ocfs2_file_release_enabled (); + +if (trace_enabled) +take_dentry_name_snapshot (&name, dentry);spin_lock (&oi->ip_lock);if (!--oi->ip_open_count) oi->ip_flags &= ~OCFS2_INODE_OPEN_DIRECT ; -trace_ocfs2_file_release (inode, file, file->f_path.dentry, - oi->ip_blkno, - file->f_path.dentry->d_name.len, - file->f_path.dentry->d_name.name, - oi->ip_open_count); +if (trace_enabled) +trace_ocfs2_file_release (inode, file, dentry, + oi->ip_blkno, name.name.len, + name.name.name, oi->ip_open_count);spin_unlock (&oi->ip_lock); +if (trace_enabled) +release_dentry_name_snapshot (&name); +ocfs2_free_file_private (inode, file);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 706/2214 ocfs2/cluster: remove zero-address nodes from IP tree on teardown
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 5dd57e77eff4ba3e85b3df126a55417c88245708 ]
o2nm_node_ipv4_address_store() accepts 0.0.0.0. It sets O2NM_NODE_ATTR_ADDRESS and links nd_ip_node into cl_node_ip_tree under cl_nodes_lock, but o2nm_node_group_drop_item() uses nd_ipv4_address as a membership test. A zero address therefore leaves the rbtree node linked when config_item_put() releases and frees struct o2nm_node. A later address store or IP lookup can then walk the stale node and dereference freed memory.
During teardown, drop_item takes cl_nodes_lock, skips rb_erase() for the zero key, and then calls config_item_put(). A later o2nm_node_ipv4_address_store() duplicate check or o2nm_get_node_by_ip() lookup takes the same lock and walks the stale cl_node_ip_tree entry. Use O2NM_NODE_ATTR_ADDRESS for teardown so every published nd_ip_node is erased before configfs can release the node, without rejecting 0.0.0.0 or changing lookup semantics.
--- fs/ocfs2/cluster/nodemanager.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/nodemanager.c +5 -2
@@ -625,8 +625,11 @@ static void o2nm_node_group_drop_item(struct config_group *group,write_lock (&cluster->cl_nodes_lock); -/* XXX sloppy */ -if (node->nd_ipv4_address) +/* +* 0.0.0.0 is a valid configured address, so nd_ipv4_address does +* not tell us whether nd_ip_node was published in the IP tree. +*/ +if (test_bit (O2NM_NODE_ATTR_ADDRESS , &node->nd_set_attributes))rb_erase (&node->nd_ip_node, &cluster->cl_node_ip_tree);/* nd_num might be 0 if the node number hasn't been set.. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 707/2214 fbdev: atmel_lcdfb: fix list_first_entry() on possibly empty modelist in probe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wang Haoran <[email protected]>
[ Upstream commit 01d1204582f16e8b7bfce29648e5cf77a585d962 ]
list_first_entry() does not return NULL on an empty list; it returns a bogus pointer computed by container_of() from the list head. atmel_lcdfb_probe() initializes info->modelist with INIT_LIST_HEAD() and later takes its first entry with list_first_entry(), assuming atmel_lcdfb_of_init() populated it. However, atmel_lcdfb_of_init() drops the return value of fb_add_videomode() — unlike every other fallible call in the same function — so if fb_add_videomode() fails (its internal kmalloc can return -ENOMEM under memory pressure or fault injection), the list stays empty while of_init() reports success. The probe path then dereferences the bogus pointer in fb_videomode_to_var(&info->var, &modelist->mode). Because the bogus pointer lands inside the contiguous fb_info allocation, this may not fault immediately; instead it silently reads adjacent memory as a struct fb_videomode and programs garbage timing parameters into the LCD controller. This was found by code audit; we do not have Atmel hardware to reproduce it.
Fix this on two levels: check the return value of fb_add_videomode() in atmel_lcdfb_of_init() so the failure is propagated (root cause), and use list_first_entry_or_null() in atmel_lcdfb_probe() with a NULL check that fails probe gracefully with -EINVAL (defense in depth), consistent with the surrounding error handling which bails out to stop_clk.
--- drivers/video/fbdev/atmel_lcdfb.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/video/fbdev/atmel_lcdfb.c +10 -3
@@ -1032,7 +1032,9 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)if (ret <0 ) goto put_display_node; -fb_add_videomode (&fb_vm, &info->modelist); + ret =fb_add_videomode (&fb_vm, &info->modelist); +if (ret <0 ) + goto put_display_node; put_display_node:of_node_put (display_np);
@@ -1100,8 +1102,13 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev) }atmel_lcdfb_start_clock (sinfo); - modelist =list_first_entry (&info->modelist, - struct fb_modelist, list); + modelist =list_first_entry_or_null (&info->modelist, + struct fb_modelist, list); +if (!modelist) { +dev_err (dev,"no video mode available\n" ); + ret = -EINVAL ; + goto stop_clk; + }fb_videomode_to_var (&info->var, &modelist->mode);atmel_lcdfb_check_var (&info->var, info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 708/2214 timers/itimer: Keep a nonzero value at CPU timer expiry
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit ef60f61208a30eb5b941b707debdf04517271b4f ]
get_cpu_itimer() returns a zero remaining time when the sampled CPU time is exactly equal to the nonzero expiry. This makes an armed ITIMER_VIRTUAL or ITIMER_PROF timer appear disarmed.
The cputime cleanup replaced cputime_le(), which implements <=, with <. Restore the inclusive comparison so the equality case returns TICK_NSEC, like the overdue case and set_process_cpu_timer().
--- kernel/time/itimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/itimer.c +1 -1
@@ -60,7 +60,7 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,thread_group_sample_cputime (tsk, samples); t = samples[clock_id]; -if (val < t) +if (val <= t)/* about to fire */ val =TICK_NSEC ;else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 709/2214 time/namespace: Fix overflow when converting absolute deadlines
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit d69cfd33b5a8d176124c564513b9ceb933595d93 ]
do_timens_ktime_to_host() subtracts the namespace offset from an absolute deadline and clamps the result to [0, KTIME_MAX]. A negative offset can make a large deadline overflow to a negative value. Since ktime_t is signed and KTIME_MAX is its maximum value, the subsequent comparison against KTIME_MAX can never detect this overflow.
For example, with a -1 second boottime offset, an absolute CLOCK_BOOTTIME timerfd deadline of KTIME_MAX can expire immediately. An absolute clock_nanosleep() using the same clock and deadline can also return immediately instead of waiting.
The earlier tim < offset check already handles the lower bound. A negative subtraction result in the remaining branch therefore indicates overflow. Detect that result and clamp it to KTIME_MAX.
--- kernel/time/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/namespace.c +1 -1
@@ -49,7 +49,7 @@ ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim, tim =0 ; }else { tim =ktime_sub (tim, offset); -if (unlikely (tim >KTIME_MAX )) +if (unlikely (tim <0 )) tim =KTIME_MAX ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 710/2214 ceph: avoid pending truncate during nonblocking cap acquire
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Max Kellermann <[email protected]>
[ Upstream commit 979b7ed4457a04c5a41c36f86052ecc6b76c67d9 ]
Readahead acquires caps while the folios are locked. This can deadlock when processing a pending truncate; truncate_pagecache() can then attempt to a folio that is already locked.
Return -EAGAIN instead when NON_BLOCKING is set, causing the readahead to be abandoned.
--- fs/ceph/caps.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ceph/caps.c +4 -0
@@ -2675,6 +2675,10 @@ static int try_get_cap_refs(struct inode *inode, int need, int want, }/* finish pending truncate */ +if (ci->i_truncate_pending && (flags &NON_BLOCKING )) { + ret = -EAGAIN ; + goto out_unlock; + }while (ci->i_truncate_pending) {spin_unlock (&ci->i_ceph_lock);if (snap_rwsem_locked) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 711/2214 ceph: reject mdsmaps that claim more than CEPH_MAX_MDS ranks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit c1742590d2b2fc5fb217e1a9b520108f1fe282e5 ]
check_new_map() sizes its export-target bitmap from CEPH_MAX_MDS but walks it with newmap->possible_max_rank, which comes straight off the wire:ceph_mdsmap_decode() sets it to max(m_num_active_mds, m_max_mds), then overwrites it with the size of the "in" set. Neither is bounded by CEPH_MAX_MDS, only by m_info allocating, so a monitor announcing more ranks than the bitmap holds makes test_bit() read past the end of targets[]. The clear_bit() loop above indexes the same bitmap, though it is additionally bounded by mdsc->max_sessions. The map arrives on the monitor connection, which is unauthenticated in legacy msgr mode.
CEPH_MAX_MDS is a protocol constant from src/mds/mdstypes.h, and the reserved inode ranges in super.h are laid out one rank apart over that span, so a map claiming more ranks is corrupt. Reject it where the rank space is established rather than letting the count reach check_new_map().
BUG: KASAN: stack-out-of-bounds in check_new_map (fs/ceph/mds_client.c:5968) Read of size 8 at addr ffffc90000ac7798 by task kworker/1:2/127 Workqueue: ceph-msgr ceph_con_workfn Call Trace: <TASK> dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120) print_report (mm/kasan/report.c:378 mm/kasan/report.c:482) kasan_report (mm/kasan/report.c:595) kasan_check_range (mm/kasan/generic.c:186 mm/kasan/generic.c:200) check_new_map (fs/ceph/mds_client.c:5968) ceph_mdsc_handle_mdsmap (fs/ceph/mds_client.c:7060) extra_mon_dispatch (fs/ceph/super.c:802) mon_dispatch (net/ceph/mon_client.c:1483) ceph_con_process_message (net/ceph/messenger.c:1424) ceph_con_v1_try_read (net/ceph/messenger_v1.c:1430) ceph_con_workfn (net/ceph/messenger.c:1576) process_one_work (kernel/workqueue.c:3396) worker_thread (kernel/workqueue.c:3479 kernel/workqueue.c:3560) kthread (kernel/kthread.c:436) ret_from_fork (arch/x86/kernel/process.c:158) ret_from_fork_asm (arch/x86/entry/entry_64.S:245) </TASK> The buggy address belongs to stack of task kworker/1:2/127 and is located at offset 288 in frame: check_new_map (fs/ceph/mds_client.c:5846) This frame has 1 object: [32, 288) 'targets'
--- fs/ceph/mdsmap.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ceph/mdsmap.c +8 -0
@@ -167,6 +167,10 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2)* and the mds rank >= m_num_active_mds. */ m->possible_max_rank =max (m->m_num_active_mds, m->m_max_mds); +if (m->possible_max_rank >CEPH_MAX_MDS ) { + err = -EIO ; + goto corrupt; + } m->m_info =kcalloc (m->possible_max_rank,sizeof (*m->m_info),GFP_NOFS );if (!m->m_info)
@@ -315,6 +319,10 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2) {int num_laggy =0 ;ceph_decode_32_safe (p, end, n, bad_ext); +if (n >CEPH_MAX_MDS ) { + err = -EIO ; + goto corrupt; + }ceph_decode_need (p, end,sizeof (u32) * n, bad_ext);for (i =0 ; i < n; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 712/2214 libceph: only set read_from_replica on read requests
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiubo Li <[email protected]>
[ Upstream commit d6c7a5fcd08873c45a2dcd645a0690fd1443af50 ]
ceph_osdc_alloc_request() ORs the mount option's read_from_replica flag into r_flags for every request, writes included. The flag is meant for reads: calc_target() skips the replica choice for any request that has CEPH_OSD_FLAG_WRITE, and the OSDs only know BALANCE_READS on read ops. Sending it on writes is at best ignored; with read_from_replica=balance a buffered write that fell back to ceph_sync_write() after losing BUFFER to a revoke failed with -EIO, while the same run without the option works fine.
Gate the flag on CEPH_OSD_FLAG_READ.
--- net/ceph/osd_client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ceph/osd_client.c +3 -1
@@ -1094,7 +1094,9 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, req->r_base_oloc.pool = layout->pool_id; req->r_base_oloc.pool_ns =ceph_try_get_string (layout->pool_ns);ceph_oid_printf (&req->r_base_oid,"%llx.%08llx" , vino.ino, objnum); - req->r_flags = flags | osdc->client->options->read_from_replica; + req->r_flags = flags; +if (flags &CEPH_OSD_FLAG_READ ) + req->r_flags |= osdc->client->options->read_from_replica; req->r_snapid = vino.snap;if (flags &CEPH_OSD_FLAG_WRITE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 713/2214 libceph: Fix unsafe decode in ceph_redirect_decode()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphael Zimmer <[email protected]>
[ Upstream commit 0405670e50f213594366ab7eddc07002bd7f84c0 ]
ceph_redirect_decode handles unchecked data received over the network from an OSD. Currently, there is only a bounds check covering the first three decode operations. After decoding the first len field from the message, the only remaining check ensures there is enough buffer space to hold len bytes. However, there is no guarantee that this value is large enough to hold the subsequently decoded fields. The decoding of the second len field is missing an explicit bounds check. Consequently, a corrupted message can trigger an out-of-bounds read.
This patch fixes the issue by switching the decoding from ceph_decode_32() to the bounds-checked version ceph_decode_32_safe().
--- net/ceph/osd_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/osd_client.c +1 -1
@@ -3575,7 +3575,7 @@ static int ceph_redirect_decode(void **p, void *end,if (ret) goto out; - len =ceph_decode_32 (p); +ceph_decode_32_safe (p, end, len, e_inval);if (len >0 ) {pr_warn ("ceph_request_redirect::object_name is set\n" ); goto e_inval;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 714/2214 libceph: Fix multiple unsafe decodes in ceph_oloc_decode()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphael Zimmer <[email protected]>
[ Upstream commit 10655007b9b679e46a9e383202c7bb791e5d1d13 ]
ceph_oloc_decode handles unchecked data received over the network from an OSD. Currently, there are multiple decode operations that aren't covered by any bounds check. Decoding these fields can therefore result in out-of-bounds reads if a corrupted message is received.
This patch fixes the issue by adding bounds checks covering all previously uncovered decode operations.
[ idryomov: use ceph_decode_64_safe() for hash ]
--- net/ceph/osd_client.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/ceph/osd_client.c +5 -2
@@ -3503,6 +3503,7 @@ static int ceph_oloc_decode(void **p, void *end,ceph_decode_need (p, end, len, e_inval); struct_end = *p + len; +ceph_decode_need (p, end,8 +4 +4 , e_inval); oloc->pool =ceph_decode_64 (p); *p +=4 ;/* skip preferred */
@@ -3515,7 +3516,7 @@ static int ceph_oloc_decode(void **p, void *end,if (struct_v >=5 ) {bool changed = false; - len =ceph_decode_32 (p); +ceph_decode_32_safe (p, end, len, e_inval);if (len >0 ) {ceph_decode_need (p, end, len, e_inval); if (!oloc->pool_ns ||
@@ -3534,7 +3535,9 @@ static int ceph_oloc_decode(void **p, void *end, }if (struct_v >=6 ) { -s64 hash =ceph_decode_64 (p); +s64 hash; + +ceph_decode_64_safe (p, end, hash, e_inval);if (hash !=-1 ) {pr_warn ("ceph_object_locator::hash is set\n" ); goto e_inval;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 715/2214 libceph: reject mismatched CRUSH weight-set sizes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Hoffmann <[email protected]>
[ Upstream commit d8fc89b5bfe4cb3aebe4c8a818247d11291b841c ]
A CEPH_MSG_OSD_MAP message can contain CRUSH choose args with replacement weight vectors for straw2 buckets. decode_choose_args() validates the optional IDs vector against the referenced bucket, but does not validate the size of any replacement-weight vector.
The CRUSH mapper assumes that each replacement vector has exactly as many entries as the bucket. A zero-length vector for a nonempty bucket makes bucket_straw2_choose() dereference NULL, while a shorter nonzero vector causes an out-of-bounds read. An authenticated monitor or OSD can deliver such a map and crash a kernel client when it performs placement for an ordinary request.
Reject a nonempty collection of weight sets for an absent bucket and require every replacement-weight vector to match its bucket size.
--- net/ceph/osdmap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/ceph/osdmap.c +12 -2
@@ -362,7 +362,9 @@ static int decode_choose_args(void **p, void *end, struct crush_map *c)ceph_decode_32_safe (p, end, num_buckets, e_inval);while (num_buckets--) {struct crush_choose_arg *arg; +struct crush_bucket *bucket;u32 bucket_index; +u32 i;ceph_decode_32_safe (p, end, bucket_index, e_inval);if (bucket_index >= arg_map->size)
@@ -373,10 +375,18 @@ static int decode_choose_args(void **p, void *end, struct crush_map *c)if (ret) goto fail; + bucket = c->buckets[bucket_index];if (arg->ids_size && - (!c->buckets[bucket_index] || - arg->ids_size != c->buckets[bucket_index]->size)) + (!bucket || arg->ids_size != bucket->size)) goto e_inval; + +if (arg->weight_set_size && !bucket) + goto e_inval; + +for (i =0 ; i < arg->weight_set_size; i++) { +if (arg->weight_set[i].size != bucket->size) + goto e_inval; + } }if (!__insert_choose_arg_map (&c->choose_args, arg_map)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 716/2214 ceph: Fix xattr buffer leak in __send_cap()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit e51cf76e7275d1bb5ad2d529bb00feade632dadc ]
__prep_cap() takes a reference on the xattr blob via ceph_buffer_get() and also grabs a reference to the old xattr blob returned by __ceph_build_xattrs_blob(). These references are normally dropped in __send_cap() after the cap message has been sent, but when ceph_msg_new() fails, __send_cap() requeues the cap and returns early without dropping them, leaking both buffers on every allocation failure.
Release arg->old_xattr_buf and arg->xattr_buf on the ceph_msg_new() failure path before returning.
--- fs/ceph/caps.c | 2 ++ 1 file changed, 2 insertions(+)
fs/ceph/caps.c +2 -0
@@ -1450,6 +1450,8 @@ static void __send_cap(struct cap_msg_args *arg, struct ceph_inode_info *ci)spin_lock (&ci->i_ceph_lock);__cap_delay_requeue (arg->session->s_mdsc, ci);spin_unlock (&ci->i_ceph_lock); +ceph_buffer_put (arg->old_xattr_buf); +ceph_buffer_put (arg->xattr_buf);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 717/2214 ceph: Fix mds session leak in __open_export_target_session()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 6c80207392fdb86107d7acbdbf4c86cac38da1af ]
__open_export_target_session() holds a reference on the target session, either from __ceph_lookup_mds_session() or from register_session(), which the caller is expected to drop. When __open_session() fails, the helper returns ERR_PTR(ret) without dropping that reference, leaking one session reference on every open failure.
Drop the session reference before returning the error.
--- fs/ceph/mds_client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/mds_client.c +3 -1
@@ -1417,8 +1417,10 @@ __open_export_target_session(struct ceph_mds_client *mdsc, int target)if (session->s_state ==CEPH_MDS_SESSION_NEW || session->s_state ==CEPH_MDS_SESSION_CLOSING ) { ret =__open_session (mdsc, session); -if (ret) +if (ret) { +ceph_put_mds_session (session);return ERR_PTR (ret); + } }return session;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 718/2214 libceph: fix out-of-bounds reads from repeated CRUSH bucket entries
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 569a9bb1e5615c2b88b8d76f03a4ab82e65a673e ]
decode_choose_arg() assumes that its destination is zero-initialized. Although decode_choose_args() zeroes the argument array, it does not reject a repeated bucket_index and can decode into an already populated entry.
Repeating a bucket with weight_set_size=0 preserves its existing weight_set pointer but clears the count. Placement then reads weight_set[-1].weights and dereferences the resulting pointer.
A malformed monitor OSDMap triggers this during RBD placement:
BUG: KASAN: slab-out-of-bounds in crush_bucket_choose+0xdd1/0xf90 Read of size 8 at addr ffff88800290df70 by task init/75
Reject populated arguments before decoding another entry, so the error path can free their original allocations.
--- net/ceph/osdmap.c | 2 ++ 1 file changed, 2 insertions(+)
net/ceph/osdmap.c +2 -0
@@ -371,6 +371,8 @@ static int decode_choose_args(void **p, void *end, struct crush_map *c) goto e_inval; arg = &arg_map->args[bucket_index]; +if (arg->ids || arg->weight_set) + goto e_inval; ret =decode_choose_arg (p, end, arg);if (ret) goto fail;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 719/2214 ceph: clamp MDS reply result code to the errno range
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuanfu Xie <[email protected]>
[ Upstream commit ec8d583469ed64b4973192a21b5a41c33219721f ]
ceph_mdsc_wait_request() returns the reply head result code of the MDS request to its callers as a plain int errno. The value is a server-controlled u32 and nothing checks that it actually is an errno; several callers pass it straight to ERR_PTR(), e.g. ceph_finish_lookup() on the atomic open path:
err = ceph_mdsc_wait_request(...) /* e.g. +0x50fc00 */ ... if (err) dentry = ERR_PTR(err);
IS_ERR() only recognizes the [-MAX_ERRNO, -1] window, so an out-of-range value is not caught anywhere and survives as a "struct dentry *". On the open path the positive error travels ceph_finish_lookup() -> ceph_atomic_open() -> ERR_PTR() in fs/namei.c's atomic_open() wrapper -> step_into(), which dereferences it as a dentry and oopses (mainline 7.3-rc3-135-g4982d3552a3b, the value in R12 is the server-supplied result):
BUG: KASAN: probably user-memory-access in range [0x000000000050fc00-0x000000000050fc07] RIP: 0010:step_into_slowpath+0x3e3/0xe60 R12: 000000000050fc00 Call Trace: <TASK> ? __pfx_ceph_atomic_open+0x10/0x10 path_openat+0xf41/0x2440 do_file_open+0x228/0x480 do_sys_openat2+0x103/0x1d0 __x64_sys_openat+0x141/0x200 do_syscall_64+0xe8/0x4f0 entry_SYSCALL_64_after_hwframe+0x77/0x79 </TASK>
(0xdffffc00000a1f80 in the full report is the KASAN shadow of 0x50fc00; without KASAN the raw value is read.) Values with the top bit set fare no better: 0xd8000000 sign-extends through the int conversion into the kernel address range and takes a page fault instead.
Clamp the result at the single read and return -EIO for anything outside the errno range, which is what a malformed reply means there. net/9p does the same to server errno values with safe_errno(). This is the path the reported crash takes; the other readers of head->result, including the ceph_async_create_cb() and ceph_async_unlink_cb() callbacks, are not covered by this patch.
Each of the six crashing opens was run on a build of 7.3-rc3-135-g4982d3552a3bf with only this change applied: it crashes the unpatched kernel on the first openat() (verified on the same tree without the patch), and with the patch the open fails cleanly without an oops. A few hundred normal file operations on the patched kernel also completed without a crash; valid errno values pass through unchanged.
--- fs/ceph/mds_client.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ceph/mds_client.c +8 -0
@@ -3083,6 +3083,14 @@ static int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc,/* only abort if we didn't race with a real reply */ if (test_bit (CEPH_MDS_R_GOT_RESULT , &req->r_req_flags)) { err =le32_to_cpu (req->r_reply_info.head->result); +if (err >0 || err < -MAX_ERRNO ) { +/* +* The result is server-controlled. Values outside +* the errno range are turned into bogus pointers by +* the ERR_PTR() users among the callers. +*/ + err = -EIO ; + } }else if (err <0 ) {dout ("aborted request %lld with %d\n" , req->r_tid, err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 720/2214 ceph: bound name skips in ceph_mdsmap_decode() by the message end
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: sung byeongchan <[email protected]>
[ Upstream commit 7f702e1703c9648fcb02a217d66c880d00417150 ]
ceph_mdsmap_decode() reads two remote u32 name lengths and advances its parser cursor without checking that either string remains in the message. On a 32-bit client, a sufficiently large length can wrap the cursor below end. The following numerical bounds check then succeeds and dereferences the wrapped address.
Use ceph_decode_skip_n() for both names so the remaining bytes are checked before the cursor advances.
The issue produced a page fault in ceph_mdsmap_decode twice on the tested i386 baseline. The same frame was rejected without a fault twice after this change, while a normal MDSMap continued to be accepted.
--- fs/ceph/mdsmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/mdsmap.c +2 -2
@@ -206,7 +206,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2)ceph_decode_need (p, end,sizeof (u64) +sizeof (u32), bad); *p +=sizeof (u64); namelen =ceph_decode_32 (p);/* skip mds name */ - *p += namelen; +ceph_decode_skip_n (p, end, namelen, bad);ceph_decode_32_safe (p, end, mds, bad);ceph_decode_32_safe (p, end, inc, bad);
@@ -224,7 +224,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2) laggy = laggy_since.tv_sec !=0 || laggy_since.tv_nsec !=0 ; *p +=sizeof (u32);ceph_decode_32_safe (p, end, namelen, bad); - *p += namelen; +ceph_decode_skip_n (p, end, namelen, bad);if (info_v >=2 ) {ceph_decode_32_safe (p, end, num_export_targets, bad); export_targets_len = size_mul(num_export_targets,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 721/2214 ceph: validate encoded xattr name lengths
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: sung byeongchan <[email protected]>
[ Upstream commit 166375898d29fea050a9abec855da6075050d5c9 ]
__build_xattrs() advances over an MDS-provided name length before checking that the name remains in the encoded xattr blob. On 32-bit clients, UINT_MAX wraps the cursor and is stored as a negative internal name length. A later ordinary listxattr() converts it back to a UINT_MAX memcpy size and corrupts kernel memory.
Check the name range before advancing and reject name, value, or aggregate sizes that overflow the signed internal accounting.
The malformed blob corrupted kernel state in two baseline boots. It was rejected cleanly twice with this change, while normal and length-only controls remained safe.
--- fs/ceph/xattr.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/ceph/xattr.c +10 -0
@@ -11,6 +11,7 @@#include <linux/security.h> #include <linux/posix_acl_xattr.h> #include <linux/slab.h> +#include <linux/overflow.h> #define XATTR_CEPH_PREFIX "ceph."#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
@@ -806,14 +807,23 @@ static int __build_xattrs(struct inode *inode) } err = -EIO ;while (numattr--) { +int names_size, vals_size; +ceph_decode_32_safe (&p, end, len, bad); namelen = len; name = p; +ceph_decode_need (&p, end, namelen, bad); p += len;ceph_decode_32_safe (&p, end, len, bad);ceph_decode_need (&p, end, len, bad); val = p; p += len; +if (namelen >INT_MAX || len >INT_MAX || +check_add_overflow (ci->i_xattrs.names_size, + (int )namelen, &names_size) || +check_add_overflow (ci->i_xattrs.vals_size, + (int )len, &vals_size)) + goto bad; err =__set_xattr (ci, name, namelen, val, len,0 ,0 , &xattrs[numattr]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 722/2214 ASoC: qcom: qdsp6: q6afe: fix clk vote response type mismatch
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Val Packett <[email protected]>
[ Upstream commit f3c7bee984aa0ba2b48a44e16a6f3ec2c27f851e ]
The response sent by the firmware when requesting a clock vote (opcode AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST) does not actually have the same opcode + status payload as APR_BASIC_RSP_RESULT. Rather, it returns one single u32 which is the client_handle that must be used in future unvote requests for the same clock.
As a result of this type confusion, the status returned by the callback to q6afe_vote_lpass_core_hw was actually an out-of-bounds read. It was only interpreted as success (0) most of the time due to luck, but there are some reports of random errors such as:
[ 20.961100] qcom-q6afe aprsvc:service:4:4: AFE failed to vote (3) [ 20.961131] Failed to prepare clk 'core': -110
Fix by correctly interpreting the response as a single u32, and actually store it as the client_handle to ensure unvote would work correctly.
--- sound/soc/qcom/qdsp6/q6afe.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
sound/soc/qcom/qdsp6/q6afe.c +8 -2
@@ -369,6 +369,7 @@ struct q6afe {struct q6core_svc_api_info ainfo;struct mutex lock;struct aprv2_ibasic_rsp_result_t result; +uint32_t vote_result;wait_queue_head_t wait;struct list_head port_list;spinlock_t port_list_lock;
@@ -873,13 +874,14 @@ static int q6afe_callback(struct apr_device *adev, struct apr_resp_pkt *data)struct aprv2_ibasic_rsp_result_t *res;struct apr_hdr *hdr = &data->hdr;struct q6afe_port *port; +uint32_t *vote_res;if (!data->payload_size)return 0 ; - res = data->payload;switch (hdr->opcode) {case APR_BASIC_RSP_RESULT : { + res = data->payload;if (res->status) {dev_err (afe->dev,"cmd = 0x%x returned error = 0x%x\n" , res->opcode, res->status);
@@ -906,8 +908,10 @@ static int q6afe_callback(struct apr_device *adev, struct apr_resp_pkt *data) }break ;case AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST : + vote_res = data->payload; afe->result.opcode = hdr->opcode; - afe->result.status = res->status; + afe->result.status =0 ; + afe->vote_result = *vote_res;wake_up (&afe->wait);break ;default :
@@ -1721,6 +1725,8 @@ int q6afe_vote_lpass_core_hw(struct device *dev, uint32_t hw_block_id, AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST);if (ret)dev_err (afe->dev,"AFE failed to vote (%d)\n" , hw_block_id); +else + *client_handle = afe->vote_result;kfree (pkt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 723/2214 net: usb: pegasus: check rx pkt_len against the received length
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Jie Law <[email protected]>
[ Upstream commit efee699f6de06611234ef9b0abd52db1340e5452 ]
read_bulk_callback() takes the frame length from the device, from the receive header on the 0x8513 and from the trailing status bytes on the other chips, and only checks it against PEGASUS_MTU before passing that many bytes up the stack. In two cases the stack then uses bytes that the device did not send:
- A device that sends a short transfer but claims a long frame gets the stale or uninitialized remainder of the receive skb delivered as packet data.
- A device that claims a frame shorter than an Ethernet header gets past the check as well. eth_type_trans() takes pkt_type from h_dest and the protocol from h_proto without checking skb->len. If the transfer is also short, those come from bytes left in the skb by an earlier transfer, or from uninitialized memory.
Drop frames shorter than ETH_HLEN, and frames whose claimed length, plus the 0x8513 header, does not fit in the bytes actually received, and count them as length errors. urb->actual_length never exceeds the PEGASUS_MTU sized transfer buffer, so this also covers the existing PEGASUS_MTU check. Valid Ethernet frames are at least 60 bytes long without the FCS, so they are not affected.
Found by code review with LLM assistance. With an emulated USB device, a 101-byte transfer claiming a 1500-byte frame was passed up as a 1500-byte packet before this change and is dropped after it, and frames claiming 0, 4 and 13 bytes were passed up and are now dropped and counted in rx_length_errors. The extra bytes happened to be zero in the first test, so disclosure of actual kernel data was not demonstrated.
--- drivers/net/usb/pegasus.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/usb/pegasus.c +9 -3
@@ -531,11 +531,17 @@ static void read_bulk_callback(struct urb *urb) }/* -* If the packet is unreasonably long, quietly drop it rather than -* kernel panicing by calling skb_put. +* Drop frames shorter than an Ethernet header, because +* eth_type_trans() reads the header whatever the length, and frames +* longer than what was actually received. Passing either up would +* expose stale buffer contents, and skb_put() could panic on the +* latter. count is at most PEGASUS_MTU. */ -if (pkt_len >PEGASUS_MTU - rx_offset) +if (pkt_len <ETH_HLEN || pkt_len + rx_offset > count) { + net->stats.rx_errors++; + net->stats.rx_length_errors++; goto goon; + }/* * at this point we are sure pegasus->rx_skb != NULL
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 724/2214 bonding: fix out-of-bounds read of arp_ip_target
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit a81513bf5bdf29cf00c0a11f56be515c1ec260f4 ]
arp_ip_target is a module parameter array with BOND_MAX_ARP_TARGETS entries. In the loop parsing it in bond_check_params(), arp_ip_count is the number of accepted targets, while i is the index into arp_ip_target. Invalid and duplicate entries are skipped without bumping arp_ip_count, so bounding the loop with arp_ip_count lets i run past the end of arp_ip_target, e.g. 16 targets with one duplicate:
BUG: KASAN: global-out-of-bounds in bond_check_params.constprop.0+0x1148/0x1440 Read of size 8 at addr ffffffff96e9ee00 by task swapper/0/1 Call Trace: <TASK> dump_stack_lvl+0x91/0xf0 print_report+0xd1/0x630 kasan_report+0xf3/0x130 __asan_report_load8_noabort+0x14/0x30 bond_check_params.constprop.0+0x1148/0x1440 bonding_init+0x13/0xe0 do_one_initcall+0xe7/0x5b0 kernel_init_freeable+0xa91/0x1120 kernel_init+0x24/0x220 ret_from_fork+0x5b3/0x820 ret_from_fork_asm+0x1a/0x30 </TASK> The buggy address belongs to the variable: arp_ip_target+0x80/0xa0
Bound the loop with i instead. arp_ip_count never exceeds i, so it stays within BOND_MAX_ARP_TARGETS too.
--- drivers/net/bonding/bond_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_main.c +1 -1
@@ -5757,7 +5757,7 @@ static int bond_check_params(struct bond_params *params) }for (arp_ip_count =0 , i =0 ; - (arp_ip_count <BOND_MAX_ARP_TARGETS ) && arp_ip_target[i]; i++) { + (i <BOND_MAX_ARP_TARGETS ) && arp_ip_target[i]; i++) {__be32 ip;/* not a complete check, but good enough to catch mistakes */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 725/2214 ipmr: fully initialize the synthetic IP header in ipmr_get_route()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 134351edc28e083c61012b6c69e8e54dd7fa5bcc ]
For an unresolved multicast route query, ipmr_get_route() builds a synthetic IP header in the headroom obtained from skb_realloc_headroom(), which does not zero the memory it allocates. Only a few fields are initialized, leaving others as stale heap contents.
ipmr_cache_report() copies this header into the IGMPMSG_NOCACHE report that is queued to the mroute socket, so a recvmsg() on that socket leaks the uninitialized bytes to user space: the 'tos' field [1] and the 'id' and 'frag_off' fields [2].
Fix by zeroing the IP header before filling in the few fields that are used, so that the entire header is initialized, as in ip6mr_get_route().
[1]
BUG: KMSAN: kernel-infoleak in _copy_to_iter raw_recvmsg
Uninit was stored to memory at:
ipmr_cache_report
ipmr_cache_unresolved
ipmr_get_route
Uninit was created at:
pskb_expand_head
skb_realloc_headroom
ipmr_get_route
Byte 1 of 28 is uninitialized
[2]
BUG: KMSAN: kernel-infoleak in _copy_to_iter raw_recvmsg
Uninit was stored to memory at:
ipmr_cache_report
ipmr_cache_unresolved
ipmr_get_route
Uninit was created at:
pskb_expand_head
skb_realloc_headroom
ipmr_get_route
Bytes 4-7 of 28 are uninitialized
--- net/ipv4/ipmr.c | 1 + 1 file changed, 1 insertion(+)
net/ipv4/ipmr.c +1 -0
@@ -2283,6 +2283,7 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb,skb_push (skb2,sizeof (struct iphdr ));skb_reset_network_header (skb2); iph =ip_hdr (skb2); +memset (iph,0 ,sizeof (*iph)); iph->ihl =sizeof (struct iphdr ) >>2 ; iph->saddr = saddr; iph->daddr = daddr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 726/2214 ALSA: hda: Reject codec reset on ASoC (ext_ops) buses
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 a4311e9447bbb219044db38897f95be112f46a8a ]
Writing to the reconfig or clear sysfs nodes of a codec handled by ASoC (SOF via hdac_hda, AVS via codecs/hda) hangs the writer.
snd_hda_codec_reset() sets card->shutdown and calls device_release_driver(). With ext_ops the driver unbind unregisters the ASoC component, which unbinds and frees the whole ASoC card:
- snd_card_disconnect() returns early as card->shutdown is already set, so the card's child devices are not removed and snd_card_free() waits for the card release forever.
- Even without that, freeing the card removes the codec's hwdep device, which owns the sysfs node the reset was issued from, deadlocking in kernfs while waiting for the active write to finish.
The legacy HDA driver keeps the card across a driver rebind, ASoC does not, so the reset cannot be supported there. Return -EOPNOTSUPP and skip the misleading "codec is being used" messages in the callers.
--- sound/pci/hda/hda_codec.c | 6 ++++++ sound/pci/hda/hda_sysfs.c | 4 ++++ 2 files changed, 10 insertions(+)
sound/pci/hda/hda_codec.c +6 -0
@@ -1812,6 +1812,12 @@ int snd_hda_codec_reset(struct hda_codec *codec) {struct hda_bus *bus = codec->bus; +/* ASoC: driver unbind frees the card, incl. the hwdep issuing the reset */ +if (bus->core.ext_ops) { +codec_err (codec,"Codec reset is not supported with ASoC\n" ); +return -EOPNOTSUPP ; + } +if (snd_hda_lock_devices (bus) <0 )return -EBUSY ;
sound/pci/hda/hda_sysfs.c +4 -0
@@ -119,6 +119,8 @@ static int clear_codec(struct hda_codec *codec)int err; err =snd_hda_codec_reset (codec); +if (err == -EOPNOTSUPP ) +return err;if (err <0 ) {codec_err (codec,"The codec is being used, can't free.\n" );return err;
@@ -134,6 +136,8 @@ static int reconfig_codec(struct hda_codec *codec)snd_hda_power_up (codec);codec_info (codec,"hda-codec: reconfiguring\n" ); err =snd_hda_codec_reset (codec); +if (err == -EOPNOTSUPP ) +return err;if (err <0 ) {codec_err (codec,"The codec is being used, can't reconfigure.\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 727/2214 ixgbe: reserve TX timestamp after skb preparation
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 f75062536e2d45ee182828f0e47e0124be2fdc8d ]
ixgbe_xmit_frame_ring() takes an extra skb reference with skb_get() for the pending TX timestamp before preparing the skb for transmit. Several of the following steps may need to reallocate the skb head:
- ixgbe_tso() calls skb_cow_head(), which reaches pskb_expand_head() when the header is cloned (e.g. a packet tap holds a clone).
- ixgbe_tx_csum() falls back to skb_checksum_help() for unsupported checksum offsets, which can call pskb_expand_head() through skb_ensure_writable().
- With DCB and a software VLAN tag, skb_cow_head() is called to rewrite the VLAN priority.
pskb_expand_head() used to BUG() on shared skbs. Since commit c7d8bc3dd511 ("net: skbuff: don't BUG() on bad arguments to pskb_expand_head()") it returns -EINVAL instead, so these packets are dropped (TSO, DCB) or sent with an unfinished checksum (skb_checksum_help() errors are ignored by ixgbe_tx_csum()).
Reserve the TX timestamp right before ixgbe_tx_map(), after all skb preparation, as i40e and ice already do. The timestamp request remains covered on the FCoE path, and the cleanup on ixgbe_tx_map() failure is unchanged.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +23 -17
@@ -8654,23 +8654,6 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, } protocol =vlan_get_protocol (skb); -if (unlikely (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) && - adapter->ptp_clock) { -if (adapter->tstamp_config.tx_type ==HWTSTAMP_TX_ON && - !test_and_set_bit_lock (__IXGBE_PTP_TX_IN_PROGRESS, - &adapter->state)) { -skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; - tx_flags |=IXGBE_TX_FLAGS_TSTAMP ; - -/* schedule check for Tx timestamp */ - adapter->ptp_tx_skb =skb_get (skb); - adapter->ptp_tx_start = jiffies; -schedule_work (&adapter->ptp_tx_work); - }else { - adapter->tx_hwtstamp_skipped++; - } - } -#ifdef CONFIG_PCI_IOV /* * Use the l2switch_enable flag - would be false if the DMA
@@ -8735,6 +8718,29 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,#ifdef IXGBE_FCOE xmit_fcoe:#endif /* IXGBE_FCOE */ +/* Reserve the Tx timestamp only after all skb preparation: +* skb_get() makes the skb shared, and pskb_expand_head() +* (reached from skb_cow_head() or skb_checksum_help()) +* refuses shared skbs. +*/ +if (unlikely (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) && + adapter->ptp_clock) { +if (adapter->tstamp_config.tx_type ==HWTSTAMP_TX_ON && + !test_and_set_bit_lock (__IXGBE_PTP_TX_IN_PROGRESS, + &adapter->state)) { +skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; + tx_flags |=IXGBE_TX_FLAGS_TSTAMP ; + first->tx_flags |=IXGBE_TX_FLAGS_TSTAMP ; + +/* schedule check for Tx timestamp */ + adapter->ptp_tx_skb =skb_get (skb); + adapter->ptp_tx_start = jiffies; +schedule_work (&adapter->ptp_tx_work); + }else { + adapter->tx_hwtstamp_skipped++; + } + } +if (ixgbe_tx_map (tx_ring, first, hdr_len)) goto cleanup_tx_timestamp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 728/2214 ASoC: hdac_hda: Balance the runtime PM disable in codec remove
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 f26c0d5f91d918bb66cbbc8916f41836adb38346 ]
hdac_hda_codec_remove() disables runtime PM of the codec device before releasing the HDA link and calling the codec driver's remove callback, so that no runtime resume can race with the teardown and access the link or the already freed codec driver data. snd_hda_codec_cleanup_for_unbind() then disables runtime PM again.
On the next probe snd_hda_codec_register() enables runtime PM only once, leaving it disabled after the ASoC card or the codec driver has been unbound and bound again: the codec stays powered and runtime_status reads 'unsupported'.
Re-enable runtime PM at the end of hdac_hda_codec_remove() to balance its own disable. The codec remains disabled until it is registered again.
--- sound/soc/codecs/hdac_hda.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/soc/codecs/hdac_hda.c +4 -0
@@ -520,6 +520,7 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component)return ; } +/* prevent runtime PM callbacks while the link and the codec are torn down */ pm_runtime_disable (&hdev->dev);snd_hdac_ext_bus_link_put (hdev->bus, hlink);
@@ -527,6 +528,9 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component) codec->patch_ops.free (codec);snd_hda_codec_cleanup_for_unbind (codec); + +/* Balances the disable above, cleanup_for_unbind keeps runtime PM disabled */ +pm_runtime_enable (&hdev->dev); }static const struct snd_soc_dapm_route hdac_hda_dapm_routes[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 729/2214 cpufreq: stats: Fix potential out-of-bounds access in deferred reset
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhongqiu Han <[email protected]>
[ Upstream commit 8a702989677216489e471a6f27599da53f753567 ]
cpufreq_stats_create_table() sets stats->last_index to -1 if policy->cur is not in the frequency table. It then stays at -1, because cpufreq_stats_record_transition() returns early on old_index == -1 before it gets to update last_index.
Commit 46a310b80bc2 ("[CPUFREQ] Don't set stat->last_index to -1 if the pol->cur has incorrect value.") added that check. However, since commit 40c3bd4cfa6f ("cpufreq: stats: Defer stats update to cpufreq_stats_record_transition()"), the stats reset is deferred to the beginning of cpufreq_stats_record_transition(), before that check, and cpufreq_stats_reset_table() ends with an unconditional cpufreq_stats_update(). So if the "reset" attribute is written while last_index is -1, the next frequency transition accesses time_in_state[-1].
Fix it by also returning early on last_index == -1 in cpufreq_stats_reset_table().
--- drivers/cpufreq/cpufreq_stats.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/cpufreq/cpufreq_stats.c +4 -0
@@ -52,6 +52,10 @@ static void cpufreq_stats_reset_table(struct cpufreq_stats *stats)* reset_pending accesses in cpufreq_stats_record_transition(). */ smp_rmb (); + +if (stats->last_index ==-1 ) +return ; +cpufreq_stats_update (stats,READ_ONCE (stats->reset_time)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 730/2214 drm/amd/display: take a runtime PM reference only when a CRTC turns on
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luigi Lauro <[email protected]>
[ Upstream commit b456f591f925fbd6b33770d0eec1b51c2f9d41c1 ]
amdgpu_dm_commit_streams() takes a runtime PM reference for every active CRTC that needs a modeset and has a new stream, but amdgpu_dm_atomic_commit_tail() drops one only for each CRTC that goes from active to inactive. A modeset of a CRTC that is already active (a mode change, or anything else that needs a full modeset) therefore leaks one reference. Once that has happened, the usage count no longer returns to zero with every CRTC off, and the device cannot runtime suspend again until reboot. The two also disagree the other way when a CRTC turns on without a stream ("Failed to create new stream"): no reference is taken, but one is dropped when it turns off.
Take the reference in the loop that counts the disabled CRTCs, on the mirror condition: when the CRTC goes from inactive to active, which is what the commit that added it intended ("every time we enable a previously disabled CRTC"). Each active CRTC then holds exactly one reference.
Tested on an RX 9070 XT (Navi 48) over OCuLink, with the change backported to 7.2.9: an unplugged connector forced on, then mode A on a CRTC, mode B on the same active CRTC, and the CRTC off, three rounds in a row. The usage count rose by 3 with the stock module, by 0 with this patch, and by 3 again after reloading the stock module.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7 -4
@@ -9640,8 +9640,6 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)if (dm_old_crtc_state->stream)remove_stream (adev, acrtc, dm_old_crtc_state->stream); -pm_runtime_get_noresume (dev->dev); - acrtc->enabled = true; acrtc->hw_mode = new_crtc_state->mode; crtc->hwmode = new_crtc_state->mode;
@@ -9911,8 +9909,13 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)struct crc_rd_work *crc_rd_wrk;#endif #endif -/* Count number of newly disabled CRTCs for dropping PM refs later. */ -if (old_crtc_state->active && !new_crtc_state->active) +/* +* One runtime PM reference per active CRTC: take it when the +* CRTC turns on, count it when it turns off for dropping later. +*/ +if (!old_crtc_state->active && new_crtc_state->active) +pm_runtime_get_noresume (dev->dev); +else if (old_crtc_state->active && !new_crtc_state->active) crtc_disable_count++; dm_new_crtc_state =to_dm_crtc_state (new_crtc_state);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 731/2214 drm/amdkfd: validate SRAT subtables before parsing
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 9866cb13ba4d39aa8fed34b765d4aecabe04f02e ]
The KFD SRAT walker reads the first subtable length without checking that a header is present and trusts subsequent lengths when accessing CPU and generic affinity records. Invalid firmware lengths can therefore cause out-of-bounds reads.
Validate the table header, every generic subtable range, and each supported typed record before reading its fields.
--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 35 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +24 -11
@@ -1893,27 +1893,33 @@ static void kfd_find_numa_node_in_srat(struct kfd_dev *kdev)return ; } +if (table_header->length <sizeof (struct acpi_table_srat )) + goto invalid_srat; + table_end = (unsigned long )table_header + table_header->length;/* Parse all entries looking for a match. */ sub_header = (struct acpi_subtable_header *) ((unsigned long )table_header +sizeof (struct acpi_table_srat )); - subtable_len = sub_header->length; -while (((unsigned long )sub_header) + subtable_len < table_end) { -/* -* If length is 0, break from this loop to avoid -* infinite loop. -*/ -if (subtable_len ==0 ) { -pr_err ("SRAT invalid zero length\n" ); -break ; - } +while ((unsigned long )sub_header < table_end) { +unsigned long start = (unsigned long )sub_header; + +if (table_end - start <sizeof (*sub_header)) + goto invalid_srat; + + subtable_len = sub_header->length; +if (subtable_len <sizeof (*sub_header) || + subtable_len > table_end - start) + goto invalid_srat;switch (sub_header->type) {case ACPI_SRAT_TYPE_CPU_AFFINITY : cpu = (struct acpi_srat_cpu_affinity *)sub_header; +if (subtable_len <sizeof (*cpu)) + goto invalid_srat; + pxm = *((u32 *)cpu->proximity_domain_hi) <<8 | cpu->proximity_domain_lo;if (pxm > max_pxm)
@@ -1921,6 +1927,9 @@ static void kfd_find_numa_node_in_srat(struct kfd_dev *kdev)break ;case ACPI_SRAT_TYPE_GENERIC_AFFINITY : gpu = (struct acpi_srat_generic_affinity *)sub_header; +if (subtable_len <sizeof (*gpu)) + goto invalid_srat; + bdf = *((u16 *)(&gpu->device_handle[0 ])) <<16 | *((u16 *)(&gpu->device_handle[2 ]));if (bdf == pci_id) {
@@ -1937,9 +1946,13 @@ static void kfd_find_numa_node_in_srat(struct kfd_dev *kdev) sub_header = (struct acpi_subtable_header *) ((unsigned long )sub_header + subtable_len); - subtable_len = sub_header->length; } + goto out; + +invalid_srat: +pr_err ("SRAT contains an invalid subtable\n" ); +out:acpi_put_table (table_header);/* Workaround bad cpu-gpu binding case */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 732/2214 macvlan: fix passthru promiscuity accounting while down
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xia Yan <[email protected]>
[ Upstream commit b6743653d134c9ef8436e2db1be1ad4c1e0d0091 ]
macvlan_changelink() adjusts the lower device's promiscuity count when NOPROMISC changes, even if the passthru macvlan is down. The reference is acquired in macvlan_open() and released in macvlan_stop(), so a down interface has no reference to change.
Clearing NOPROMISC while down leaves an extra reference after the next open/stop cycle. Setting it while down can remove a reference held by another user of the lower device.
Guard the count adjustment with netif_running(dev). Keep storing the requested flags while down so the next open uses the new setting.
Comparing changelink with open/stop exposed the unmatched count changes; the same issue was also described in earlier macvlan reviews. A netlink test on UML reproduced both DOWN cases before the fix and verified the expected counts afterwards. Repeated flag updates, two open/stop cycles, deletion and bidirectional small-frame delivery were also checked.
Full x86_64 builds completed with WERROR disabled for allmodconfig, and WERROR and KASAN disabled for allyesconfig, including the resulting dependency changes. Neither comparison showed new diagnostics.
--- drivers/net/macvlan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/macvlan.c +2 -1
@@ -1590,7 +1590,8 @@ static int macvlan_changelink(struct net_device *dev,if (data && data[IFLA_MACVLAN_FLAGS ]) {__u16 flags =nla_get_u16 (data[IFLA_MACVLAN_FLAGS ]);bool promisc = (flags ^ vlan->flags) &MACVLAN_FLAG_NOPROMISC ; -if (macvlan_passthru (vlan->port) && promisc) { +if (macvlan_passthru (vlan->port) && promisc && +netif_running (dev)) {int err;if (flags &MACVLAN_FLAG_NOPROMISC )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 733/2214 net: hisilicon: hisi_femac: Stop the receiver before releasing the RX ring
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Yang <[email protected]>
[ Upstream commit d54b21d824302af52d06574870817fbe14774dab ]
hisi_femac_net_close() frees the receive ring while the RX address queue still holds every address that was pushed to IQ_ADDR.
A port that keeps receiving then DMAs arrived frames into buffers that other slab caches have already taken back; on an EC6108V9C (hi3798mv100) the queue still held all 52 armed addresses right after the interface was closed, and had dropped to 43 after 15 s of broadcast traffic.
Reset the port before the buffers are released, so that the receiver no longer holds any of their addresses.
--- drivers/net/ethernet/hisilicon/hisi_femac.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/hisilicon/hisi_femac.c +1 -0
@@ -491,6 +491,7 @@ static int hisi_femac_net_close(struct net_device *dev)netif_stop_queue (dev);napi_disable (&priv->napi); +hisi_femac_port_reset (priv);hisi_femac_free_skb_rings (priv);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 734/2214 fs/ntfs3: bound CreateAttribute asize against record_size in do_action
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyeontae Lee <[email protected]>
[ Upstream commit fb0f0ef7b5a6bc761b372ce00764d4b6e0b91a47 ]
In do_action()'s CreateAttribute case (fslog.c:3286), attr2 points into the on-disk log record and asize = le32_to_cpu(attr2->size) is therefore attacker-controlled on mount. The guard bounds asize only against the log record itself,
Add2Ptr(attr2, asize) > Add2Ptr(lrh, rec_len)
where rec_len is the client data length, and separately bounds dlen against the MFT record. Nothing bounds asize against record_size, but all three writes that follow are into rec, a kmalloc(sbi->record_size) buffer allocated by mi_init() (record.c:105):
memmove(Add2Ptr(attr, asize), attr, used - roff); memcpy(attr, attr2, asize); rec->used = cpu_to_le32(used + asize);
With record_size 0x400, roff 0x38, used 0x160 and asize 0x800 the memcpy writes 2048 bytes at rec + 0x38, 0x438 bytes past the allocation, and rec->used is left at 0x960. dlen is 0x18 here, so the existing dlen check passes: dlen bounds nothing about the size of the copy.
The equivalent non-replay path already refuses this. mi_insert_attr() performs the same insert and starts with (record.c:488):
if (used + asize > sbi->record_size) return NULL;
Apply the same bound, spelled as a subtraction to match the neighbouring clause. used <= record_size holds here because check_file_record() validates it (fslog.c:2826) and is called on this record at fslog.c:3172; roff <= used - 4 follows from check_if_attr() together with the ATTR_END check at fslog.c:2844, so bounding used + asize bounds both copies.
The sibling WriteEndOfFileRecordSegment case does the equivalent check against record_size at fslog.c:3277.
Reproduced by mounting a crafted image on v7.2-rc5 under KASAN:
BUG: KASAN: slab-out-of-bounds in do_action.isra.0+0x41f6/0x83a0 Write of size 2048 at addr ffff888005c74838 by task mount/69 CPU: 0 UID: 0 PID: 69 Comm: mount Not tainted 7.2.0-rc5-00300-g8ba098e6b6ff #2 Call Trace: kasan_report+0xce/0x100 kasan_check_range+0x105/0x1b0 __asan_memcpy+0x3c/0x60 do_action.isra.0+0x41f6/0x83a0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 get_tree_bdev_flags+0x2ef/0x550 vfs_get_tree+0x82/0x2f0 fc_mount+0x10/0x1b0 path_mount+0x517/0x1df0 __x64_sys_mount+0x20b/0x270 do_syscall_64+0xf9/0x540 entry_SYSCALL_64_after_hwframe+0x77/0x7f Allocated by task 69: __kasan_kmalloc+0x8f/0xa0 __kmalloc_noprof+0x1b4/0x460 mi_init+0x81/0x110 mi_get+0x6a/0x220 do_action.isra.0+0x1db4/0x83a0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 The buggy address belongs to the object at ffff888005c74800 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 56 bytes inside of allocated 1024-byte region [ffff888005c74800, ffff888005c74c00)
--- fs/ntfs3/fslog.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/ntfs3/fslog.c +6 -1
@@ -3307,10 +3307,15 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe, asize =le32_to_cpu (attr2->size); used =le32_to_cpu (rec->used); +/* +* attr2->size is taken from the log record and is bounded only +* by the log record length, not by the MFT record. Refuse an +* attribute that does not fit, as mi_insert_attr() does. +*/ if (!check_if_attr (rec, lrh) || dlen <SIZEOF_RESIDENT || !IS_ALIGNED (asize,8 ) ||Add2Ptr (attr2, asize) >Add2Ptr (lrh, rec_len) || - dlen > record_size - used) { + dlen > record_size - used || asize > record_size - used) { goto dirty_vol; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 735/2214 fs/ntfs3: bound DeleteAttribute asize against rec->used in do_action
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyeontae Lee <[email protected]>
[ Upstream commit 408216b66afd9ddadaba2dce56fd4af6793e95a2 ]
In do_action()'s DeleteAttribute case (fslog.c:3316), attr is Add2Ptr(rec, roff) with roff taken from the on-disk lrh->record_off, and asize = le32_to_cpu(attr->size) is read straight out of the MFT record:
asize = le32_to_cpu(attr->size); used = le32_to_cpu(rec->used); if (!check_if_attr(rec, lrh)) goto dirty_vol; ... memmove(attr, Add2Ptr(attr, asize), used - asize - roff);
check_if_attr() (fslog.c:2869) walks the attribute chain from rec->attr_off and returns o == ro. Its loop breaks on ATTR_END, so ro may legitimately equal the offset of the ATTR_END marker; that is exactly how CreateAttribute appends to a record. But check_file_record()'s walk (fslog.c:2831) also stops at ATTR_END, so check_attr() never inspects the bytes there. When roff is the ATTR_END offset, those never-validated bytes are what gets read as attr->size, and used - asize - roff underflows.
The read itself is also unbounded: roff is a u16 and attr->size is dereferenced at fslog.c:3317, before check_if_attr() has constrained roff at all, so it can be up to ~64K past a record_size-sized object.
Commit 0ca0485e4b2e ("fs/ntfs3: validate rec->used in journal-replay file record check") added at fslog.c:2844
if (used < PtrOffset(rec, attr) + sizeof(attr->type)) return false;
and its changelog names this very memmove. It bounds rec->used against the ATTR_END offset; it does not bound asize. With record_size 0x400, attr_off 0x38, a valid three-attribute chain ending in ATTR_END at 0x158 and used 0x160, a record whose four bytes at 0x15c read 0x100 gives
used - asize - roff = 0x160 - 0x100 - 0x158 = 0xffffff08
i.e. a ~4 GiB memmove whose source and destination both run off the end of rec, a kmalloc(sbi->record_size) object (record.c:105).
The equivalent non-replay path already refuses this. mi_remove_attr() performs the same removal and starts with (record.c:548):
if (aoff + asize > used) return false;
Apply the same bound, spelled as a subtraction to match the neighbouring cases, and move the attr->size read after check_if_attr() so that the header is known to lie inside the record before it is dereferenced. Requiring roff + SIZEOF_RESIDENT <= used rejects the ATTR_END offset without rejecting any real attribute: for an attribute the walk validated, roff + asize <= off(ATTR_END) <= used - 4, and any attribute a DeleteAttribute record can legitimately name carries a full resident header, so roff + SIZEOF_RESIDENT <= roff + asize <= used - 4. check_attr() itself imposes no lower bound on asize, so a crafted sub-header asize can still pass the first test; the second test then bounds it and the memmove stays inside the record.
Reproduced by mounting a crafted image on v7.2-rc5, which already contains 0ca0485e4b2e, under KASAN. The image is an ordinary mkfs.ntfs volume with four bytes of one MFT record changed and a crafted $LogFile:
BUG: KASAN: slab-out-of-bounds in do_action.isra.0+0x3211/0x83c0 Read of size 4294967048 at addr ffff888002423258 by task mount/66 CPU: 1 UID: 0 PID: 66 Comm: mount Not tainted 7.2.0-rc5 #3 Call Trace: kasan_report+0xce/0x100 kasan_check_range+0x105/0x1b0 __asan_memmove+0x23/0x60 do_action.isra.0+0x3211/0x83c0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 get_tree_bdev_flags+0x2ef/0x550 vfs_get_tree+0x82/0x2f0 fc_mount+0x10/0x1b0 path_mount+0x517/0x1df0 __x64_sys_mount+0x20b/0x270 do_syscall_64+0xf9/0x540 entry_SYSCALL_64_after_hwframe+0x77/0x7f Allocated by task 66: __kasan_kmalloc+0x8f/0xa0 __kmalloc_noprof+0x1b4/0x460 mi_init+0x81/0x110 mi_get+0x6a/0x220 do_action.isra.0+0x1dbf/0x83c0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 The buggy address belongs to the object at ffff888002423000 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 600 bytes inside of allocated 1024-byte region [ffff888002423000, ffff888002423400)
KASAN reports the source side because __asan_memmove() (mm/kasan/shadow.c:94) validates src before dest and returns without copying. Both ends are out of bounds, and on a kernel built without KASAN the copy is performed.
rec->used is also left at used - asize by fslog.c:3323 before the memmove, so the record stays inconsistent even when the copy is suppressed; the same mount goes on to report "ino=1a, mi_enum_attr" and marks the volume dirty.
--- fs/ntfs3/fslog.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
fs/ntfs3/fslog.c +13 -2
@@ -3345,10 +3345,21 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,break ;case DeleteAttribute: - asize =le32_to_cpu (attr->size); used =le32_to_cpu (rec->used); -if (!check_if_attr (rec, lrh)) +/* +* check_if_attr() accepts a record_off that points at the +* ATTR_END marker, which is how CreateAttribute appends. The +* bytes there are not an attribute and check_attr() never +* validated them, so refuse an offset that cannot hold a +* resident header before reading attr->size, and then bound it +* as mi_remove_attr() does. +*/ +if (!check_if_attr (rec, lrh) || roff +SIZEOF_RESIDENT > used) + goto dirty_vol; + + asize =le32_to_cpu (attr->size); +if (asize > used - roff) goto dirty_vol; rec->used =cpu_to_le32 (used - asize);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 736/2214 ntfs3: fix mapping pairs bounds check for alignment
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit f517cae6333121783043d9ba5142b50f5d1cf75b ]
In the UpdateMappingPairs action, the expansion check compares the unaligned new attribute size with the available record space. The new size is aligned to an 8-byte boundary before the mapping pairs are updated, so the check can underestimate the required space by up to seven bytes.
Use the aligned size in the expansion check to ensure that the subsequent update cannot exceed the available record space.
--- fs/ntfs3/fslog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ntfs3/fslog.c +2 -1
@@ -3441,7 +3441,8 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,if (!check_if_attr (rec, lrh) || !attr->non_res || aoff <le16_to_cpu (attr->nres.run_off) || aoff > asize || - (nsize > asize && nsize - asize > record_size - used)) { + (nsize > asize && +ALIGN (nsize,8 ) - asize > record_size - used)) { goto dirty_vol; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 737/2214 ASoC: hdac_hda: Keep runtime PM state in sync across codec remove/probe
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 99203e8d8968def973e82bb712ea959c6a46c16e ]
After the codec has been removed, its runtime PM status is RPM_SUSPENDED while hdac_hda_codec_probe() powers the codec up via snd_hda_codec_device_new(). The pm_runtime_put()/snd_hda_power_down() calls on probe and registration then see an already suspended device, the codec suspend callback is not called and the codec, its HDA link and the codec_powered bit stay set, preventing the controller from runtime suspending.
The remove has a similar problem with the codec link accounting:hdac_hda_codec_remove() drops the link reference taken in probe without looking at the runtime PM state of the codec. If the codec was already runtime suspended, the link reference has been dropped by the codec suspend callback and the remove drops it a second time.
Resume the codec in hdac_hda_codec_remove() before disabling runtime PM so that the link reference and the codec_powered bit are always in the same state as after the probe, and mark the device active on probe once the codec has been powered up.
Finally mark the codec device suspended at the end of the remove. Its runtime PM is disabled at this point and if only the ASoC card is unbound (e.g. by unbinding the machine driver), a following system suspend would otherwise call the runtime suspend callback on the already cleaned up codec via pm_runtime_force_suspend().
This is a followup patch to address Sashiko reports.
--- sound/soc/codecs/hdac_hda.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
sound/soc/codecs/hdac_hda.c +12 -0
@@ -481,6 +481,9 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)snd_hdac_display_power (hdev->bus,HDA_CODEC_IDX_CONTROLLER , false); +/* The codec is in D0, the status is RPM_SUSPENDED after a previous unbind */ +pm_runtime_set_active (&hdev->dev); +/* match for forbid call in snd_hda_codec_device_new() */ pm_runtime_allow (&hdev->dev);
@@ -520,6 +523,12 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component)return ; } +/* +* Resume the codec to have its link reference (dropped below) and +* codec_powered bit in the same state as after the probe. +*/ +pm_runtime_get_sync (&hdev->dev); +/* prevent runtime PM callbacks while the link and the codec are torn down */ pm_runtime_disable (&hdev->dev);snd_hdac_ext_bus_link_put (hdev->bus, hlink);
@@ -531,6 +540,9 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component)/* Balances the disable above, cleanup_for_unbind keeps runtime PM disabled */ pm_runtime_enable (&hdev->dev); +pm_runtime_put_noidle (&hdev->dev); +/* The codec is cleaned up, system suspend must skip it from now on */ +pm_runtime_set_suspended (&hdev->dev); }static const struct snd_soc_dapm_route hdac_hda_dapm_routes[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 738/2214 ppp: fix stale pointer access after pskb_may_pull in ppp_ccp_peek
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
[ Upstream commit 1e860f42f41c6fbf3304f6a52be38245b9394982 ]
ppp_ccp_peek() caches a pointer to skb->data in dp after the first pskb_may_pull(), then uses dp after a second pskb_may_pull(skb, len + 2) in the CCP_CONFACK handler. If the second pull triggers pskb_expand_head() due to a cloned skb or frag linearization, skb->head is freed and reallocated, leaving dp stale.
The stale dp is subsequently used in CCP_OPT_LENGTH() and passed to decomp_init()/comp_init() which read from the freed memory.
Re-derive dp from skb->data after the second pskb_may_pull.
--- drivers/net/ppp/ppp_generic.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ppp/ppp_generic.c +1 -0
@@ -3158,6 +3158,7 @@ ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound) len =CCP_LENGTH (dp);if (!pskb_may_pull (skb, len +2 ))return ;/* too short */ + dp = skb->data +2 ; dp +=CCP_HDRLEN ; len -=CCP_HDRLEN ;if (len <CCP_OPT_MINLEN || len <CCP_OPT_LENGTH (dp))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 739/2214 nvmet-rdma: reject short connection requests
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 635e760169a87abf03874cd4636cd91b580cb427 ]
nvmet_rdma_parse_cm_connect_req() treats RDMA-CM private data as a struct nvme_rdma_cm_req but accepts any nonzero private_data_len. The iWARP path allocates exactly the peer-provided length, so a six-byte MPA request reaches the parser and the hsqsize load reads two bytes past the allocation.
Require the complete request structure before reading any of its fields. The decoded KASAN report is:
BUG: KASAN: slab-out-of-bounds in nvmet_rdma_cm_handler
(drivers/nvme/target/rdma.c:1427 drivers/nvme/target/rdma.c:1475
drivers/nvme/target/rdma.c:1614 drivers/nvme/target/rdma.c:1814)
Read of size 2 at addr ff1100010459d366 by task kworker/u16:1/41
Workqueue: iw_cm_wq cm_work_handler
Call Trace:
<TASK>
dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
kasan_report (mm/kasan/report.c:595)
nvmet_rdma_cm_handler
(drivers/nvme/target/rdma.c:1427 drivers/nvme/target/rdma.c:1475
drivers/nvme/target/rdma.c:1614 drivers/nvme/target/rdma.c:1814)
cma_cm_event_handler (drivers/infiniband/core/cma.c:2181)
iw_conn_req_handler (drivers/infiniband/core/cma.c:2640)
cm_work_handler
(drivers/infiniband/core/cm.c:2502
drivers/infiniband/core/cm.c:3858)
process_one_work (kernel/workqueue.c:3396)
worker_thread (kernel/workqueue.c:3479 kernel/workqueue.c:3560)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/x86/kernel/process.c:158)
ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
</TASK>
Allocated by task 12:
__kasan_kmalloc (mm/kasan/common.c:398 mm/kasan/common.c:415)
__kmalloc_node_track_caller_noprof
(mm/slub.c:5414 mm/slub.c:5545)
kmemdup_noprof (mm/util.c:138)
cm_event_handler
(drivers/infiniband/core/iwcm.c:194
drivers/infiniband/core/iwcm.c:1076)
siw_cm_upcall (drivers/infiniband/sw/siw/siw_cm.c:408)
siw_proc_mpareq (drivers/infiniband/sw/siw/siw_cm.c:750)
siw_cm_work_handler (drivers/infiniband/sw/siw/siw_cm.c:1086) The buggy address is located 0 bytes to the right of allocated 6-byte region [ff1100010459d360, ff1100010459d366)
--- drivers/nvme/target/rdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/rdma.c +1 -1
@@ -1411,7 +1411,7 @@ nvmet_rdma_parse_cm_connect_req(struct rdma_conn_param *conn,struct nvme_rdma_cm_req *req; req = (struct nvme_rdma_cm_req *)conn->private_data; -if (!req || conn->private_data_len ==0 ) +if (!req || conn->private_data_len <sizeof (*req))return NVME_RDMA_CM_INVALID_LEN ;if (le16_to_cpu (req->recfmt) !=NVME_RDMA_CM_FMT_1_0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 740/2214 nvmet-fc: only send read data for successful commands
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit 94f93c61b1a5dd08d011be58172ce4392b849008 ]
When a read command completes with an error, __nvmet_fc_fcp_nvme_cmd_done() still pushes the whole data buffer to the host before the response. nvmet_fc_alloc_tgt_pgs() allocates that buffer with sgl_alloc() and no __GFP_ZERO, and a command rejected by nvmet_check_transfer_len() leaves it untouched, so the host receives stale target memory.
The buffer is as large as the data length in the command IU, so the amount of stale memory returned is up to the host.
The tcp and rdma targets send data only when cqe->status is zero (see nvmet_tcp_need_data_out() and nvmet_rdma_need_data_out()), so no nvmet command can rely on returning data with an error status. Do the same for fc. The ERSP then reports a transferred length of fod->offset, which is 0, matching what nvme_fc_fcpio_done() checks on the host.
Tested over nvme-fcloop: a failed read command no longer transfers data and still completes with its error status, and successful reads are unaffected.
--- drivers/nvme/target/fc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/nvme/target/fc.c +4 -4
@@ -2464,11 +2464,11 @@ __nvmet_fc_fcp_nvme_cmd_done(struct nvmet_fc_tgtport *tgtport, }else {/* -* try to push the data even if the SQE status is non-zero. -* There may be a status where data still was intended to -* be moved +* A failed command may not have filled its read buffer, so +* only push data for success, as the tcp and rdma targets do. */ -if ((fod->io_dir ==NVMET_FCP_READ ) && (fod->data_sg_cnt)) { +if (fod->io_dir ==NVMET_FCP_READ && fod->data_sg_cnt && + !cqe->status) {/* push the data over before sending rsp */ nvmet_fc_transfer_fcp_data (tgtport, fod,NVMET_FCOP_READDATA );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 741/2214 nvmet-fc: Tear down the association when the admin queue allocation fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit 11db8ab55e1a7533e9cfe57687ab142ba67d3c84 ]
When the initial admin queue allocation fails after a new association was created, nvmet_fc_ls_create_association() only drops the association reference, which frees the association. By then the association is already on the target port's assoc_list, though, and removal from that list only happens in nvmet_fc_delete_target_assoc(), which this error path never calls. The freed association stays on the list, where later lookups and the port teardown can access it, and the target port reference taken at allocation time leaks.
A remote host can trigger this reliably with a Create Association LS requesting a queue too large to allocate.
Schedule the regular association teardown instead of dropping the reference directly. The teardown removes the association from the list and releases the target port reference before the final reference drop frees it.
--- drivers/nvme/target/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/fc.c +1 -1
@@ -1681,7 +1681,7 @@ nvmet_fc_ls_create_association(struct nvmet_fc_tgtport *tgtport, be16_to_cpu(rqst->assoc_cmd.sqsize));if (!queue) { ret =VERR_QUEUE_ALLOC_FAIL ; -nvmet_fc_tgt_a_put (iod->assoc); +nvmet_fc_schedule_delete_assoc (iod->assoc); } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 742/2214 nvmet: Finish the blk plug when integrity allocation fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit 18fc5f6f1ca945630dae5404265de55d65194e22 ]
nvmet_bdev_execute_rw() starts a plug before building the bios, but the two error exits taken when nvmet_bdev_alloc_bip() fails return without calling blk_finish_plug(). current->plug is left pointing at the stack frame of the returned function, so the next blk_flush_plug() walks a stale list.
Route both failures through a common exit that finishes the plug.
--- drivers/nvme/target/io-cmd-bdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +3 -2
@@ -291,7 +291,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) &prot_miter);if (unlikely (rc)) {bio_io_error (bio); -return ; + goto out_plug; } }
@@ -312,11 +312,12 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) rc =nvmet_bdev_alloc_bip (req, bio, &prot_miter);if (unlikely (rc)) {bio_io_error (bio); -return ; + goto out_plug; } }submit_bio (bio); +out_plug:blk_finish_plug (&plug); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 743/2214 kgdb: Fix buffer overflow in the m packet handler
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fang Xieyan <[email protected]>
[ Upstream commit ac0159129e2cb99a70c4b80cfbf58d03e092dc7b ]
gdb_cmd_memread() passes the length of the 'm' packet straight to kgdb_mem2hex(), which hex-encodes the reply into remcom_out_buffer[BUFMAX] without checking that the reply fits. A client on the KGDB I/O console can ask for a read of any size, and the hex encoding runs off the end of the buffer. kgdb_mem2hex() takes that length as an int count, so 2^31 truncates to a negative value and copy_from_kernel_nofault() is handed buf + count as its destination.
On x86 BUFMAX is 1024, so a read of 512 bytes overruns by the single byte that terminates the hex string:
BUG: KASAN: global-out-of-bounds in kgdb_mem2hex+0x1dd/0x230 Write of size 1 at addr ffffffff87651780 by task sh/1 ... The buggy address belongs to the variable: remcom_out_buffer+0x400/0x420
Bounds check the length before the hex encoding:
if (length > (BUFMAX - 1) / 2) {
error_packet(remcom_out_buffer, -EINVAL);
return;
}gdbstub_msg_write() already bounds the count it hex-encodes against BUFMAX. Reads over the limit never returned valid data, so an error reply loses nothing.
--- kernel/debug/gdbstub.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/debug/gdbstub.c +8 -0
@@ -561,6 +561,14 @@ static void gdb_cmd_memread(struct kgdb_state *ks)if (kgdb_hex2long (&ptr, &addr) >0 && *ptr++ ==',' &&kgdb_hex2long (&ptr, &length) >0 ) { +/* +* The hex-encoded reply needs 2 * length + 1 bytes +* in remcom_out_buffer[BUFMAX]. +*/ +if (length > (BUFMAX -1 ) /2 ) { +error_packet (remcom_out_buffer, -EINVAL ); +return ; + } err =kgdb_mem2hex ((char *)addr, remcom_out_buffer, length);if (!err)error_packet (remcom_out_buffer, -EINVAL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 744/2214 kgdb: Fix buffer overflow in the M and X packet handlers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fang Xieyan <[email protected]>
[ Upstream commit 13962ef7021ef2531a4f6650eca87c363e6c9c32 ]
write_mem_msg() passes the length claimed by an 'M' or 'X' packet directly to kgdb_hex2mem() or kgdb_ebin2mem(). A malformed packet can claim more data than was actually received, causing the decoders to read past remcom_in_buffer.
Record the received payload length in get_packet() and use it to bound the decoders. 'M' carries two hex characters per byte, while 'X' carries one byte per output byte except that a 0x7d escape consumes an additional input byte. Pass the packet end to kgdb_ebin2mem() so both reads are checked against the received data.
Keep zero-length 'X' packets valid, as GDB uses them to probe binary download support.
--- kernel/debug/gdbstub.c | 45 +++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-)
kernel/debug/gdbstub.c +38 -7
@@ -41,6 +41,8 @@/* Our I/O buffers. */ static char remcom_in_buffer[BUFMAX ];static char remcom_out_buffer[BUFMAX ]; +/* Payload bytes get_packet() stored in remcom_in_buffer, excluding the NUL. */ +static int remcom_in_len;static int gdbstub_use_prev_in_buf;static int gdbstub_prev_in_buf_pos;
@@ -85,7 +87,7 @@ static int gdbstub_read_wait(void) }#endif /* scan for the sequence $<data>#<checksum> */ -static void get_packet (char *buffer) +static int get_packet (char *buffer) {unsigned char checksum;unsigned char xmitcsum;
@@ -133,6 +135,8 @@ static void get_packet(char *buffer) } buffer[count] =0 ; }while (checksum != xmitcsum); + +return count; }/*
@@ -319,16 +323,26 @@ int kgdb_hex2long(char **ptr, unsigned long *long_val)* Copy the binary array pointed to by buf into mem. Fix $, #, and * 0x7d escaped with 0x7d. Return -EFAULT on failure or 0 on success. * The input buf is overwritten with the result to write to mem. +* +* buf_end points one past the last byte received for this packet. Each +* 0x7d escape consumes a second input byte, so decoding count bytes can +* read up to 2 * count input bytes; stop at buf_end rather than running +* off the end of remcom_in_buffer. */ -static int kgdb_ebin2mem (char *buf,char *mem,int count) +static int kgdb_ebin2mem (char *buf,char *mem,int count,char *buf_end) {int size =0 ;char *c = buf;while (count-- >0 ) { +if (buf >= buf_end) +return -EINVAL ; c[size] = *buf++; -if (c[size] ==0x7d ) +if (c[size] ==0x7d ) { +if (buf >= buf_end) +return -EINVAL ; c[size] = *buf++ ^0x20 ; + } size++; }
@@ -365,16 +379,33 @@ void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)static int write_mem_msg (int binary) {char *ptr = &remcom_in_buffer[1 ]; +char *buf_end = &remcom_in_buffer[remcom_in_len];unsigned long addr;unsigned long length;int err;if (kgdb_hex2long (&ptr, &addr) >0 && *(ptr++) ==',' &&kgdb_hex2long (&ptr, &length) >0 && *(ptr++) ==':' ) { -if (binary) - err =kgdb_ebin2mem (ptr, (char *)addr, length); -else +/* +* Trust only the bytes actually received, not length: the +* client can claim more payload than it sent. 'M' decodes two +* hex chars per byte in place, so it needs 2 * length bytes at +* ptr; 'X' decodes one byte per byte, and kgdb_ebin2mem() bounds +* its extra 0x7d-escape reads against buf_end itself. +*/ +if (ptr >= buf_end) +return -EINVAL ; + +if (binary) { +if (length > (unsigned long )(buf_end - ptr)) +return -EINVAL ; + err =kgdb_ebin2mem (ptr, (char *)addr, length, buf_end); + }else { +if (length > (unsigned long )(buf_end - ptr) /2 ) +return -EINVAL ; err =kgdb_hex2mem (ptr, (char *)addr, length); + } +if (err)return err;if (CACHE_FLUSH_IS_SAFE )
@@ -991,7 +1022,7 @@ int gdb_serial_stub(struct kgdb_state *ks)/* Clear the out buffer. */ memset (remcom_out_buffer,0 ,sizeof (remcom_out_buffer)); -get_packet (remcom_in_buffer); + remcom_in_len =get_packet (remcom_in_buffer);switch (remcom_in_buffer[0 ]) {case '?' :/* gdbserial status */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 745/2214 kgdb: Fix buffer overflow in the qRcmd packet handler
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fang Xieyan <[email protected]>
[ Upstream commit 9ca9e8c857b55a081d5a1f8039b27cbb4d646b49 ]
gdb_cmd_query() decodes the hex payload of a qRcmd packet (the GDB "monitor" command passthrough to kdb) into remcom_out_buffer and hands it to kdb_parse(). It sizes the decode with strlen() of the payload:
int len = strlen(remcom_in_buffer + 6); ... kgdb_hex2mem(remcom_in_buffer + 6, remcom_out_buffer, len); len = len / 2;
kgdb_hex2mem() takes count as the number of bytes to produce and decodes them in place at buf, reading and writing 2 * count bytes there. len here is the hex character count, twice the decoded size, so the decode runs over 2 * len bytes at remcom_in_buffer + 6, off the end of the buffer. On x86 BUFMAX is 1024, so a 256-byte monitor command (512 hex characters) overruns remcom_in_buffer during the in-place decode:
BUG: KASAN: global-out-of-bounds in kgdb_hex2mem+0x131/0x160 Read of size 1 at addr ffffffff8765ef05 by task sh/1 ... kgdb_hex2mem+0x131/0x160 gdb_serial_stub+0x16d4/0x3170 kgdb_cpu_enter+0xb68/0x1520 ... The buggy address belongs to the variable: remcom_in_buffer+0x405/0x420
Halve len before the call so kgdb_hex2mem() gets the decoded byte count. It then reads the len hex characters already in remcom_in_buffer and writes len / 2 bytes, all inside the buffer, and remcom_out_buffer holds the same command as before.
--- kernel/debug/gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/gdbstub.c +1 -1
@@ -815,9 +815,9 @@ static void gdb_cmd_query(struct kgdb_state *ks)strcpy (remcom_out_buffer,"E01" );break ; } + len = len /2 ;kgdb_hex2mem (remcom_in_buffer +6 , remcom_out_buffer, len); - len = len /2 ; remcom_out_buffer[len++] =0 ;kdb_common_init_state (ks);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 746/2214 fsverity: Be more careful with return value of ->get_verity_descriptor()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
[ Upstream commit 8f8faec82aa902b1997ae578c46bcc84afbad811 ]
If fsverity_operations::get_verity_descriptor() returns that the verity descriptor has 0 size, then a zero-size buffer is allocated to hold it, and it's called again with bufsize=0.
But bufsize=0 is a special case that says to return the actual size. If in the meantime the filesystem has decided that the size is some actually valid size, it will return that size, and then validate_fsverity_descriptor() will read from ZERO_SIZE_PTR and crash.
Of course, for the filesystem to misbehave in that strange way, it generally would require direct writes to the block device.
Regardless, fsverity_get_descriptor() might as well guard against it. Make it do so. Specifically, validate that the first call to ->get_verity_descriptor() returns at least the minimum descriptor size, and validate that the second call returns the same size as the first.
--- fs/verity/open.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
fs/verity/open.c +19 -19
@@ -222,12 +222,6 @@ static bool validate_fsverity_descriptor(struct inode *inode,const struct fsverity_descriptor *desc, size_t desc_size) { - if (desc_size < sizeof(*desc)) { - fsverity_err(inode, "Unrecognized descriptor size: %zu bytes", - desc_size); -return false; - } - if (desc->version != 1) { fsverity_err(inode, "Unrecognized descriptor version: %u", desc->version);
@@ -267,31 +261,37 @@ int fsverity_get_descriptor(struct inode *inode,struct fsverity_descriptor **desc_ret, size_t *desc_size_ret) { - int res; + int size, res;struct fsverity_descriptor *desc; - res = inode->i_sb->s_vop->get_verity_descriptor (inode,NULL ,0 ); -if (res <0 ) { -fsverity_err (inode, -"Error %d getting verity descriptor size" , res); -return res; + size = inode->i_sb->s_vop->get_verity_descriptor (inode,NULL ,0 ); +if (size <0 ) { +fsverity_err (inode,"Error %d getting verity descriptor size" , + size); +return size; } -if (res >FS_VERITY_MAX_DESCRIPTOR_SIZE ) { -fsverity_err (inode,"Verity descriptor is too large (%d bytes)" , - res); +if (size <sizeof (*desc) || size >FS_VERITY_MAX_DESCRIPTOR_SIZE ) { +fsverity_err (inode, +"Verity descriptor has invalid size (%d bytes)" , + size);return -EMSGSIZE ; } - desc =kmalloc (res,GFP_KERNEL ); + desc =kmalloc (size,GFP_KERNEL );if (!desc)return -ENOMEM ; - res = inode->i_sb->s_vop->get_verity_descriptor (inode, desc, res); + res = inode->i_sb->s_vop->get_verity_descriptor (inode, desc, size);if (res <0 ) {fsverity_err (inode,"Error %d reading verity descriptor" , res);kfree (desc);return res; } - -if (!validate_fsverity_descriptor (inode, desc, res)) { +if (res != size) { +fsverity_err (inode,"Verity descriptor size changed (%d => %d)" , + size, res); +kfree (desc); +return -EINVAL ; + } +if (!validate_fsverity_descriptor (inode, desc, size)) {kfree (desc);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 747/2214 mount: refuse setns() with a shared fs_struct again
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 948e604aca8af30490accf7d46d44814ffa26f80 ]
mntns_install() refuses to switch the mount namespace of a task that shares its fs_struct, since root and cwd of the others would move to a namespace they are not in. It looks at nsset->fs for that. If more than the mount namespace is asked for, that is a private copy made by prepare_nsset(), which has one user by definition; commit_nsset() then writes root and cwd of the copy to the fs_struct of the task.
A thread of a process with two threads, pidfd of a task in another mount namespace:
setns(pidfd, CLONE_NEWNS) -EINVAL
setns(pidfd, CLONE_NEWNS | CLONE_NEWUTS) 0
and after the second call the other thread, still in the old mount namespace, has lost its cwd (/tmp became /) and sees the mounts of the other namespace under /.
Look at the fs_struct that is going to be changed. The second call then fails with -EINVAL like the first one.
--- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namespace.c +1 -1
@@ -4706,7 +4706,7 @@ static int mntns_install(struct nsset *nsset, struct ns_common *ns)if (is_anon_ns (mnt_ns))return -EINVAL ; -if (fs->users !=1 ) +if (current->fs->users !=1 )return -EINVAL ;get_mnt_ns (mnt_ns);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 748/2214 blk-iocost: abort weight transfer on invalid donation weights
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kunhai Dai <[email protected]>
[ Upstream commit c810ee88cdab27f443c32270dc7c0eaad2cca3f8 ]
transfer_surpluses() warns and then keeps going when the donation calculation produced invalid weights. The following propagation can then divide by a zero hweight_inuse, so the warning is immediately followed by a divide error.
When the check trips, abandon this period's donation transfer and release the walk lists. This trades one period without donation for not crashing; the invalid state is not expected on the normal path.
Developed with assistance from Claude Code (Anthropic): the assistant analysed the failure path, drafted the change and ran the checks listed below. The author reviewed the result and remains responsible for it.
--- block/blk-iocost.c | 2 ++ 1 file changed, 2 insertions(+)
block/blk-iocost.c +2 -0
@@ -1960,6 +1960,7 @@ static void transfer_surpluses(struct list_head *surpluses, struct ioc_now *now)pr_cont (": active=%u donating=%u after=%u\n" , iocg->hweight_active, iocg->hweight_donating, iocg->hweight_after_donation); + goto out; } }
@@ -2058,6 +2059,7 @@ static void transfer_surpluses(struct list_head *surpluses, struct ioc_now *now)__propagate_weights (iocg, iocg->active, inuse, true, now); } +out:/* walk list should be dissolved after use */ list_for_each_entry_safe (iocg, tiocg, &inner_walk, walk_list)list_del_init (&iocg->walk_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 749/2214 tcp: check congestion control restriction first
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit dda51b73721684637ab8e9bd97c78228b99c4bd2 ]
tcp_set_default_congestion_control() takes a reference to an algorithm before checking whether a non-init network namespace may select it. A rejected request returns -EPERM without dropping the reference.
This affects module-backed algorithms too; BPF is not required. For example, after root loads tcp_bbr, a user with CAP_NET_ADMIN in a non-init network namespace can repeatedly request it as the default although it is not in tcp_allowed_congestion_control. Each rejected write leaks a module reference. Since module->refcnt is an atomic_t, 2^31 such writes can make it negative; later module_put() calls warn, and rmmod can hit the BUG_ON() in try_release_module_ref().
Check the namespace restriction before acquiring the reference, as tcp_set_congestion_control() already does.
--- net/ipv4/tcp_cong.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_cong.c +2 -2
@@ -228,12 +228,12 @@ int tcp_set_default_congestion_control(struct net *net, const char *name) ca =tcp_ca_find_autoload (net, name);if (!ca) { ret = -ENOENT ; - }else if (!bpf_try_module_get (ca, ca->owner)) { - ret = -EBUSY ; }else if (!net_eq (net, &init_net) && !(ca->flags &TCP_CONG_NON_RESTRICTED )) {/* Only init netns can set default to a restricted algorithm */ ret = -EPERM ; + }else if (!bpf_try_module_get (ca, ca->owner)) { + ret = -EBUSY ; }else { prev =xchg (&net->ipv4.tcp_congestion_control, ca);if (prev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 750/2214 tcp: fix reordering addition overflow in MTU probing
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 c1df9c0c0536393de43310f84ca4f8b217271a00 ]
Commit efb8763d7bbb ("net: ipv4: bound TCP reordering sysctl writes and MTU probe sizes") widened size_needed and the MSS multiplication, but tp->reordering + 1 is still evaluated as u32. RTAX_REORDERING accepts an unrestricted u32, and tcp_init_metrics() can install U32_MAX.
In that case the extra-data requirement becomes zero. A write queue with probe_size - 1 data bytes and a FIN satisfies the sequence-space check. The coalescing walk can pass the queue head to tcp_skb_can_collapse(), and tcp_clone_payload() can produce an skb whose advertised payload exceeds the data in its fragments. Local delivery followed by TCP_ZEROCOPY_RECEIVE can then walk beyond the fragment array. KASAN reports a slab-out-of-bounds read in can_map_frag().
Cast reordering before incrementing it so the arithmetic handles the entire u32 metric range. For U32_MAX, the required size exceeds the 32-bit queue and window limits, so the existing checks skip the probe. The calculation is unchanged for all other reordering values.
--- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_output.c +1 -1
@@ -2370,7 +2370,7 @@ static int tcp_mtu_probe(struct sock *sk) mss_now =tcp_current_mss (sk); probe_size =tcp_mtu_to_mss (sk, (icsk->icsk_mtup.search_high + icsk->icsk_mtup.search_low) >>1 ); - size_needed = probe_size + (tp->reordering +1 ) * (u64 )tp->mss_cache; + size_needed = probe_size + ((u64 )tp->reordering +1 ) * tp->mss_cache; interval = icsk->icsk_mtup.search_high - icsk->icsk_mtup.search_low;/* When misfortune happens, we are reprobing actively, * and then reprobe timer has expired. We stick with current
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 751/2214 fs: skip copy_file_range write limits when there is no data
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 81dfa035891f0502674332ee97db348a16486de0 ]
generic_copy_file_checks() reduces count to zero for a source offset at or beyond EOF, but still checks the destination write limits. If pos_out is at RLIMIT_FSIZE, this sends SIGXFSZ and returns -EFBIG even though there is no data to write.
For example, GNU cat copying a 1024-byte regular file to another regular file with RLIMIT_FSIZE=1024 copies all bytes and is then killed by its next copy_file_range() call at EOF. A zero-length request can fail in the same way.
Check write limits only when count is nonzero, as the ordinary write checks already do. Keep the other copy validation in place.
--- fs/read_write.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/read_write.c +5 -3
@@ -1446,9 +1446,11 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,else count =min (count, size_in - (uint64_t )pos_in); - ret =generic_write_check_limits (file_out, pos_out, &count); -if (ret) -return ret; +if (count) { + ret =generic_write_check_limits (file_out, pos_out, &count); +if (ret) +return ret; + }/* Don't allow overlapped copying within the same file. */ if (inode_in == inode_out &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 752/2214 init/bootconfig: pass init arguments in documented order
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 278b2abf660a3e0991eb9f16f11bd9e9514a286d ]
start_kernel() appends command-line init arguments before bootconfig init arguments, while setup_command_line() places them in the opposite order. As a result, the arguments passed to init do not match the saved command line, reversing the intended precedence of options.
Parse extra_init_args before after_dashes so command-line init arguments are passed last.
--- init/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
init/main.c +3 -3
@@ -953,12 +953,12 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) __stop___param - __start___param, -1, -1, NULL, &unknown_bootoption);print_unknown_bootoptions (); -if (!IS_ERR_OR_NULL (after_dashes)) -parse_args ("Setting init args" , after_dashes,NULL ,0 ,-1 ,-1 , -NULL , set_init_arg);if (extra_init_args)parse_args ("Setting extra init args" , extra_init_args,NULL ,0 ,-1 ,-1 ,NULL , set_init_arg); +if (!IS_ERR_OR_NULL (after_dashes)) +parse_args ("Setting init args" , after_dashes,NULL ,0 ,-1 ,-1 , +NULL , set_init_arg);/* * These use large bootmem allocations and must precede
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 753/2214 wifi: brcmfmac: map msgbuf RX packet IDs bidirectional
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Perlow <[email protected]>
[ Upstream commit 7ed5dce55fa8393972b1bf2bf5af1c818c5e7dc2 ]
Commit f0ba5fd51ff2 ("wifi: brcmfmac: Set DMA direction for msgbuf packet IDs") maps the RX packet ID buffers DMA_FROM_DEVICE. The BCM4364 firmware also reads posted RX buffers, so with VT-d translation enabled every such read faults ("PTE Read access is not set") and the firmware crashes and resets in a loop.
Map the RX pool DMA_BIDIRECTIONAL again, as before that commit. TX keeps DMA_TO_DEVICE.
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +1 -1
@@ -1617,7 +1617,7 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr)if (!msgbuf->tx_pktids) goto fail; msgbuf->rx_pktids =brcmf_msgbuf_init_pktids (NR_RX_PKTIDS , -DMA_FROM_DEVICE ); +DMA_BIDIRECTIONAL );if (!msgbuf->rx_pktids) goto fail;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 754/2214 ksmbd: fix out-of-bounds write in smb2_get_ea() EA alignment
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
[ Upstream commit 30010c952077a1c89ecdd71fc4d574c75a8f5617 ]
smb2_get_ea() applies 4-byte alignment padding via memset() after writing each EA entry. The bounds check on buf_free_len is performed before the value memcpy, but the alignment memset fires unconditionally afterward with no check on remaining space.
When the EA value exactly fills the remaining buffer (buf_free_len == 0 after value subtraction), the alignment memset writes 1-3 NUL bytes past the buf_free_len boundary. In compound requests where the response buffer is shared across commands, the first command (e.g., READ) can consume most of the buffer, leaving a tight remainder for the QUERY_INFO EA response. The alignment memset then overwrites past the physical kvmalloc allocation into adjacent kernel heap memory.
Add a bounds check before the alignment memset to ensure buf_free_len can accommodate the padding bytes.
This is the same bug pattern fixed by commit beef2634f81f ("ksmbd: fix potencial OOB in get_file_all_info() for compound requests") and commit fda9522ed6af ("ksmbd: fix OOB write in QUERY_INFO for compound requests"), both of which added bounds checks before unconditional writes in QUERY_INFO response handlers.
--- fs/ksmbd/smb2pdu.c | 2 ++ 1 file changed, 2 insertions(+)
fs/ksmbd/smb2pdu.c +2 -0
@@ -4556,6 +4556,8 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,/* align next xattr entry at 4 byte bundary */ alignment_bytes = ((next_offset +3 ) & ~3 ) - next_offset;if (alignment_bytes) { +if (buf_free_len < alignment_bytes) +break ;memset (ptr,'\0' , alignment_bytes); ptr += alignment_bytes; next_offset += alignment_bytes;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 755/2214 smb: client: validate the data area in SMB2_read()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdifatah Suruur <[email protected]>
[ Upstream commit 2ec9cdf469dd32bcf33073aeb30c08e9356e0ca1 ]
SMB2_read() copies le32_to_cpu(rsp->DataLength) bytes from (char *)rsp + rsp->DataOffset without checking that the range lies within the response actually received. A READ response with DataOffset == 0 makes smb2_get_data_area_len() zero the data length, so smb2_check_message() accepts a frame as short as the fixed response, while SMB2_read() still uses the server-supplied DataLength, capped only by CIFS_MAX_MSGSIZE and the caller's length.
A malicious server can answer the synchronous read used by the mfsymlinks (or SFU) symlink parser with an 81-byte READ response carrying DataOffset 0 and DataLength 1067, making the client copy 1067 bytes from a 448-byte receive object (KASAN slab-out-of-bounds; up to 16 KiB in the general case).
Clamp a zero (or header-overlapping) DataOffset to read_rsp_size, as handle_read_data() does for the asynchronous path, and reject the response unless DataOffset + DataLength fits within rsp_iov.iov_len. The SMB1 helper was fixed the same way in 5be5bdda5863.
--- fs/cifs/smb2pdu.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +22 -1
@@ -4236,6 +4236,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,struct kvec iov[1 ];struct kvec rsp_iov;unsigned int total_len; +u16 data_offset;int flags =CIFS_LOG_ERROR ;struct cifs_ses *ses = io_parms->tcon->ses;
@@ -4292,8 +4293,28 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, *nbytes =0 ; } + data_offset = rsp->DataOffset; +if (data_offset < io_parms->server->vals->read_rsp_size) { +/* +* win2k8 sometimes sends an offset of 0 when the read is beyond +* the EOF. Treat it as if the data starts just after the header, +* as handle_read_data() does. +*/ +cifs_dbg (FYI ,"data offset %u inside read response header\n" , + data_offset); + data_offset = io_parms->server->vals->read_rsp_size; + } + +/* The data area must lie within the response actually received */ +if (*nbytes && (size_t )data_offset + *nbytes > rsp_iov.iov_len) { +cifs_dbg (FYI ,"bad data offset %u length %u for response of %zu\n" , + data_offset, *nbytes, rsp_iov.iov_len); + rc = -EIO ; + *nbytes =0 ; + } +if (*buf) { -memcpy (*buf, (char *)rsp + rsp->DataOffset, *nbytes); +memcpy (*buf, (char *)rsp + data_offset, *nbytes);free_rsp_buf (resp_buftype, rsp_iov.iov_base); }else if (resp_buftype !=CIFS_NO_BUFFER ) { *buf = rsp_iov.iov_base;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 756/2214 NFSD: Set nn->cld_net before registering the cld pipe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 14996e662f3b734427e2d645cacffc27b779f7d1 ]
rpc_mkpipe_dentry() instantiates the pipe's dentry before it returns, so the cld pipe can be opened as soon as nfsd4_cld_register_net() has run. __nfsd4_init_cld_pipe() does not store the new cld_net in nn->cld_net until after that call. cld_pipe_downcall() reaches the cld_net only through that pointer and takes cn_lock without checking it, so a write() that lands in the window oopses.
Store nn->cld_net once @cn is fully initialized and before the pipe is registered, and clear it again when registration fails.
--- fs/nfsd/nfs4recover.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/nfsd/nfs4recover.c +8 -2
@@ -1014,6 +1014,13 @@ __nfsd4_init_cld_pipe(struct net *net) }spin_lock_init (&cn->cn_lock);INIT_LIST_HEAD (&cn->cn_list); + cn->cn_has_legacy = false; + +/* +* The pipe's methods reach @cn through nn->cld_net, so set +* it before the pipe can be opened. +*/ + nn->cld_net = cn; dentry =nfsd4_cld_register_net (net, cn->cn_pipe);if (IS_ERR (dentry)) {
@@ -1022,11 +1029,10 @@ __nfsd4_init_cld_pipe(struct net *net) } cn->cn_pipe->dentry = dentry; - cn->cn_has_legacy = false; - nn->cld_net = cn;return 0 ; err_destroy_data: + nn->cld_net =NULL ;rpc_destroy_pipe_data (cn->cn_pipe); err:kfree (cn);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 757/2214 rxrpc: Fix update of call->tx_pending without holding lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 7801c42c3bb737cfb06194a383873fcad8daacf5 ]
Currently, rxrpc_send_data() updates call->tx_pending just before it returns - but it won't be holding the call->user_mutex when it does this if a wait was interrupted by a signal. This would allow a parallel sendmsg() to race.
Further, both the callers of rxrpc_send_data() call it with the lock held, and then it returns an indication through the parameter list to say whether it has dropped the lock or not - after which the callers both just drop the lock if it's still held.
Fix this by:
(1) Moving the release of call->user_mutex down into rxrpc_send_data() and get rid of the indicator parameter. This makes it easier to see where the lock is held.
(2) After waiting, if the attempt to reacquire the mutex is interrupted, just return directly there rather than going to out_unlock
(3) Restricting the txb variable to inside the buffering loop and leaving
->tx_pending set until we've queued the buffer.
Note that there's a slight change in behaviour in that wait_for_space failure now doesn't check for completion because it doesn't hold the call user_mutex. The caller, however, should re-issue the send and pick up any error at a second attempt.
--- net/rxrpc/sendmsg.c | 57 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 29 deletions(-)
net/rxrpc/sendmsg.c +28 -29
@@ -287,11 +287,10 @@ static int rxrpc_queue_packet(struct rxrpc_sock *rx, struct rxrpc_call *call,static int rxrpc_send_data (struct rxrpc_sock *rx,struct rxrpc_call *call,struct msghdr *msg,size_t len, -rxrpc_notify_end_tx_t notify_end_tx, -bool *_dropped_lock) +rxrpc_notify_end_tx_t notify_end_tx) + __releases(&call->user_mutex) {struct rxrpc_skb_priv *sp; -struct sk_buff *skb;struct sock *sk = &rx->sk;enum rxrpc_call_state state;long timeo;
@@ -325,11 +324,9 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, goto maybe_error; } - skb = call->tx_pending; - call->tx_pending =NULL ; -rxrpc_see_skb (skb, rxrpc_skb_seen); - do { + struct sk_buff *skb = call->tx_pending; + /* Check to see if there's a ping ACK to reply to. */ if (call->ackr_reason == RXRPC_ACK_PING_RESPONSE) rxrpc_send_ack_packet(call, false, NULL);
@@ -381,6 +378,9 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, sp->remain); skb->ip_summed =CHECKSUM_UNNECESSARY ; + call->tx_pending = skb; + }else { +rxrpc_see_skb (skb, rxrpc_skb_seen); }_debug ("append" );
@@ -432,13 +432,13 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, ret = call->security->secure_packet (call, skb, skb->mark);if (ret <0 ) - goto out; + goto out_unlock; ret =rxrpc_queue_packet (rx, call, skb, !msg_data_left (msg) && !more, notify_end_tx);/* Should check for failure here */ - skb =NULL ; + call->tx_pending =NULL ; } }while (msg_data_left (msg) >0 );
@@ -450,45 +450,46 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, ret = call->error;read_unlock_bh (&call->state_lock); } -out: - call->tx_pending = skb; +out_unlock: +mutex_unlock (&call->user_mutex);_leave (" = %d" , ret);return ret; call_terminated: -rxrpc_free_skb (skb, rxrpc_skb_freed); -_leave (" = %d" , call->error); -return call->error; + ret = call->error; + goto out_unlock; maybe_error:if (copied) goto success; - goto out; + goto out_unlock; efault: ret = -EFAULT ; - goto out; + goto out_unlock; wait_for_space: ret = -EAGAIN ;if (msg->msg_flags &MSG_DONTWAIT ) goto maybe_error;mutex_unlock (&call->user_mutex); - *_dropped_lock = true; + ret =rxrpc_wait_for_tx_window (rx, call, &timeo, msg->msg_flags &MSG_WAITALL );if (ret <0 ) - goto maybe_error; + goto out_nolock;if (call->interruptibility ==RXRPC_INTERRUPTIBLE ) {if (mutex_lock_interruptible (&call->user_mutex) <0 ) { ret =sock_intr_errno (timeo); - goto maybe_error; + goto out_nolock; } }else {mutex_lock (&call->user_mutex); } - *_dropped_lock = false; goto reload; +out_nolock: +_leave (" = %d [intr]" , ret); +return copied ?: ret; }/*
@@ -650,7 +651,6 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)enum rxrpc_call_state state;struct rxrpc_call *call;unsigned long now, j; -bool dropped_lock = false;int ret;struct rxrpc_send_params p = {
@@ -760,12 +760,12 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) }else if (p.command !=RXRPC_CMD_SEND_DATA ) { ret = -EINVAL ; }else { - ret =rxrpc_send_data (rx, call, msg, len,NULL , &dropped_lock); + ret =rxrpc_send_data (rx, call, msg, len,NULL ); + goto error_put; } out_put_unlock: -if (!dropped_lock) -mutex_unlock (&call->user_mutex); +mutex_unlock (&call->user_mutex); error_put:rxrpc_put_call (call, rxrpc_call_put);_leave (" = %d" , ret);
@@ -793,7 +793,6 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, struct msghdr *msg, size_t len, rxrpc_notify_end_tx_t notify_end_tx) { - bool dropped_lock = false; int ret;_enter ("{%d,%s}," , call->debug_id, rxrpc_call_states[call->state]);
@@ -811,8 +810,8 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,case RXRPC_CALL_SERVER_ACK_REQUEST :case RXRPC_CALL_SERVER_SEND_REPLY : ret =rxrpc_send_data (rxrpc_sk (sock->sk), call, msg, len, - notify_end_tx, &dropped_lock); -break ; + notify_end_tx); + goto out;case RXRPC_CALL_COMPLETE :read_lock_bh (&call->state_lock); ret = call->error;
@@ -825,8 +824,8 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,break ; } -if (!dropped_lock) -mutex_unlock (&call->user_mutex); +mutex_unlock (&call->user_mutex); +out:_leave (" = %d" , ret);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 758/2214 SUNRPC: fix oversized GSS proxy token copy
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 62319c2534b603b416fa2aa2f3ef18c311f75010 ]
gss_read_proxy_verf() allocates one page per token chunk, but it copies the entire linear head of an RPC request into in_token->pages[0]. A UDP datagram can leave more than PAGE_SIZE bytes in the linear head, so a large RPCSEC_GSS INIT token overwrites following pages.
Copy the linear head in page-sized chunks before switching to the request page array. The linear head itself can span multiple pages.
--- net/sunrpc/auth_gss/svcauth_gss.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +4 -3
@@ -1185,10 +1185,11 @@ static int gss_read_proxy_verf(struct svc_rqst *rqstp, } length = min_t(unsigned int, inlen, argv->iov_len); -if (length) -memcpy (page_address (in_token->pages[0 ]), argv->iov_base, length); +for (to_offs =0 ; to_offs < length; to_offs +=PAGE_SIZE ) +memcpy (page_address (in_token->pages[to_offs >>PAGE_SHIFT ]), + (char *)argv->iov_base + to_offs, + min_t(unsigned int, length - to_offs, PAGE_SIZE)); inlen -= length; - to_offs = length; from_offs = rqstp->rq_arg.page_base;while (inlen) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 759/2214 ALSA: x86: hdmi: fix chmap array missing terminator entry
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 f5e1a9a3fddab8421416b68bb132ae9626d07156 ]
had_build_channel_allocation_map() allocates a single struct snd_pcm_chmap_elem via kzalloc() and stores it as intelhaddata->chmap->chmap. struct snd_pcm_chmap.chmap is expected to be a zero-terminated array (see snd_pcm_std_chmaps[]), but had_register_chmap_ctls() never overrides the TLV callback installed by snd_pcm_add_chmap_ctls(), so the generic pcm_chmap_ctl_tlv() from ALSA core is left in place.
pcm_chmap_ctl_tlv() is reachable by any local user via SNDRV_CTL_IOCTL_TLV_READ on the "Playback Channel Map" control and walks the array with "for (map = info->chmap; map->channels; map++)". Since the driver's single element is never terminated, this walks past the allocation. The same pointer is also freed on hot-unplug and rebuilt on hot-plug under intelhaddata->mutex, while the TLV callback runs under card->controls_rwsem without that mutex, so the walk can also race a concurrent free of the array.
Fix this by allocating a second, zeroed element so the array is properly terminated, and by dropping the inherited TLV callback entirely at registration time, since the driver never implements one of its own.
--- sound/x86/intel_hdmi_audio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/x86/intel_hdmi_audio.c +8 -1
@@ -476,7 +476,8 @@ static void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata)kfree (intelhaddata->chmap->chmap); intelhaddata->chmap->chmap =NULL ; - chmap =kzalloc (sizeof (*chmap),GFP_KERNEL ); +/* info->chmap must be zero-terminated; allocate a spare terminator entry */ + chmap =kcalloc (2 ,sizeof (*chmap),GFP_KERNEL );if (!chmap)return ;
@@ -579,6 +580,12 @@ static int had_register_chmap_ctls(struct snd_intelhad *intelhaddata, intelhaddata->chmap->kctl->info = had_chmap_ctl_info; intelhaddata->chmap->kctl->get = had_chmap_ctl_get; intelhaddata->chmap->chmap =NULL ; + +/* drop the inherited TLV read: it walks chmap without our mutex */ + intelhaddata->chmap->kctl->tlv.c =NULL ; + intelhaddata->chmap->kctl->vd[0 ].access &= + ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ |SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK ); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 760/2214 nvmet-rdma: fix out-of-bounds write in nvmet_rdma_map_sgl_inline()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Stellman <[email protected]>
[ Upstream commit d1512773a0d539669440bd9f6d050b8e12923b5f ]
nvmet_rdma_map_sgl_inline() bounds the host-supplied in-capsule SGL offset with "off + len > inline_data_size", evaluated in 64-bit arithmetic. off is taken straight from the host SGL descriptor (le64_to_cpu(sgl->addr)) and len is promoted to 64-bit, so the sum
wraps: an off within len of 2^64 makes it small and the check passes. off is then used as page_idx = off / PAGE_SIZE to index the fixed-size rsp->cmd->inline_sg[] array (NVMET_RDMA_MAX_INLINE_SGE entries), so a crafted offset yields an out-of-bounds scatterlist index that is written through in nvmet_rdma_use_inline_sg().
The mapping runs while handling a received capsule, before the command executes, so a remote RDMA peer can reach it (the Connect capsule is a write and takes this path on a queue that has no controller yet). The host controls only the low bits of the resulting displacement, so the expected impact is an out-of-bounds write that faults the target (remote denial of service).
This wrap was reported, with a KASAN reproduction, on linux-nvme in May, and the check below was suggested in that thread. The fix that was applied, 48c0162f647b, reworked how the offset is mapped but kept the original check, and its page index turns a wrapped offset into an out-of-bounds index into inline_sg[].
Reject the offset before it can wrap.
Found independently by static analysis with AI assistance, not reproduced at runtime.
--- drivers/nvme/target/rdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/target/rdma.c +2 -1
@@ -864,7 +864,8 @@ static u16 nvmet_rdma_map_sgl_inline(struct nvmet_rdma_rsp *rsp)return NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ; } -if (off + len > rsp->queue->dev->inline_data_size) { +if (off > (u64 )rsp->queue->dev->inline_data_size || + len > (u64 )rsp->queue->dev->inline_data_size - off) {pr_err ("invalid inline data offset!\n" );return NVME_SC_SGL_INVALID_OFFSET |NVME_STATUS_DNR ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 761/2214 net: limit priority VLAN untag depth
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kamil Sawicki <[email protected]>
[ Upstream commit d3ff07f5acc573e5f72bf1c581bae5d05191ba61 ]
The priority VLAN receive path can repeatedly remove VID 0 tags and retry packet processing. Unlike the read-only VLAN protocol parser, this path has no limit on the number of nested tags it consumes.
Each skb_vlan_untag() advances skb->data and resets header offsets. The offsets are stored in 16-bit fields. With enough nested tags, the network or transport offset can wrap. A later protocol handler can then derive a large pull length from the wrapped offsets and access memory outside the skb allocation.
Apply the existing VLAN_MAX_DEPTH limit to the exceptional VID 0 retry. Count the tag already stored in skb VLAN metadata as the first level, then stop before untagging a ninth level. Keep the accounting inside this uncommon branch so the regular VLAN receive path is unaffected.
A single VID 0 priority tag before a real VLAN tag is valid. No normal deployment was found that intentionally emits multiple consecutive VID 0 tags; permitting eight levels is therefore conservative.
The issue was found while researching the Linux network receive path for Google kvmCTF, with OpenAI Codex (gpt-5.6-sol) assisting the analysis. The affected path, reproducer and fix were manually reviewed and tested.
[ Backport to 5.15.y: __netif_receive_skb_core() has no local
drop_reason variable, and this branch does not define SKB_DROP_REASON_RECURSION_LIMIT. Omit the upstream assignment and keep the existing drop path, which frees the skb with kfree_skb(). ]
--- net/core/dev.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/core/dev.c +6 -0
@@ -5461,6 +5461,8 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, }if (unlikely (skb_vlan_tag_present (skb)) && !netdev_uses_dsa (skb->dev)) { +unsigned int priority_tag_depth =1 ; + check_vlan_id:if (skb_vlan_tag_get_id (skb)) {/* Vlan id is non 0 and vlan_do_receive() above couldn't
@@ -5472,6 +5474,10 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc,* 802.1Q or 802.1AD and vlan_do_receive() above could * not find vlan dev for vlan id 0. */ +if (unlikely (priority_tag_depth >=VLAN_MAX_DEPTH )) + goto drop; + + priority_tag_depth++;__vlan_hwaccel_clear_tag (skb); skb =skb_vlan_untag (skb);if (unlikely (!skb))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 762/2214 smb: client: hold server info until cifsd exits
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zateev <[email protected]>
[ Upstream commit 482c117c6dbeee382790168af10959810450ab09 ]
The last session reference can be dropped while the cifsd demultiplex thread is still running clean_demultiplex_info(). That thread frees TCP_Server_Info there, racing with cifs_put_tcp_session() as it releases the server crypto state. syzbot reported a KASAN use-after-free in cifs_crypto_secmech_release().
Keep an object reference for the cifsd thread. Defer final crypto, session-key, network namespace, string, and structure cleanup until both the last session reference and the thread reference are dropped. Drop the thread reference after clean_demultiplex_info() has finished using the server.
Build-tested with ARCH=arm64 and W=1 for fs/smb/client/connect.o. The KASAN reproducer was not run on the patched kernel.
--- fs/cifs/cifsglob.h | 2 ++ fs/cifs/connect.c | 38 +++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-)
fs/cifs/cifsglob.h +2 -0
@@ -16,6 +16,7 @@#include <linux/scatterlist.h> #include <linux/mm.h> #include <linux/mempool.h> +#include <linux/refcount.h> #include <linux/workqueue.h> #include "cifs_fs_sb.h" #include "cifsacl.h"
@@ -578,6 +579,7 @@ struct TCP_Server_Info {struct list_head smb_ses_list;__u64 conn_id;/* connection identifier (useful for debugging) */ int srv_count;/* reference counter */ +refcount_t obj_refs;/* struct lifetime: srv_count users + cifsd */ /* 15 character server name + 0x20 16th byte indicating type = srv */ char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL ];struct smb_version_operations *ops;
fs/cifs/connect.c +23 -15
@@ -754,6 +754,22 @@ handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server,dequeue_mid (mid, malformed); } +static void cifs_tcp_server_put (struct TCP_Server_Info *server) +{ +if (!refcount_dec_and_test (&server->obj_refs)) +return ; + +cifs_crypto_secmech_release (server); +kfree_sensitive (server->session_key.response); +put_net (cifs_net_ns (server)); +#ifdef CONFIG_CIFS_DFS_UPCALL +kfree (server->origin_fullpath); +kfree (server->leaf_fullpath); +#endif +kfree (server->hostname); +kfree_sensitive (server); +} +static void clean_demultiplex_info (struct TCP_Server_Info *server) {int length;
@@ -839,15 +855,11 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)*/ } -#ifdef CONFIG_CIFS_DFS_UPCALL -kfree (server->origin_fullpath); -kfree (server->leaf_fullpath); -#endif -kfree (server); - length =atomic_dec_return (&tcpSesAllocCount);if (length >0 )mempool_resize (cifs_req_poolp, length + cifs_min_rcv); + +cifs_tcp_server_put (server); } static int
@@ -1374,8 +1386,6 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)/* srv_count can never go negative */ WARN_ON (server->srv_count <0 ); -put_net (cifs_net_ns (server)); -list_del_init (&server->tcp_ses_list);spin_unlock (&cifs_tcp_ses_lock);
@@ -1397,18 +1407,13 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) server->tcpStatus = CifsExiting;spin_unlock (&GlobalMid_Lock); -cifs_crypto_secmech_release (server);cifs_fscache_release_client_cookie (server); -kfree (server->session_key.response); - server->session_key.response =NULL ; - server->session_key.len =0 ; -kfree (server->hostname); - server->hostname =NULL ; - task =xchg (&server->tsk,NULL );if (task)send_sig (SIGKILL , task,1 ); + +cifs_tcp_server_put (server); } struct TCP_Server_Info *
@@ -1429,6 +1434,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx) rc = -ENOMEM ; goto out_err; } +refcount_set (&tcp_ses->obj_refs,1 ); tcp_ses->hostname =kstrdup (ctx->server_hostname,GFP_KERNEL );if (!tcp_ses->hostname) {
@@ -1525,6 +1531,8 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx)* this will succeed. No need for try_module_get(). */ __module_get (THIS_MODULE ); +/* Keep the server alive until the demultiplex thread has exited */ +refcount_inc (&tcp_ses->obj_refs); tcp_ses->tsk =kthread_run (cifs_demultiplex_thread, tcp_ses,"cifsd" );if (IS_ERR (tcp_ses->tsk)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 763/2214 ovl: take a snapshot of the name for copy up
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 65bf000962a33ec9d2488e4e1797b6cf630abcbb ]
The copy up of a directory reads a freed dentry name when a lookup moves the directory at the same time.
A pointer to the name of a dentry is only valid while something stops a move of the dentry. ovl_do_copy_up() keeps a plain copy of c->dentry->d_name in c->destname, and ovl_copy_up_start() only keeps ovl_rename() away. When a lookup finds the same directory under another name after a change to the lower layer, d_splice_alias() moves the dentry and frees its external name.
With a delay in ovl_do_copy_up(), a chmod of a lower-only directory with a 60 byte name raced with a rename of that directory in the lower layer and a stat of the new name, and KASAN reported a use-after-free in lookup_noperm_common().
Fix this by using take_dentry_name_snapshot() for c->destname.
--- fs/overlayfs/copy_up.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
fs/overlayfs/copy_up.c +14 -2
@@ -791,6 +791,7 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c) {int err;struct ovl_fs *ofs =OVL_FS (c->dentry->d_sb); +struct name_snapshot name;bool to_index = false;/*
@@ -819,13 +820,23 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)/* Disconnected dentry must be copied up to index dir */ return -EIO ; }else { +/* +* ovl_copy_up_start() keeps ovl_rename() away from c->dentry, +* because ovl_rename() calls ovl_copy_up() on source and target +* dentry. It does not stop d_splice_alias() from moving a +* directory that a lookup found under another name after a +* change to the lower layer. That move frees an external name, +* so take a snapshot. +*/ +take_dentry_name_snapshot (&name, c->dentry); + c->destname = name.name;/* * Mark parent "impure" because it may now contain non-pure * upper */ err =ovl_set_impure (c->parent, c->destdir);if (err) -return err; + goto out; }/* Should we copyup with O_TMPFILE or with workdir? */
@@ -857,6 +868,8 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c) out:if (to_index)kfree (c->destname.name); +else +release_dentry_name_snapshot (&name);return err; }
@@ -982,7 +995,6 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,if (parent) {ovl_path_upper (parent, &parentpath); ctx.destdir = parentpath.dentry; - ctx.destname = dentry->d_name; err = vfs_getattr(&parentpath, &ctx.pstat, STATX_ATIME | STATX_MTIME,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 764/2214 ovl: add ovl_upper_mnt_userns() wrapper
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 b65c20acef23cea2989c9f23414930149d38962f ]
Add a tiny wrapper to retrieve the upper mount's idmapping. Have it return the initial idmapping until we have prepared and converted all places to take the relevant idmapping into account. Then we can switch on idmapped layer support by having ovl_upper_mnt_userns() return the upper mount's idmapping.
Stable-dep-of: 755b5c5c9277 ("ovl: do not copy up an xattr value that was never read")
--- fs/overlayfs/ovl_entry.h | 5 +++++ 1 file changed, 5 insertions(+)
fs/overlayfs/ovl_entry.h +5 -0
@@ -99,6 +99,11 @@ static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)return ofs->layers[0 ].mnt; } +static inline struct user_namespace *ovl_upper_mnt_userns (struct ovl_fs *ofs) +{ +return &init_user_ns; +} +static inline struct ovl_fs *OVL_FS (struct super_block *sb) {return (struct ovl_fs *)sb->s_fs_info;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 765/2214 ovl: pass ofs to setattr operations
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 5272eaf3a5682750f6f26ec542b206f0821fb3cb ]
Pass down struct ovl_fs to setattr operations so we can ultimately retrieve the relevant upper mount and take the mount's idmapping into account when creating new filesystem objects. This is needed to support idmapped base layers with overlay.
Stable-dep-of: 755b5c5c9277 ("ovl: do not copy up an xattr value that was never read")
--- fs/overlayfs/copy_up.c | 19 +++++++++++-------- fs/overlayfs/dir.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-)
fs/overlayfs/copy_up.c +11 -8
@@ -292,7 +292,8 @@ static int ovl_copy_up_data(struct ovl_fs *ofs, struct path *old,return error; } -static int ovl_set_size (struct dentry *upperdentry,struct kstat *stat) +static int ovl_set_size (struct ovl_fs *ofs, +struct dentry *upperdentry,struct kstat *stat) {struct iattr attr = { .ia_valid =ATTR_SIZE ,
@@ -302,7 +303,8 @@ static int ovl_set_size(struct dentry *upperdentry, struct kstat *stat)return notify_change (&init_user_ns, upperdentry, &attr,NULL ); } -static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat) +static int ovl_set_timestamps(struct ovl_fs *ofs, struct dentry *upperdentry, + struct kstat *stat) { struct iattr attr = { .ia_valid =
@@ -314,7 +316,8 @@ static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat)return notify_change (&init_user_ns, upperdentry, &attr,NULL ); } -int ovl_set_attr (struct dentry *upperdentry,struct kstat *stat) +int ovl_set_attr (struct ovl_fs *ofs,struct dentry *upperdentry, +struct kstat *stat) {int err =0 ;
@@ -334,7 +337,7 @@ int ovl_set_attr(struct dentry *upperdentry, struct kstat *stat) err =notify_change (&init_user_ns, upperdentry, &attr,NULL ); }if (!err) -ovl_set_timestamps (upperdentry, stat); +ovl_set_timestamps (ofs, upperdentry, stat);return err; }
@@ -540,7 +543,7 @@ static int ovl_link_up(struct ovl_copy_up_ctx *c)if (!err) {/* Restore timestamps on parent (best effort) */ -ovl_set_timestamps (upperdir, &c->pstat); +ovl_set_timestamps (ofs, upperdir, &c->pstat);ovl_dentry_set_upper_alias (c->dentry);ovl_dentry_update_reval (c->dentry, upper); }
@@ -617,9 +620,9 @@ static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp)inode_lock (temp->d_inode);if (S_ISREG (c->stat.mode)) - err =ovl_set_size (temp, &c->stat); + err =ovl_set_size (ofs, temp, &c->stat);if (!err) - err =ovl_set_attr (temp, &c->stat); + err =ovl_set_attr (ofs, temp, &c->stat);inode_unlock (temp->d_inode);return err;
@@ -858,7 +861,7 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)/* Restore timestamps on parent (best effort) */ inode_lock (udir); -ovl_set_timestamps (c->destdir, &c->pstat); +ovl_set_timestamps (ofs, c->destdir, &c->pstat);inode_unlock (udir);ovl_dentry_set_upper_alias (c->dentry);
fs/overlayfs/dir.c +1 -1
@@ -407,7 +407,7 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry, goto out_cleanup;inode_lock (opaquedir->d_inode); - err =ovl_set_attr (opaquedir, &stat); + err =ovl_set_attr (ofs, opaquedir, &stat);inode_unlock (opaquedir->d_inode);if (err) goto out_cleanup;
fs/overlayfs/overlayfs.h +1 -1
@@ -618,7 +618,7 @@ int ovl_copy_up_with_data(struct dentry *dentry);int ovl_maybe_copy_up (struct dentry *dentry,int flags);int ovl_copy_xattr (struct super_block *sb,struct dentry *old,struct dentry *new); -int ovl_set_attr (struct dentry *upper,struct kstat *stat); +int ovl_set_attr (struct ovl_fs *ofs,struct dentry *upper,struct kstat *stat);struct ovl_fh *ovl_encode_real_fh (struct ovl_fs *ofs,struct dentry *real,bool is_upper); int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 766/2214 ovl: use ovl_path_getxattr() wrapper
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 dad7017a840d8d198074338224cd418d37b8f79d ]
Add a helper that allows to retrieve ovl xattrs from either lower or upper layers. To stop passing mnt and dentry separately everywhere use struct path which more accurately reflects the tight coupling between mount and dentry in this helper. Swich over all places to pass a path argument that can operate on either upper or lower layers. This is needed to support idmapped base layers with overlayfs.
Some helpers are always called with an upper dentry, which is now utilized by these helpers to create the path. Make this usage explicit by renaming the argument to "upperdentry" and by renaming the function as well in some cases. Also add a check in ovl_do_getxattr() to catch misuse of these functions.
Stable-dep-of: 755b5c5c9277 ("ovl: do not copy up an xattr value that was never read")
--- fs/overlayfs/copy_up.c | 21 ++++++----- fs/overlayfs/dir.c | 2 +- fs/overlayfs/inode.c | 10 ++++-- fs/overlayfs/namei.c | 37 ++++++++++++------- fs/overlayfs/overlayfs.h | 77 ++++++++++++++++++++++++++++------------ fs/overlayfs/util.c | 29 ++++++++------- 6 files changed, 111 insertions(+), 65 deletions(-)
fs/overlayfs/copy_up.c +10 -11
@@ -44,9 +44,9 @@ static bool ovl_must_copy_xattr(const char *name) !strncmp (name,XATTR_SECURITY_PREFIX ,XATTR_SECURITY_PREFIX_LEN ); } -int ovl_copy_xattr (struct super_block *sb,struct dentry *old, -struct dentry *new) +int ovl_copy_xattr (struct super_block *sb,struct path *oldpath,struct dentry *new) { +struct dentry *old = oldpath->dentry;ssize_t list_size, size, value_size =0 ;char *buf, *name, *value =NULL ;int error =0 ;
@@ -94,9 +94,9 @@ int ovl_copy_xattr(struct super_block *sb, struct dentry *old,continue ;/* Discard */ } retry: - size =vfs_getxattr (&init_user_ns, old, name, value, value_size); + size =ovl_do_getxattr (oldpath, name, value, value_size);if (size == -ERANGE ) - size =vfs_getxattr (&init_user_ns, old, name,NULL ,0 ); + size =ovl_do_getxattr (oldpath, name,NULL ,0 );if (size <0 ) { error = size;
@@ -583,7 +583,7 @@ static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp)return err; } - err =ovl_copy_xattr (c->dentry->d_sb, c->lowerpath.dentry, temp); + err =ovl_copy_xattr (c->dentry->d_sb, &c->lowerpath, temp);if (err)return err;
@@ -893,13 +893,12 @@ static bool ovl_need_meta_copy_up(struct dentry *dentry, umode_t mode,return true; } -static ssize_t ovl_getxattr_value (struct ovl_fs *ofs,struct dentry *dentry, -char *name,char **value) +static ssize_t ovl_getxattr_value (struct path *path,char *name,char **value) {ssize_t res;char *buf; - res =ovl_do_getxattr (ofs, dentry, name,NULL ,0 ); + res =ovl_do_getxattr (path, name,NULL ,0 );if (res == -ENODATA || res == -EOPNOTSUPP ) res =0 ;
@@ -908,7 +907,7 @@ static ssize_t ovl_getxattr_value(struct ovl_fs *ofs, struct dentry *dentry,if (!buf)return -ENOMEM ; - res =ovl_do_getxattr (ofs, dentry, name, buf, res); + res =ovl_do_getxattr (path, name, buf, res);if (res <0 )kfree (buf);else
@@ -935,8 +934,8 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)return -EIO ;if (c->stat.size) { - err = cap_size =ovl_getxattr_value (ofs, upperpath.dentry, -XATTR_NAME_CAPS , &capability); + err = cap_size =ovl_getxattr_value (&upperpath,XATTR_NAME_CAPS , + &capability);if (cap_size <0 ) goto out; }
fs/overlayfs/dir.c +1 -1
@@ -398,7 +398,7 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry,if (IS_ERR (opaquedir)) goto out_unlock; - err =ovl_copy_xattr (dentry->d_sb, upper, opaquedir); + err =ovl_copy_xattr (dentry->d_sb, &upperpath, opaquedir);if (err) goto out_cleanup;
fs/overlayfs/inode.c +7 -3
@@ -922,8 +922,8 @@ unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry,if (!indexed &&d_inode (lowerdentry)->i_nlink ==1 )return fallback; - err =ovl_getxattr (ofs, upperdentry,OVL_XATTR_NLINK , - &buf,sizeof (buf) -1 ); + err =ovl_getxattr_upper (ofs, upperdentry,OVL_XATTR_NLINK , + &buf,sizeof (buf) -1 );if (err <0 ) goto fail;
@@ -1127,6 +1127,10 @@ struct inode *ovl_get_inode(struct super_block *sb,struct inode *realinode = upperdentry ?d_inode (upperdentry) :NULL ;struct inode *inode;struct dentry *lowerdentry = lowerpath ? lowerpath->dentry :NULL ; +struct path realpath = { + .dentry = upperdentry ?: lowerdentry, + .mnt = upperdentry ?ovl_upper_mnt (ofs) : lowerpath->layer->mnt, + };bool bylower =ovl_hash_bylower (sb, upperdentry, lowerdentry, oip->index);int fsid = bylower ? lowerpath->layer->fsid :0 ;
@@ -1200,7 +1204,7 @@ struct inode *ovl_get_inode(struct super_block *sb,/* Check for non-merge dir that may have whiteouts */ if (is_dir) {if (((upperdentry && lowerdentry) || oip->numlower >1 ) || -ovl_check_origin_xattr (ofs, upperdentry ?: lowerdentry)) { +ovl_path_check_origin_xattr (ofs, &realpath)) {ovl_set_flag (OVL_WHITEOUTS , inode); } }
fs/overlayfs/namei.c +24 -13
@@ -16,6 +16,7 @@struct ovl_lookup_data {struct super_block *sb; +struct vfsmount *mnt;struct qstr name;bool is_dir;bool opaque;
@@ -25,14 +26,14 @@ struct ovl_lookup_data {bool metacopy; }; -static int ovl_check_redirect (struct dentry *dentry,struct ovl_lookup_data *d, +static int ovl_check_redirect (struct path *path,struct ovl_lookup_data *d,size_t prelen,const char *post) {int res;char *buf;struct ovl_fs *ofs =OVL_FS (d->sb); - buf =ovl_get_redirect_xattr (ofs, dentry, prelen +strlen (post)); + buf =ovl_get_redirect_xattr (ofs, path, prelen +strlen (post));if (IS_ERR_OR_NULL (buf))return PTR_ERR (buf);
@@ -105,13 +106,13 @@ int ovl_check_fb_len(struct ovl_fb *fb, int fb_len)return 0 ; } -static struct ovl_fh *ovl_get_fh (struct ovl_fs *ofs,struct dentry *dentry, +static struct ovl_fh *ovl_get_fh (struct ovl_fs *ofs,struct dentry *upperdentry,enum ovl_xattr ox) {int res, err;struct ovl_fh *fh =NULL ; - res =ovl_getxattr (ofs, dentry, ox,NULL ,0 ); + res =ovl_getxattr_upper (ofs, upperdentry, ox,NULL ,0 );if (res <0 ) {if (res == -ENODATA || res == -EOPNOTSUPP )return NULL ;
@@ -125,7 +126,7 @@ static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *dentry,if (!fh)return ERR_PTR (-ENOMEM ); - res =ovl_getxattr (ofs, dentry, ox, fh->buf, res); + res =ovl_getxattr_upper (ofs, upperdentry, ox, fh->buf, res);if (res <0 ) goto fail;
@@ -193,9 +194,9 @@ struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,return real; } -static bool ovl_is_opaquedir (struct super_block *sb,struct dentry *dentry) +static bool ovl_is_opaquedir (struct ovl_fs *ofs,struct path *path) { -return ovl_check_dir_xattr (sb, dentry,OVL_XATTR_OPAQUE ); +return ovl_path_check_dir_xattr (ofs, path,OVL_XATTR_OPAQUE ); } static struct dentry *ovl_lookup_positive_unlocked(const char *name,
@@ -224,6 +225,7 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d, struct dentry **ret, bool drop_negative) {struct dentry *this; +struct path path;int err;bool last_element = !post[0 ];
@@ -253,12 +255,15 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d, d->stop = true; goto put_and_out; } + + path.dentry = this; + path.mnt = d->mnt;if (!d_can_lookup (this)) {if (d->is_dir || !last_element) { d->stop = true; goto put_and_out; } - err =ovl_check_metacopy_xattr (OVL_FS (d->sb), this); + err =ovl_check_metacopy_xattr (OVL_FS (d->sb), &path);if (err <0 ) goto out_err;
@@ -278,14 +283,14 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,if (d->last) goto out; -if (ovl_is_opaquedir (d->sb, this)) { +if (ovl_is_opaquedir (OVL_FS (d->sb), &path)) { d->stop = true;if (last_element) d->opaque = true; goto out; } } - err =ovl_check_redirect (this, d, prelen, post); + err =ovl_check_redirect (&path, d, prelen, post);if (err) goto out_err; out:
@@ -856,6 +861,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, old_cred =ovl_override_creds (dentry->d_sb); upperdir =ovl_dentry_upper (dentry->d_parent);if (upperdir) { + d.mnt =ovl_upper_mnt (ofs); err =ovl_lookup_layer (upperdir, &d, &upperdentry, true);if (err) goto out;
@@ -911,6 +917,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,else d.last = lower.layer->idx == roe->numlower; + d.mnt = lower.layer->mnt; err =ovl_lookup_layer (lower.dentry, &d, &this, false);if (err) goto out_put;
@@ -1071,14 +1078,18 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,if (upperdentry)ovl_dentry_set_upper_alias (dentry);else if (index) { - upperdentry =dget (index); - upperredirect =ovl_get_redirect_xattr (ofs, upperdentry,0 ); +struct path upperpath = { + .dentry = upperdentry =dget (index), + .mnt =ovl_upper_mnt (ofs), + }; + + upperredirect =ovl_get_redirect_xattr (ofs, &upperpath,0 );if (IS_ERR (upperredirect)) { err =PTR_ERR (upperredirect); upperredirect =NULL ; goto out_free_oe; } - err =ovl_check_metacopy_xattr (ofs, upperdentry); + err =ovl_check_metacopy_xattr (ofs, &upperpath);if (err <0 ) goto out_free_oe; uppermetacopy = err;
fs/overlayfs/overlayfs.h +55 -22
128 lines not on this page · raw message
fs/overlayfs/util.c +14 -15
@@ -584,11 +584,11 @@ void ovl_copy_up_end(struct dentry *dentry)ovl_inode_unlock (d_inode (dentry)); } -bool ovl_check_origin_xattr (struct ovl_fs *ofs,struct dentry *dentry) +bool ovl_path_check_origin_xattr (struct ovl_fs *ofs,struct path *path) {int res; - res =ovl_getxattr (ofs, dentry,OVL_XATTR_ORIGIN ,NULL ,0 ); + res =ovl_path_getxattr (ofs, path,OVL_XATTR_ORIGIN ,NULL ,0 );/* Zero size value means "copied up but origin unknown" */ if (res >=0 )
@@ -597,16 +597,16 @@ bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry)return false; } -bool ovl_check_dir_xattr (struct super_block *sb,struct dentry *dentry, -enum ovl_xattr ox) +bool ovl_path_check_dir_xattr (struct ovl_fs *ofs,struct path *path, +enum ovl_xattr ox) {int res;char val; -if (!d_is_dir (dentry)) +if (!d_is_dir (path->dentry))return false; - res =ovl_getxattr (OVL_FS (sb), dentry, ox, &val,1 ); + res =ovl_path_getxattr (ofs, path, ox, &val,1 );if (res ==1 && val =='y' )return true;
@@ -686,8 +686,8 @@ void ovl_check_protattr(struct inode *inode, struct dentry *upper)char buf[OVL_PROTATTR_MAX +1 ];int res, n; - res =ovl_getxattr (ofs, upper,OVL_XATTR_PROTATTR , buf, -OVL_PROTATTR_MAX ); + res =ovl_getxattr_upper (ofs, upper,OVL_XATTR_PROTATTR , buf, +OVL_PROTATTR_MAX );if (res <0 )return ;
@@ -977,15 +977,15 @@ int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir) }/* err < 0, 0 if no metacopy xattr, 1 if metacopy xattr found */ -int ovl_check_metacopy_xattr (struct ovl_fs *ofs,struct dentry *dentry) +int ovl_check_metacopy_xattr (struct ovl_fs *ofs,struct path *path) {int res;/* Only regular files can have metacopy xattr */ -if (!S_ISREG (d_inode (dentry)->i_mode)) +if (!S_ISREG (d_inode (path->dentry)->i_mode))return 0 ; - res =ovl_getxattr (ofs, dentry,OVL_XATTR_METACOPY ,NULL ,0 ); + res =ovl_path_getxattr (ofs, path,OVL_XATTR_METACOPY ,NULL ,0 );if (res <0 ) {if (res == -ENODATA || res == -EOPNOTSUPP )return 0 ;
@@ -1021,13 +1021,12 @@ bool ovl_is_metacopy_dentry(struct dentry *dentry)return (oe->numlower >1 ); } -char *ovl_get_redirect_xattr (struct ovl_fs *ofs,struct dentry *dentry, -int padding) +char *ovl_get_redirect_xattr (struct ovl_fs *ofs,struct path *path,int padding) {int res;char *s, *next, *buf =NULL ; - res =ovl_getxattr (ofs, dentry,OVL_XATTR_REDIRECT ,NULL ,0 ); + res =ovl_path_getxattr (ofs, path,OVL_XATTR_REDIRECT ,NULL ,0 );if (res == -ENODATA || res == -EOPNOTSUPP )return NULL ;if (res <0 )
@@ -1039,7 +1038,7 @@ char *ovl_get_redirect_xattr(struct ovl_fs *ofs, struct dentry *dentry,if (!buf)return ERR_PTR (-ENOMEM ); - res =ovl_getxattr (ofs, dentry,OVL_XATTR_REDIRECT , buf, res); + res =ovl_path_getxattr (ofs, path,OVL_XATTR_REDIRECT , buf, res);if (res <0 ) goto fail;if (res ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 767/2214 ovl: do not copy up an xattr value that was never read
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 755b5c5c9277be251a51623d6065abab948c61bc ]
Copy-up stores uninitialized kernel memory in an xattr of the upper file, where the user can read it.
ovl_copy_xattr() may only pass bytes to ovl_do_setxattr() that ovl_do_getxattr() has read. When the read fails with -ERANGE the function asks for the size again, and if the new size fits the buffer it stores the buffer although nothing was read into it. The buffer comes from kvmalloc(), or it still holds the value of the previous xattr.
A FUSE lower layer that answers every sized GETXATTR with -ERANGE made copy-up store 4096 bytes that the server never sent, with a kernel pointer in them, as an xattr of the upper file.
Fix this by failing the copy-up with -EIO when the size that follows -ERANGE fits the buffer.
--- fs/overlayfs/copy_up.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/overlayfs/copy_up.c +5 -1
@@ -95,8 +95,12 @@ int ovl_copy_xattr(struct super_block *sb, struct path *oldpath, struct dentry * } retry: size =ovl_do_getxattr (oldpath, name, value, value_size); -if (size == -ERANGE ) +if (size == -ERANGE ) { size =ovl_do_getxattr (oldpath, name,NULL ,0 ); +/* Nothing was read into value, so it must not be used */ +if (size >=0 && size <= value_size) + size = -EIO ; + }if (size <0 ) { error = size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 768/2214 ovl: hold a reference on the parent in readdir
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 16d319e12328acafeafd3eecdf09c46d7fb43452 ]
Listing a directory on an overlay uses a freed dentry and crashes the kernel when a lookup moves the directory at the same time.
Code that can sleep may only use d_parent without a reference while something stops a move of the dentry. ovl_iterate_real(), ovl_need_adjust_d_ino() and ovl_cache_update() use the d_parent of the listed directory and hold only the lock of that directory. When a lookup finds the directory under another parent after a change to a layer, d_splice_alias() moves it without that lock and drops its reference on the old parent.
With a delay in ovl_iterate_real(), getdents64 on an overlay directory raced a rename in the lower layer and a lookup that moved its dentry, and after an rmdir of the old parent KASAN reported a use-after-free in security_inode_getattr().
Fix this by using dget_parent() in the three functions.
--- fs/overlayfs/readdir.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
fs/overlayfs/readdir.c +18 -6
@@ -474,8 +474,8 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p) goto get; }if (p->len ==2 && p->name[1 ] =='.' ) { -/* we shall not be moved */ - this =dget (dir->d_parent); +/* d_splice_alias() can move even a locked dir */ + this =dget_parent (dir); goto get; } }
@@ -693,6 +693,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)struct ovl_dir_file *od = file->private_data;struct dentry *dir = file->f_path.dentry;const struct ovl_layer *lower_layer =ovl_layer_lower (dir); +struct dentry *parent;struct ovl_readdir_translate rdt = { .ctx.actor = ovl_fill_real, .orig_ctx = ctx,
@@ -703,18 +704,26 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)if (rdt.xinobits && lower_layer) rdt.fsid = lower_layer->fsid; -if (OVL_TYPE_MERGE (ovl_path_type (dir->d_parent))) { +/* +* The lock on dir does not stop d_splice_alias() from moving it to +* another parent, which drops the reference dir holds on this one. +*/ + parent =dget_parent (dir); +if (OVL_TYPE_MERGE (ovl_path_type (parent))) {struct kstat stat;struct path statpath = file->f_path; - statpath.dentry = dir->d_parent; + statpath.dentry = parent; err =vfs_getattr (&statpath, &stat,STATX_INO ,0 ); -if (err) +if (err) { +dput (parent);return err; + }WARN_ON_ONCE (dir->d_sb->s_dev != stat.dev); rdt.parent_ino = stat.ino; } +dput (parent);if (ovl_is_impure_dir (file)) { rdt.cache =ovl_cache_get_impure (&file->f_path);
@@ -742,6 +751,8 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)ovl_dir_reset (file);if (od->is_real) { +struct dentry *parent =dget_parent (dentry); +/* * If parent is merge, then need to adjust d_ino for '..', if * dir is impure then need to adjust d_ino for copied up
@@ -750,11 +761,12 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)if (ovl_xino_bits (dentry->d_sb) || (ovl_same_fs (dentry->d_sb) && (ovl_is_impure_dir (file) || -OVL_TYPE_MERGE (ovl_path_type (dentry->d_parent))))) { +OVL_TYPE_MERGE (ovl_path_type (parent))))) { err =ovl_iterate_real (file, ctx); }else { err =iterate_dir (od->realfile, ctx); } +dput (parent); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 769/2214 ovl: do not copy up a dentry that was removed
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 f635192ad223d2009ee640b63adf5ce3198aa338 ]
A change to a removed file through an open descriptor replaces whatever has its old name in the upper layer.
Copy up must only create a name in the upper directory, never replace one. After an unlink, an rmdir or a rename over a lower dentry, a dentry that an open file keeps alive still has its old parent and name, but in the upper directory that name is now a whiteout or a new object. ovl_copy_up_workdir() renames the copy over it, which brings back the removed object and destroys whatever took its name.
An unprivileged user opened a lower FIFO and unlinked it, root created a file at that name, and fchmod on the old descriptor replaced the file of root with the FIFO.
Fix this by looking up the target name of the rename in ovl_copy_up_workdir() with LOOKUP_EXCL, so that copy up fails with -EEXIST if the name is taken, as copy up with O_TMPFILE already does when it links the copy to the name.
--- fs/overlayfs/copy_up.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/overlayfs/copy_up.c +4 -1
@@ -710,7 +710,10 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)if (IS_ERR (upper)) goto cleanup; - err =ovl_do_rename (ofs, wdir, temp, udir, upper,0 ); +/* The name may have been taken since lookup, never replace it */ + err = -EEXIST ; +if (!d_is_positive (upper)) + err =ovl_do_rename (ofs, wdir, temp, udir, upper,0 );dput (upper);if (err) goto cleanup;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 770/2214 ovl: check that the parents of volatile/dirty are dirs
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 e34d2ef818e4c7676d8d8e1bf43e6a1ed39efb2a ]
An unprivileged user crashes the kernel by mounting overlayfs with the volatile option.
A dentry that serves as the parent of a lookup must be a directory. ovl_create_volatile_dirty() walks work/incompat/volatile/dirty by name, and ovl_lookup_or_create() returns an existing entry whatever its type. A file or a symlink that another task creates during the mount becomes the parent of the next lookup, which calls a NULL ->lookup.
An unprivileged user mounted overlayfs with "volatile" in a user namespace while a second process created a symlink named work/incompat, and the mount task oopsed on a NULL ->lookup call.
Fix this by returning -ENOTDIR from ovl_lookup_or_create() when the caller asked for a directory and the existing entry is a non-dir.
--- fs/overlayfs/super.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
fs/overlayfs/super.c +12 -5
@@ -1321,16 +1321,23 @@ static int ovl_check_rename_whiteout(struct ovl_fs *ofs)static struct dentry *ovl_lookup_or_create (struct ovl_fs *ofs,struct dentry *parent, -const char *name,umode_t mode) +const char *name,bool is_dir) {size_t len =strlen (name);struct dentry *child;inode_lock_nested (parent->d_inode,I_MUTEX_PARENT ); child =lookup_one_len (name, parent, len); -if (!IS_ERR (child) && !child->d_inode) - child =ovl_create_real (ofs, parent->d_inode, child, -OVL_CATTR (mode)); +if (!IS_ERR (child)) { +if (!child->d_inode) { + child =ovl_create_real (ofs, parent->d_inode, child, +OVL_CATTR (is_dir ?S_IFDIR : +S_IFREG )); + }else if (is_dir && !d_can_lookup (child)) { +dput (child); + child =ERR_PTR (-ENOTDIR ); + } + }inode_unlock (parent->d_inode);dput (parent);
@@ -1351,7 +1358,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs)const char *const *name = volatile_path;for (ctr =ARRAY_SIZE (volatile_path); ctr; ctr--, name++) { - d =ovl_lookup_or_create (ofs, d, *name, ctr >1 ?S_IFDIR :S_IFREG ); + d =ovl_lookup_or_create (ofs, d, *name, ctr >1 );if (IS_ERR (d))return PTR_ERR (d); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 771/2214 xfs: bound inode fork length against the fork size during log recovery
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
[ Upstream commit 9232301894a06e664d8de2da97175cf98419bd16 ]
xlog_recover_inode_commit_pass2() copies an inode log item's data/attr fork region into the inode buffer using the on-log region length without bounding it against the fork capacity, e.g.:
len = item->ri_buf[2].iov_len; memcpy(XFS_DFORK_DPTR(dip), src, len);
The only guard is an ASSERT, which is a no-op on production kernels (CONFIG_XFS_DEBUG off), and xfs_dinode_verify() runs only after the copy. A crafted image with a dirty log can therefore drive a heap out-of-bounds write at mount time. The XFS_ILOG_DBROOT sibling already passes XFS_DFORK_DSIZE as a bound; the DDATA/DEXT and ADATA/AEXT memcpy paths did not.
Bound each logged fork region against the destination fork size before copying it, and reject the log item with -EFSCORRUPTED when it does not fit. Because the recovered inode is only verified after the fork data has been copied in, the checks are done up front, before any memcpy into the on-disk inode.
--- fs/xfs/xfs_inode_item_recover.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
fs/xfs/xfs_inode_item_recover.c +19 -1
@@ -403,6 +403,25 @@ xlog_recover_inode_commit_pass2(ASSERT (!(fields &XFS_ILOG_DFORK ) || (len == in_f->ilf_dsize)); +/* +* The recovered inode is verified only after the fork data has been +* copied into it, so bound each logged fork region against the size of +* its fork now, before the memcpy below can overrun the on-disk inode. +* The DBROOT/ABROOT cases already bound their copies against the fork +* size. +*/ +if ((fields & (XFS_ILOG_DDATA |XFS_ILOG_DEXT )) && + item->ri_buf[2 ].i_len >XFS_DFORK_DSIZE (dip, mp)) { + error = -EFSCORRUPTED ; + goto out_release; + } +if ((fields & (XFS_ILOG_ADATA |XFS_ILOG_AEXT )) && + item->ri_buf[(fields &XFS_ILOG_DFORK ) ?3 :2 ].i_len > +XFS_DFORK_ASIZE (dip, mp)) { + error = -EFSCORRUPTED ; + goto out_release; + } +switch (fields &XFS_ILOG_DFORK ) {case XFS_ILOG_DDATA :case XFS_ILOG_DEXT :
@@ -442,7 +461,6 @@ xlog_recover_inode_commit_pass2(case XFS_ILOG_ADATA :case XFS_ILOG_AEXT : dest =XFS_DFORK_APTR (dip); -ASSERT (len <=XFS_DFORK_ASIZE (dip, mp));memcpy (dest, src, len);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 772/2214 smb: server: size directory name conversion buffer correctly
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: VeroFess <[email protected]>
[ Upstream commit f1f37834eaba5904103af1f18afe3510c7e9dc71 ]
A 2048-byte ASCII directory name needs 4098 bytes when converted to UTF-16, including the terminator. ksmbd_convert_dir_info_name() caps its allocation at PATH_MAX and writes past the end of that buffer.
Allocate space for one UTF-16 code unit per input byte plus the terminator. Use kmalloc_array() to check the size calculation.
--- fs/ksmbd/misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ksmbd/misc.c +4 -4
@@ -322,12 +322,13 @@ char *ksmbd_convert_dir_info_name(struct ksmbd_dir_info *d_info, int *conv_len) {char *conv; -int sz =min (4 * d_info->name_len,PATH_MAX ); -if (!sz) +if (d_info->name_len <=0 )return NULL ; - conv =kmalloc (sz,GFP_KERNEL ); +/* One UTF-16 code unit per input byte, plus the terminating NUL. */ + conv =kmalloc_array ((size_t )d_info->name_len +1 , +sizeof (__le16),GFP_KERNEL );if (!conv)return NULL ;
@@ -336,7 +337,6 @@ char *ksmbd_convert_dir_info_name(struct ksmbd_dir_info *d_info, d_info->name_len, local_nls, 0); *conv_len *=2 ; -/* We allocate buffer twice bigger than needed. */ conv[*conv_len] =0x00 ; conv[*conv_len +1 ] =0x00 ;return conv;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 773/2214 smb: client: fix fiemap wild read on empty truncated response
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdifatah Suruur <[email protected]>
[ Upstream commit f5baa17a0f316c235d61623ac8e8fb32c2b3c0cc ]
smb3_fiemap() treats -E2BIG from SMB2_ioctl() as a truncated range blob and loops for the next chunk. If the server reports STATUS_BUFFER_OVERFLOW with OutputCount == 0, SMB2_ioctl() returns -E2BIG with out_data == NULL and out_data_len == 0, and the existing length checks accept the empty result. The loop then evaluates
next = out_data[num - 1].file_offset + ...
with num == 0, reading 16 bytes before NULL.
Reject a truncated range blob that contains no range, so the resume offset is never computed from an empty response. Also require the last range in a truncated blob to advance the resume offset without overflowing, and to stay within the requested range; a malicious or broken server could otherwise make no progress or underflow len and loop forever. Free the previous response buffer before retrying.
Reproduced on 6.6.87.2 with a malicious SMB2 server that answers FSCTL_QUERY_ALLOCATED_RANGES with STATUS_BUFFER_OVERFLOW and OutputCount == 0; an FS_IOC_FIEMAP ioctl on the mount oopses in cifs_fiemap() with CR2 = fffffffffffffff8. The code path is unchanged on mainline.
--- fs/cifs/smb2ops.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
fs/cifs/smb2ops.c +27 -3
@@ -4167,6 +4167,15 @@ static int smb3_fiemap(struct cifs_tcon *tcon, goto out; } +/* +* A truncated range blob must contain at least one range, otherwise +* there is no offset to resume from and out_data is NULL. +*/ +if (!last_blob && out_data_len ==0 ) { + rc = -EINVAL ; + goto out; + } + num = out_data_len /sizeof (struct file_allocated_range_buffer );for (i =0 ; i < num; i++) { flags =0 ;
@@ -4187,10 +4196,25 @@ static int smb3_fiemap(struct cifs_tcon *tcon, }if (!last_blob) { - next =le64_to_cpu (out_data[num -1 ].file_offset) + -le64_to_cpu (out_data[num -1 ].length); - len = len - (next - start); +u64 last_start, last_len; + + last_start =le64_to_cpu (out_data[num -1 ].file_offset); + last_len =le64_to_cpu (out_data[num -1 ].length); + +if (check_add_overflow (last_start, last_len, &next) || + next <= start) { + rc = -EINVAL ; + goto out; + } +if (next - start >= len) { + rc =0 ; + goto out; + } + + len -= next - start; start = next; +kfree (out_data); + out_data =NULL ; goto again; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 774/2214 smb: client: fix buffer overflow in SMB2_tcon()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
[ Upstream commit 73cc469b0ff7551f8537ea919709973e6dc4f514 ]
In SMB2_tcon(), unc_path is allocated with a fixed buffer size of MAX_SHARENAME_LENGTH * 2 bytes (672 bytes). However, the user-controlled UNC path (tree) length is passed to cifs_strtoUTF16(), which assumes the destination buffer is large enough and writes strlen(tree) + 1 UTF-16 code units.
Commit 62a1a439e0fd ("cifs: clean up handling of unc= option") removed the length check on UNC mount options, allowing mount paths to exceed MAX_SHARENAME_LENGTH while retaining the fixed-size buffer allocation in SMB2_tcon(). Consequently, an oversized UNC string causes cifs_strtoUTF16() to write past the end of the heap object, resulting in a slab-out-of-bounds write. Furthermore, if a tree exceeds MAX_TREE_SIZE characters, strscpy() truncates it in cifs_tcon::tree_name, causing subsequent reconnects or failovers to fail.
Fix this by first verifying that the length of tree does not exceed MAX_TREE_SIZE, returning -EINVAL if it does. Then, dynamically allocate unc_path based on the length of tree so that it safely accommodates all UTF-16 code units for paths within MAX_TREE_SIZE.
--- fs/cifs/smb2pdu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +9 -3
@@ -1769,8 +1769,6 @@ static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code)cifs_stats_inc (&tcon->stats.smb2_stats.smb2_com_failed[code]); } -#define MAX_SHARENAME_LENGTH (255 /* server */ + 80 /* share */ + 1 /* NULL */) -/* These are similar values to what Windows uses */ static inline void init_copy_chunk_defaults (struct cifs_tcon *tcon) {
@@ -1804,7 +1802,15 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,if (!server || !tree)return -EIO ; - unc_path =kmalloc (MAX_SHARENAME_LENGTH *2 ,GFP_KERNEL ); + total_len =strlen (tree); +if (total_len >MAX_TREE_SIZE ) { +cifs_server_dbg (VFS |ONCE , +"%s: tree name exceeded %u characters\n" , + __func__,MAX_TREE_SIZE ); +return -EINVAL ; + } + + unc_path =kmalloc ((total_len +1 ) *sizeof (*unc_path),GFP_KERNEL );if (unc_path ==NULL )return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 775/2214 smb: client: fix slab-out-of-bounds write in id_mode_to_cifs_acl()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dominik Maier <[email protected]>
[ Upstream commit a377a3645c7d0246af0bc4ef24db94bb2670bdde ]
In id_mode_to_cifs_acl(), while the chown branch reserves sizeof(struct smb_ntsd) + 2 * sizeof(struct smb_sid) (plus sizeof(struct smb_acl) and the worst-case ACE space after commit 0ee150794c75 ("smb: client: fix heap overflow in DACL owner/group rewrite")), the chmod branch only adds 2 * sizeof(struct smb_ace) or 5 * sizeof(struct smb_ace) to secdesclen (or 1 * sizeof(struct smb_ace) on posix).
However, the chmod branch also invokes build_sec_desc() -> copy_sec_desc(), which unconditionally writes the Owner SID at pnntsd + sidsoffset and the Group SID at
pnntsd + sidsoffset + sizeof(struct smb_sid) (2 * 68 = 136 bytes total), and set_chmod_dacl() always writes a struct smb_acl header (8 bytes) even when the source descriptor has dacloffset == 0. When a security descriptor has compact or overlapping Owner/Group SIDs (or dacloffset == 0), calling chmod() under-allocates pnntsd and writes past the end of the slab buffer.
Reserve sizeof(struct smb_acl) + 2 * sizeof(struct smb_sid) (plus sizeof(struct smb_ntsd) on the posix path) in the chmod branch of id_mode_to_cifs_acl().
--- fs/cifs/cifsacl.c | 2 ++ 1 file changed, 2 insertions(+)
fs/cifs/cifsacl.c +2 -0
@@ -1725,6 +1725,8 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,/* Potentially, five new ACEs can be added to the ACL for U,G,O mapping */ nsecdesclen = secdesclen;if (pnmode && *pnmode !=NO_CHANGE_64 ) {/* chmod */ + nsecdesclen +=sizeof (struct cifs_acl ) + +2 *sizeof (struct cifs_sid );if (mode_from_sid) nsecdesclen +=2 *sizeof (struct cifs_ace );else /* cifsacl */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 776/2214 smb: client: validate SMB1 EA list bounds before parsing
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratnaker Gautam <[email protected]>
[ Upstream commit ddc7a7e1eeb116ccaf010a6f1fb6ab927f3f888d ]
CIFSSMBQAllEAs() checks the server-provided EA list length by adding it to the response pointer. On 32-bit systems, a positive length can wrap the pointer and pass the comparison. The parser then walks outside the received response while reading the next FEA header.
A response with a list length of 0x40000000 reproduces this as a native i386 page fault and kernel panic from listxattr() against an SMB1 server.
Check that the EA list starts within the SMB byte area before reading its header. Keep its length unsigned and compare it with the bytes left in the response without pointer addition.
SMB1 is not negotiated by default and requires an explicit vers=1.0 mount.
--- fs/cifs/cifssmb.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
fs/cifs/cifssmb.c +16 -5
@@ -6039,9 +6039,11 @@ CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon,int rc =0 ;int bytes_returned;int list_len; +u32 ea_list_len;struct fealist *ea_response_data;struct fea *temp_fea;char *temp_ptr; +char *byte_area;char *end_of_smb;__u16 params, byte_count, data_offset;unsigned int ea_name_len = ea_name ?strlen (ea_name) :0 ;
@@ -6118,9 +6120,18 @@ CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, ea_response_data = (struct fealist *) (((char *) &pSMBr->hdr.Protocol) + data_offset); - list_len =le32_to_cpu (ea_response_data->list_len); -cifs_dbg (FYI ,"ea length %d\n" , list_len); -if (list_len <=8 ) { + byte_area =pByteArea (&pSMBr->hdr); + end_of_smb = byte_area +get_bcc (&pSMBr->hdr); +if ((char *)ea_response_data < byte_area || + (char *)ea_response_data > + end_of_smb -sizeof (ea_response_data->list_len)) { + rc = -EIO ; + goto QAllEAsOut; + } + + ea_list_len =le32_to_cpu (ea_response_data->list_len); +cifs_dbg (FYI ,"%s: ea length: %u\n" , __func__, ea_list_len); +if (ea_list_len <=8 ) {cifs_dbg (FYI ,"empty EA list returned from server\n" );/* didn't find the named attribute */ if (ea_name)
@@ -6129,12 +6140,12 @@ CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, }/* make sure list_len doesn't go past end of SMB */ - end_of_smb = (char *)pByteArea (&pSMBr->hdr) +get_bcc (&pSMBr->hdr); -if ((char *)ea_response_data + list_len > end_of_smb) { +if (ea_list_len > end_of_smb - (char *)ea_response_data) {cifs_dbg (FYI ,"EA list appears to go beyond SMB\n" ); rc = -EIO ; goto QAllEAsOut; } + list_len = ea_list_len;/* account for ea list len */ list_len -=4 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 777/2214 xfs: check for buffer overruns when examining local/remote xattr entries
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 91c41f9524906a8ebd2ae68c98a07b4bd5255ddb ]
LOLLM noticed that the xattr scrub and repair code can walk off the end of the buffer if the xattr entry record starts so close to the end of the buffer that there's not even space for the entry structure itself. Strengthen the bounds checking here.
--- fs/xfs/scrub/attr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/xfs/scrub/attr.c +12 -0
@@ -276,6 +276,12 @@ xchk_xattr_entry(/* Check the name information. */ if (ent->flags &XFS_ATTR_LOCAL ) { lentry =xfs_attr3_leaf_name_local (leaf, idx); + name_end = (char *)lentry + offsetof(typeof(*lentry), nameval[0]); +if (name_end > buf_end) { +xchk_da_set_corrupt (ds, level); +return ; + } + namesize =xfs_attr_leaf_entsize_local (lentry->namelen,be16_to_cpu (lentry->valuelen)); name_end = (char *)lentry + namesize;
@@ -283,6 +289,12 @@ xchk_xattr_entry(xchk_da_set_corrupt (ds, level); }else { rentry =xfs_attr3_leaf_name_remote (leaf, idx); + name_end = (char *)rentry + offsetof(typeof(*rentry), name[0]); +if (name_end > buf_end) { +xchk_da_set_corrupt (ds, level); +return ; + } + namesize =xfs_attr_leaf_entsize_remote (rentry->namelen); name_end = (char *)rentry + namesize;if (rentry->namelen ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 778/2214 xfs: improve dirent bounds checking in scrub and repair
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 5d470234d04dae6fe2ca2cf4b9ef277b78c7e05a ]
LOLLM complains that we don't do enough bounds checking of the directory entries in directory blocks when we're looking for errors or trying to salvage entries. Let's improve that with more detailed checks.
--- fs/xfs/scrub/dir.c | 61 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 6 deletions(-)
fs/xfs/scrub/dir.c +55 -6
@@ -219,6 +219,7 @@ xchk_dir_rec(xfs_dahash_t hash;struct xfs_dir3_icleaf_hdr hdr;unsigned int tag; +bool foundit = false;int error; ASSERT(blk->magic == XFS_DIR2_LEAF1_MAGIC ||
@@ -263,28 +264,68 @@ xchk_dir_rec( dent = bp->b_addr + off;/* Make sure we got a real directory entry. */ - iter_off = geo->data_entry_offset; end =xfs_dir3_data_end_offset (geo, bp->b_addr);if (!end) {xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno); goto out_relse; } -for (;;) { + iter_off = geo->data_entry_offset; +while (iter_off < end) {struct xfs_dir2_data_entry *dep = bp->b_addr + iter_off;struct xfs_dir2_data_unused *dup = bp->b_addr + iter_off; +unsigned int advance; -if (iter_off >= end) { +/* must have freetag */ + advance = offsetof(typeof(*dup), length); +if (iter_off + advance >= end) {xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno); goto out_relse; }if (be16_to_cpu (dup->freetag) ==XFS_DIR2_DATA_FREE_TAG ) { - iter_off +=be16_to_cpu (dup->length); +if (iter_off +sizeof (*dup) > end) { +xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , + rec_bno); + goto out_relse; + } + + advance =round_up (be16_to_cpu (dup->length), +XFS_DIR2_DATA_ALIGN ); +if (!advance || iter_off + advance > end) { +xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , + rec_bno); + goto out_relse; + } + + iter_off += advance;continue ; } -if (dep == dent) + +/* must have namelen */ + advance = offsetof(typeof(*dep), name); +if (iter_off + advance >= end) { +xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno); + goto out_relse; + } + +/* Don't walk off the end of the block. */ + advance =xfs_dir2_data_entsize (mp, dep->namelen); +if (!advance || iter_off + advance > end) { +xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno); + goto out_relse; + } + +if (dep == dent) { + foundit = true;break ; - iter_off +=xfs_dir2_data_entsize (mp, dep->namelen); + } + iter_off += advance; + } + +/* Hash tree must point to the exact dirent */ +if (!foundit) { +xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno); + goto out_relse; }/* Retrieve the entry, sanity check it, and compare hashes. */
@@ -297,6 +338,14 @@ xchk_dir_rec(xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno); goto out_relse; } + +/* Name must not overflow end of block */ +if ((char *)dent->name + dent->namelen > + (char *)bp->b_addr +BBTOB (bp->b_length)) { +xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno); + goto out_relse; + } + calc_hash =xfs_da_hashname (dent->name, dent->namelen);if (calc_hash != hash)xchk_fblock_set_corrupt (ds->sc,XFS_DATA_FORK , rec_bno);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 779/2214 NFSv4/pnfs: bound the CB_NOTIFY_DEVICEID array count before allocating
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Coddington <[email protected]>
[ Upstream commit 32f0967ea296d447925465c98e7eec71d4e2f755 ]
decode_devicenotify_args() hands the server's notification count straight to kmalloc_objs() as the array length, without checking it against the message that carried it. Bound it the way nfs4xdr.c bounds an attribute length, against xdr_stream_remaining().
--- fs/nfs/callback_xdr.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/nfs/callback_xdr.c +7 -0
@@ -272,6 +272,13 @@ __be32 decode_devicenotify_args(struct svc_rqst *rqstp,if (n ==0 ) goto out; +/* sanity check the count against the remaining stream */ +if (n >xdr_stream_remaining (xdr) / + ((4 *sizeof (uint32_t )) +NFS4_DEVICEID4_SIZE )) { + status =htonl (NFS4ERR_BADXDR ); + goto out; + } + args->devs =kmalloc_array (n,sizeof (*args->devs),GFP_KERNEL );if (!args->devs) { status =htonl (NFS4ERR_DELAY );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 780/2214 smb: client: bound POSIX lock data area by response length
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratnaker Gautam <[email protected]>
[ Upstream commit 8fc9af68c57156ff64769f30e831553cd03b3000 ]
CIFSSMBPosixLock() receives a TRANS2 response whose server-provided DataOffset and DataCount are not required by validate_t2() to describe an interval inside the response. A server can therefore make the client read a cifs_posix_lock beyond the response buffer and return those kernel bytes through F_GETLK.
Use smbCalcSize() to obtain the full response length after any multipart TRANS2 reassembly, then reject data areas that extend past it before dereferencing them.
--- fs/cifs/cifssmb.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/cifs/cifssmb.c +7 -0
@@ -2481,6 +2481,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,cifs_dbg (FYI ,"Send error in Posix Lock = %d\n" , rc); }else if (pLockData) {/* lock structure can be returned on get */ +unsigned int rsp_len;__u16 data_offset;__u16 data_count; rc =validate_t2 ((struct smb_t2_rsp *)pSMBr);
@@ -2491,10 +2492,16 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, } data_offset =le16_to_cpu (pSMBr->t2.DataOffset); data_count =le16_to_cpu (pSMBr->t2.DataCount); + rsp_len =smbCalcSize (&pSMBr->hdr) -4 ;if (data_count <sizeof (struct cifs_posix_lock )) { rc = -EIO ; goto plk_err_exit; } +if (data_offset > rsp_len || + data_count > rsp_len - data_offset) { + rc = -EIO ; + goto plk_err_exit; + } parm_data = (struct cifs_posix_lock *) ((char *)&pSMBr->hdr.Protocol + data_offset);if (parm_data->lock_type ==cpu_to_le16 (CIFS_UNLCK ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 781/2214 NFSv4/flexfiles: fail I/O to the data server once a lock is lost
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Coddington <[email protected]>
[ Upstream commit 7fa2ad367abe6d3155daefb57331e7fce1a17afd ]
When a client loses a byte-range lock, because its lease expired and it may not recover the lock (nfs.recover_lost_locks=0) or because reclaim failed, it marks the lock state NFS_LOCK_LOST and fails further I/O by that lock owner. Otherwise an application that believes it holds a lock over a range is never told that the lock is gone, and can overwrite data that another client has since written under its own lock on that range.
The NFSv4 READ/WRITE and file layout I/O paths apply this in rpc_call_prepare, where nfs4_set_rw_stateid() returns -EIO for a lost lock. The flexfiles data server I/O path does not: the NFSv3 data server path never checked, and the check on the NFSv4 path was removed when the data server stateid began to be taken from the layout.
Fail read and write RPCs to the data server in rpc_call_prepare when the lock is lost. The data server path has no use for the stateid that nfs4_set_rw_stateid() selects, and selecting it looks up a delegation or open stateid on every I/O.
Instead add nfs4_lock_context_lost(), which only tests NFS_LOCK_LOST, and check it alongside the open state. Its lookup, __nfs4_lookup_lock_state(), is split out of __nfs4_find_lock_state() and takes no reference: a lock state is only unlinked from state->lock_states under state->state_lock, so one found while holding that lock cannot be freed before it is released. Use it in nfs4_copy_lock_stateid() as well, which only reads the lock state under that lock. That drops a reference get and put from stateid selection for all NFSv4 I/O without changing the stateid selected.
Terminating the RPC in rpc_call_prepare is not enough on its own. The done callback reads the -EIO as a data server connection error, forgets the device ID, and resets the I/O to pNFS (or, for an NFSv4 data server, possibly to the MDS). After a reset to pNFS a new LAYOUTGET is granted and rpc_call_prepare fails the I/O again, without end. The existing NFS_CONTEXT_BAD check does not loop, since the open state is then invalid and pnfs_update_layout() fails the reset I/O, but it still forgets the device ID.
So when an RPC that was never sent fails and the open context is bad, the open state is invalid, or the lock is lost, complete it with -EIO without error handling. An RPC that was sent and failed is handled as before, so a real data server error is still reported to the MDS.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 25 +++++++++++++++-- fs/nfs/nfs4_fs.h | 2 ++ fs/nfs/nfs4state.c | 38 +++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 6 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +23 -2
@@ -1374,12 +1374,27 @@ static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,dprintk ("%s: err %d op %d status %u\n" , __func__, err, opnum, status); } +static bool ff_layout_io_state_lost (const struct nfs_pgio_header *hdr) +{ +struct nfs_open_context *ctx = hdr->args.context; + +return test_bit (NFS_CONTEXT_BAD , &ctx->flags) || + !nfs4_valid_open_stateid (ctx->state) || +nfs4_lock_context_lost (ctx->state, hdr->args.lock_context); +} +/* NFS_PROTO call done callback routines */ static int ff_layout_read_done_cb (struct rpc_task *task,struct nfs_pgio_header *hdr) {int err; +if (task->tk_status <0 && !RPC_WAS_SENT (task) && +ff_layout_io_state_lost (hdr)) { + task->tk_status = -EIO ; +return 0 ; + } +if (task->tk_status <0 ) { ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, hdr->args.offset, hdr->args.count,
@@ -1467,7 +1482,7 @@ static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,static int ff_layout_read_prepare_common (struct rpc_task *task,struct nfs_pgio_header *hdr) { -if (unlikely (test_bit (NFS_CONTEXT_BAD , &hdr->args.context->flags))) { +if (unlikely (ff_layout_io_state_lost (hdr))) {rpc_exit (task, -EIO );return -EIO ; }
@@ -1548,6 +1563,12 @@ static int ff_layout_write_done_cb(struct rpc_task *task,loff_t end_offs =0 ;int err; +if (task->tk_status <0 && !RPC_WAS_SENT (task) && +ff_layout_io_state_lost (hdr)) { + task->tk_status = -EIO ; +return 0 ; + } +if (task->tk_status <0 ) { ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, hdr->args.offset, hdr->args.count,
@@ -1651,7 +1672,7 @@ static void ff_layout_write_record_layoutstats_done(struct rpc_task *task,static int ff_layout_write_prepare_common (struct rpc_task *task,struct nfs_pgio_header *hdr) { -if (unlikely (test_bit (NFS_CONTEXT_BAD , &hdr->args.context->flags))) { +if (unlikely (ff_layout_io_state_lost (hdr))) {rpc_exit (task, -EIO );return -EIO ; }
fs/nfs/nfs4_fs.h +2 -0
@@ -518,6 +518,8 @@ extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, const struct cred **); extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,struct nfs4_state *state); +extern bool nfs4_lock_context_lost (struct nfs4_state *state, +const struct nfs_lock_context *l_ctx);extern struct nfs_seqid *nfs_alloc_seqid (struct nfs_seqid_counter *counter,gfp_t gfp_mask);extern int nfs_wait_on_sequence (struct nfs_seqid *seqid,struct rpc_task *task);
fs/nfs/nfs4state.c +34 -4
@@ -845,10 +845,13 @@ void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode)* be made. Failing that, a "consistent" choice is preferable. The * consistent choice we make is to prefer the first owner, that of a * Posix lock. +* +* Called with state->state_lock held. No reference is taken: a lock +* state is freed only after it is unlinked under state->state_lock. */ static struct nfs4_lock_state * -__nfs4_find_lock_state (struct nfs4_state *state, -fl_owner_t fl_owner,fl_owner_t fl_owner2) +__nfs4_lookup_lock_state (struct nfs4_state *state, +fl_owner_t fl_owner,fl_owner_t fl_owner2) {struct nfs4_lock_state *pos, *ret =NULL ;list_for_each_entry (pos, &state->lock_states, ls_locks) {
@@ -859,6 +862,16 @@ __nfs4_find_lock_state(struct nfs4_state *state,if (pos->ls_owner == fl_owner2) ret = pos; } +return ret; +} + +static struct nfs4_lock_state * +__nfs4_find_lock_state (struct nfs4_state *state, +fl_owner_t owner,fl_owner_t owner2) +{ +struct nfs4_lock_state *ret; + + ret =__nfs4_lookup_lock_state (state, owner, owner2);if (ret)refcount_inc (&ret->ls_count);return ret;
@@ -1007,7 +1020,7 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst, fl_flock_owner = l_ctx->open_context->flock_owner;spin_lock (&state->state_lock); - lsp =__nfs4_find_lock_state (state, fl_owner, fl_flock_owner); + lsp =__nfs4_lookup_lock_state (state, fl_owner, fl_flock_owner);if (lsp &&test_bit (NFS_LOCK_LOST , &lsp->ls_flags)) ret = -EIO ;else if (lsp !=NULL &&test_bit (NFS_LOCK_INITIALIZED , &lsp->ls_flags) !=0 ) {
@@ -1015,11 +1028,28 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst, ret =0 ; }spin_unlock (&state->state_lock); -nfs4_put_lock_state (lsp); out:return ret; } +bool nfs4_lock_context_lost (struct nfs4_state *state, +const struct nfs_lock_context *l_ctx) +{ +struct nfs4_lock_state *lsp; +bool ret; + +if (!test_bit (LK_STATE_IN_USE , &state->flags)) +return false; + +spin_lock (&state->state_lock); + lsp =__nfs4_lookup_lock_state (state, l_ctx->lockowner, + l_ctx->open_context->flock_owner); + ret = lsp &&test_bit (NFS_LOCK_LOST , &lsp->ls_flags); +spin_unlock (&state->state_lock); +return ret; +} +EXPORT_SYMBOL_GPL (nfs4_lock_context_lost); +bool nfs4_copy_open_stateid (nfs4_stateid *dst,struct nfs4_state *state) {bool ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 782/2214 nfsd: dont offer flexfiles layouts when NFSv3 isnt being served
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 5d28b2c920d9d9d3c45b41769342ad785eb372a7 ]
The flexfiles layout driver hands out a deviceinfo that names this server as an NFSv3 DS (flexfilelayout.c hardcodes da->version = 3). With v3 disabled, the client can't talk to the DS: it loops on v3 NULL calls that the server answers with PROG_MISMATCH, and I/O hangs in D state.
Skip LAYOUT_FLEX_FILES in nfsd4_setup_layout_type() unless v3 is enabled.
--- fs/nfsd/nfs4layouts.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/nfsd/nfs4layouts.c +4 -3
@@ -125,6 +125,7 @@ nfsd4_set_deviceid(struct nfsd4_deviceid *id, const struct svc_fh *fhp,void nfsd4_setup_layout_type (struct svc_export *exp) { +struct nfsd_net *nn =net_generic (exp->cd->net, nfsd_net_id);#if defined(CONFIG_NFSD_BLOCKLAYOUT ) || defined(CONFIG_NFSD_SCSILAYOUT )struct super_block *sb = exp->ex_path.mnt->mnt_sb;#endif
@@ -132,9 +133,9 @@ void nfsd4_setup_layout_type(struct svc_export *exp)if (!(exp->ex_flags &NFSEXP_PNFS ))return ; -#ifdef CONFIG_NFSD_FLEXFILELAYOUT - exp->ex_layout_types |=1 <<LAYOUT_FLEX_FILES ; -#endif +if (IS_ENABLED (CONFIG_NFSD_FLEXFILELAYOUT ) && +nfsd_vers (nn,3 ,NFSD_TEST )) + exp->ex_layout_types |=1 <<LAYOUT_FLEX_FILES ;#ifdef CONFIG_NFSD_BLOCKLAYOUT if (sb->s_export_op->get_uuid && sb->s_export_op->map_blocks &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 783/2214 NFSD: Move the cld upcall message out of the callers stack frame
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit c559b05610557fa3c6c30259261f6dae523b3f23 ]
__cld_pipe_upcall() builds its struct rpc_pipe_msg on the stack and hands it to rpc_queue_upcall(), which links it into a list the pipe owns until the message is released. Only the completion rules keep that frame alive for as long as the pipe refers to it, and the peer that drives those rules is an untrusted userspace daemon. The gss and idmap upcalls do not take that on: each keeps the message in the object it already allocates.
Do the same here and put the message in struct cld_upcall, beside the reply buffer it carries. cld_pipe_destroy_msg() then reaches the upcall from the message directly rather than through msg->data.
Stable-dep-of: 2a83fcb50f3c ("NFSD: Complete a cld upcall when the daemon closes the pipe")
--- fs/nfsd/nfs4recover.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
fs/nfsd/nfs4recover.c +10 -10
@@ -720,6 +720,7 @@ struct cld_upcall {struct completion cu_done;/* daemon has read the whole upcall; protected by cn_lock */ bool cu_inflight; +struct rpc_pipe_msg cu_pipe_msg;union {struct cld_msg_hdr cu_hdr;struct cld_msg cu_msg;
@@ -731,22 +732,22 @@ static int __cld_pipe_upcall(struct rpc_pipe *pipe, void *cmsg, struct nfsd_net *nn) { int ret; -struct rpc_pipe_msg msg; struct cld_upcall *cup = container_of(cmsg, struct cld_upcall, cu_u); +struct rpc_pipe_msg *msg = &cup->cu_pipe_msg; -memset (&msg,0 ,sizeof (msg)); - msg.data = cmsg; - msg.len = nn->client_tracking_ops->msglen; +memset (msg,0 ,sizeof (*msg)); + msg->data = cmsg; + msg->len = nn->client_tracking_ops->msglen; - ret =rpc_queue_upcall (pipe, &msg); + ret =rpc_queue_upcall (pipe, msg);if (ret <0 ) { goto out; }wait_for_completion (&cup->cu_done); -if (msg.errno <0 ) - ret = msg.errno; +if (msg->errno <0 ) + ret = msg->errno; out:return ret; }
@@ -918,9 +919,8 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)static void cld_pipe_destroy_msg (struct rpc_pipe_msg *msg) { -struct cld_msg *cmsg = msg->data; - struct cld_upcall *cup = container_of(cmsg, struct cld_upcall, - cu_u.cu_msg); + struct cld_upcall *cup = container_of(msg, struct cld_upcall, + cu_pipe_msg);struct cld_net *cn = cup->cu_net;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 784/2214 NFSD: Complete a cld upcall when the daemon closes the pipe
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 2a83fcb50f3c25c493cc4389619340fefe9d6ac4 ]
Once nfsdcld has read a whole upcall, rpc_pipe_read() unlinks the message from every pipe list, so the purges in rpc_pipe_release() and rpc_close_pipes() no longer reach it. cld_upcall_ops supplies no .release_pipe callback, and cld_pipe_destroy_msg() returns without completing the upcall because a downcall is expected to follow. A daemon that exits between the read and the write therefore strands its waiter: the nfsd thread sleeps in TASK_UNINTERRUPTIBLE in __cld_pipe_upcall() and never returns, hung task warnings follow, and the server cannot be shut down.
Add a .release_pipe that completes every upcall the daemon has consumed. cu_inflight distinguishes those from upcalls still queued on the pipe, which the framework purges before it calls this callback; cld_pipe_downcall() removes an upcall it accepts from cn_list under the same lock. Neither can be completed twice.
Fail the stranded upcall with -EPIPE rather than the -EAGAIN that makes cld_pipe_upcall() retry. The daemon consumed the request, so whether it acted on it before exiting is unknown.
--- fs/nfsd/nfs4recover.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/nfsd/nfs4recover.c +24 -0
@@ -937,10 +937,34 @@ cld_pipe_destroy_msg(struct rpc_pipe_msg *msg)complete (&cup->cu_done); } +/* +* An upcall the daemon has consumed is off every pipe list, so the +* purge in rpc_pipe_release() and rpc_close_pipes() cannot reach it. +* Release its waiter here instead; no downcall can arrive now. +*/ +static void +cld_release_pipe (struct inode *inode) +{ +struct nfsd_net *nn =net_generic (inode->i_sb->s_fs_info, nfsd_net_id); +struct cld_net *cn = nn->cld_net; +struct cld_upcall *cup; + +spin_lock (&cn->cn_lock); +list_for_each_entry (cup, &cn->cn_list, cu_list) { +if (!cup->cu_inflight) +continue ; + cup->cu_inflight = false; + cup->cu_pipe_msg.errno = -EPIPE ; +complete (&cup->cu_done); + } +spin_unlock (&cn->cn_lock); +} +static const struct rpc_pipe_ops cld_upcall_ops = { .upcall = rpc_pipe_generic_upcall, .downcall = cld_pipe_downcall, .destroy_msg = cld_pipe_destroy_msg, + .release_pipe = cld_release_pipe, }; static struct dentry *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 785/2214 NFSD: Complete a cld upcall when copying its reply fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 8cef2b0a01d28647facc57501a3df7ccd8d13ccd ]
cld_pipe_downcall() removes the matching upcall from cn_list before copying the daemon's reply. When that copy_from_user() faults, the downcall returns -EFAULT without completing the upcall, and a retried write cannot reach it because its xid is no longer on the list. __cld_pipe_upcall() waits on cu_done uninterruptibly, so the nfsd thread that sent the upcall is stuck, and nfsd shutdown hangs behind it. The pipe is mode 0600, so only a broken or hostile nfsdcld can trigger the fault.
Record the fault in the upcall's pipe message and complete it, so the waiter returns the error to its client tracking operation.
--- fs/nfsd/nfs4recover.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/nfsd/nfs4recover.c +4 -1
@@ -909,8 +909,11 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)if (status == -EINPROGRESS )return __cld_pipe_inprogress_downcall (cmsg, nn); -if (copy_from_user (&cup->cu_u.cu_msg_v2, src, mlen) !=0 ) +if (copy_from_user (&cup->cu_u.cu_msg_v2, src, mlen) !=0 ) { + cup->cu_pipe_msg.errno = -EFAULT ; +complete (&cup->cu_done);return -EFAULT ; + }complete (&cup->cu_done);return mlen;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 786/2214 NFSD: Map flex file layout IDs through the requests user namespace
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit f913d5d2130a584d1a027ffe3dfd88b6be2e0540 ]
nfsd4_ff_proc_layoutget() and nfsd4_ff_encode_layoutget() translate the file's owner and group with init_user_ns, but every other identity nfsd places on the wire goes through nfsd_user_namespace(). When the transport carries a credential from a non-initial user namespace, the flex file layout reports host-global IDs. The client copies those IDs into the AUTH_SYS credential it presents to the data server, and svcauth_unix_accept() resolves that credential in the transport's namespace, so data server I/O runs under an identity unrelated to the file's owner.
Switching to the request's namespace introduces a second hazard. from_kuid() returns (uid_t)-1 when the target namespace has no mapping for the owner, and the IOMODE_READ arm adds one to that result to derive an identity for which the data server denies writes. The addition would wrap to zero, handing the client uid 0 instead of an identity distinct from the owner.
Translate both IDs in nfsd4_ff_proc_layoutget(), which has the svc_rqst, and carry the wire values in struct pnfs_ff_layout. from_kuid_munged() substitutes overflowuid for an unmapped owner and thus never returns (uid_t)-1, so the increment cannot wrap to zero.
--- fs/nfsd/blocklayout.c | 4 ++-- fs/nfsd/flexfilelayout.c | 24 ++++++++++++++---------- fs/nfsd/flexfilelayoutxdr.c | 4 ++-- fs/nfsd/flexfilelayoutxdr.h | 5 +++-- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/pnfs.h | 4 ++-- 6 files changed, 24 insertions(+), 19 deletions(-)
fs/nfsd/blocklayout.c +2 -2
@@ -22,8 +22,8 @@static __be32 -nfsd4_block_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +nfsd4_block_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, +const struct svc_fh *fhp,struct nfsd4_layoutget *args) {struct nfsd4_layout_seg *seg = &args->lg_seg;struct super_block *sb = inode->i_sb;
fs/nfsd/flexfilelayout.c +14 -10
@@ -14,19 +14,20 @@#include <linux/sunrpc/addr.h> #include "flexfilelayoutxdr.h" +#include "auth.h" #include "pnfs.h" #include "vfs.h" #define NFSDDBG_FACILITY NFSDDBG_PNFSstatic __be32 -nfsd4_ff_proc_layoutget (struct inode *inode,const struct svc_fh *fhp, -struct nfsd4_layoutget *args) +nfsd4_ff_proc_layoutget (struct svc_rqst *rqstp,struct inode *inode, +const struct svc_fh *fhp,struct nfsd4_layoutget *args) { +struct user_namespace *userns =nfsd_user_namespace (rqstp);struct nfsd4_layout_seg *seg = &args->lg_seg;u32 device_generation =0 ;int error; -uid_t u;struct pnfs_ff_layout *fl;
@@ -49,13 +50,16 @@ nfsd4_ff_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, fl->flags =FF_FLAGS_NO_LAYOUTCOMMIT |FF_FLAGS_NO_IO_THRU_MDS |FF_FLAGS_NO_READ_IO ; -/* Do not allow a IOMODE_READ segment to have write pemissions */ -if (seg->iomode ==IOMODE_READ ) { - u =from_kuid (&init_user_ns, inode->i_uid) +1 ; - fl->uid =make_kuid (&init_user_ns, u); - }else - fl->uid = inode->i_uid; - fl->gid = inode->i_gid; + fl->uid =from_kuid_munged (userns, inode->i_uid); + fl->gid =from_kgid_munged (userns, inode->i_gid); + +/* +* Do not allow an IOMODE_READ segment to have write permissions. +* The group is left intact so group-readable files stay readable; +* nfsd_setuser() squashes an unmapped uid to the export's anon ID. +*/ +if (seg->iomode ==IOMODE_READ ) + fl->uid++; error =nfsd4_set_deviceid (&fl->deviceid, fhp, device_generation);if (error)
fs/nfsd/flexfilelayoutxdr.c +2 -2
@@ -32,8 +32,8 @@ nfsd4_ff_encode_layoutget(struct xdr_stream *xdr, fh_len =4 +xdr_align_size (fl->fh.size); - uid.len =sprintf (uid.buf,"%u" ,from_kuid (&init_user_ns, fl->uid)); - gid.len =sprintf (gid.buf,"%u" ,from_kgid (&init_user_ns, fl->gid)); + uid.len =sprintf (uid.buf,"%u" , fl->uid); + gid.len =sprintf (gid.buf,"%u" , fl->gid);/* data server entry: deviceid + efficiency + stateid + fh list + * user + group + flags + stats_collect_hint
fs/nfsd/flexfilelayoutxdr.h +3 -2
@@ -35,8 +35,9 @@ struct pnfs_ff_device_addr {struct pnfs_ff_layout {u32 flags;u32 stats_collect_hint; -kuid_t uid; -kgid_t gid; +/* Values to encode; nfsd4_ff_proc_layoutget() has mapped these */ +u32 uid; +u32 gid;struct nfsd4_deviceid deviceid;stateid_t stateid;struct nfs_fh fh;
fs/nfsd/nfs4proc.c +1 -1
@@ -2258,7 +2258,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp,if (atomic_read (&ls->ls_stid.sc_file->fi_lo_recalls)) goto out_put_stid; - nfserr = ops->proc_layoutget (d_inode (current_fh->fh_dentry), + nfserr = ops->proc_layoutget (rqstp,d_inode (current_fh->fh_dentry), current_fh, lgp);if (nfserr) goto out_put_stid;
fs/nfsd/pnfs.h +2 -2
@@ -29,8 +29,8 @@ struct nfsd4_layout_ops {__be32 (*encode_getdeviceinfo)(struct xdr_stream *xdr,struct nfsd4_getdeviceinfo *gdevp); -__be32 (*proc_layoutget)(struct inode *,const struct svc_fh *fhp, -struct nfsd4_layoutget *lgp); +__be32 (*proc_layoutget)(struct svc_rqst *rqstp,struct inode *inode, +const struct svc_fh *fhp,struct nfsd4_layoutget *lgp);__be32 (*encode_layoutget)(struct xdr_stream *,struct nfsd4_layoutget *lgp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 787/2214 afs: Fix afs to abort the rxrpc call on send error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 3e6af08a571fe2943a006acf3e890f36322602bc ]
Fix afs_send_empty_reply() and afs_send_simple_reply() to always try to abort the rxrpc call rather than just aborting on -ENOMEM and otherwise abandoning it. If the call is already complete due to network failure or a received abort, this will do nothing.
Also make afs_make_call() always abort on send error; again, it does nothing if the rxrpc call is already dead.
--- fs/afs/rxrpc.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
fs/afs/rxrpc.c +12 -22
@@ -400,10 +400,9 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)return ; error_do_abort: -if (ret != -ECONNABORTED ) { -rxrpc_kernel_abort_call (call->net->socket, rxcall, -RX_USER_ABORT , ret,"KSD" ); - }else { +rxrpc_kernel_abort_call (call->net->socket, rxcall, +RX_USER_ABORT , ret,"KSD" ); +if (ret == -ECONNABORTED ) { len =0 ;iov_iter_kvec (&msg.msg_iter,ITER_DEST ,NULL ,0 ,0 ); rxrpc_kernel_recv_data(call->net->socket, rxcall,
@@ -821,6 +820,7 @@ void afs_send_empty_reply(struct afs_call *call) {struct afs_net *net = call->net;struct msghdr msg; +int ret;_enter ("" );
@@ -833,20 +833,12 @@ void afs_send_empty_reply(struct afs_call *call) msg.msg_controllen =0 ; msg.msg_flags =0 ; -switch (rxrpc_kernel_send_data (net->socket, call->rxcall, &msg,0 , - afs_notify_end_reply_tx)) { -case 0 : -_leave (" [replied]" ); -return ; - -case -ENOMEM : -_debug ("oom" ); + ret =rxrpc_kernel_send_data (net->socket, call->rxcall, &msg,0 , + afs_notify_end_reply_tx); +if (ret <0 ) {rxrpc_kernel_abort_call (net->socket, call->rxcall, -RXGEN_SS_MARSHAL , -ENOMEM ,"KOO" ); - fallthrough; -default : -_leave (" [error]" ); -return ; +RXGEN_SS_MARSHAL , ret,"KSE" ); +afs_set_call_complete (call, ret,RXGEN_SS_MARSHAL ); } }
@@ -881,11 +873,9 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)return ; } -if (n == -ENOMEM ) { -_debug ("oom" ); -rxrpc_kernel_abort_call (net->socket, call->rxcall, -RXGEN_SS_MARSHAL , -ENOMEM ,"KOO" ); - } +rxrpc_kernel_abort_call (net->socket, call->rxcall, +RXGEN_SS_MARSHAL , n,"KSE" ); +afs_set_call_complete (call, n,RXGEN_SS_MARSHAL );_leave (" [error]" ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 788/2214 KVM: nSVM: Reject KVM_SET_NESTED_STATE if L1 has EFER.LMA=1 && EFER.LME=0
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 5dc500a354cc8e109df678076ae3488094649468 ]
Reject KVM_SET_NESTED_STATE if the incoming L1 host state has what is effectively an impossible EFER combination of LMA=1 but LME=0, i.e. if the state says long mode is active but not enabled. Unlike VMX, SVM doesn't have an explicit consistent check for the illegal combination; presumably hardware simply ignores EFER.LMA if EFER.LME=0.
Unfortunately, KVM doesn't ignore EFER.LMA in this case and consumes the illegal state when constructing the shadow MMU for L2. E.g. if userspace also clears CR4.PAE, then kvm_calc_cpu_role() will compute a role with 4 or 5 levels of paging, but shadow_mmu_init_context() will wire up the MMU to use the paging32 template, which maxes out its levels at 2.
Note, the "real badness" is effectively the same as what happened with the nVMX bug fixed by commit 112e66017bff ("KVM: nVMX: add missing consistency checks for CR0 and CR4"). Unfortunately, the sanity check added by commit 72e2fb24a0b0 ("KVM: x86/mmu: Bug the VM if a vCPU ends up in long mode without PAE enabled") doesn't work for this case, since L2 state is active at the time of the page fault, but it's L1 that has the bad state.
--- arch/x86/kvm/svm/nested.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/svm/nested.c +1 -0
@@ -1363,6 +1363,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,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)) goto out_free;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 789/2214 KVM: x86: Clear hardware HLT state when userspace makes a vCPU not-halted
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Keqiang Duan <[email protected]>
[ Upstream commit 883719f57f5d3898637b130d6db4742471cad618 ]
Force a vCPU out of its hardware-tracked halted state when userspace puts the vCPU into any state other than HALTED via KVM_SET_MP_STATE, i.e. clear VMCS.GUEST_ACTIVITY_STATE if it says the vCPU is halted. Add an optional kvm_x86_ops hook to do the clearing, as SVM has no equivalent VMCB field.
When HLT-exiting is disabled for a VM (KVM_CAP_X86_DISABLE_EXITS with KVM_X86_DISABLE_EXITS_HLT, e.g. QEMU's "-overcommit cpu-pm=on"), a guest HLT halts the physical CPU instead of exiting to KVM, and hardware saves GUEST_ACTIVITY_STATE=HLT into the VMCS on the next VM-Exit. That field is
sticky: it survives VM-Exit/VM-Enter and is only cleared by vmx_clear_hlt() on event injection, or by vmx_vcpu_reset() on INIT / vCPU creation.
Nothing clears it on a userspace-driven state change. KVM_SET_REGS only writes the software register cache and KVM_SET_MP_STATE only writes vcpu->arch.mp_state; kvm_vcpu_running() likewise consults software state only. A VMM that emulates a machine reset therefore ends up with a vCPU that KVM happily VM-Enters while hardware refuses to fetch instructions.
Reproduce with a Linux guest by triggering a panic/kdump on a non-boot
vCPU: nmi_shootdown_cpus() parks the other vCPUs -- including vCPU0 -- in crash_nmi_callback(), which does local_irq_disable() followed by a bare HLT. The capture kernel then resets the machine via port 0xCF9. QEMU rewrites RIP to 0xfff0 and sets mp_state to RUNNABLE, but vCPU0's GUEST_ACTIVITY_STATE is still HLT, so the BSP never executes the reset vector, never sends SIPIs, and the entire VM hangs at "reboot: machine restart" forever. Only destroying and recreating the VM recovers it.
Key off "not HALTED" rather than "is RUNNABLE" as HALTED is the only target state for which retaining the hardware halted state is meaningful; every other transition either can't be reached on VMX, e.g. AP_RESET_HOLD, or goes through vmx_vcpu_reset(), which stuffs GUEST_ACTIVITY_ACTIVE anyways. This also captures the intent more directly: KVM only ever drops the hardware halted state, it never installs it.
Hook KVM_SET_MP_STATE rather than the VM-Enter path so that the clearing is driven by an explicit userspace declaration, and so that no work is added to vmx_vcpu_run(). Gate the call on kvm_hlt_in_guest() even though vmx_clear_hlt() checks it as well, as the check is cheap and makes it obvious in common code when the hardware state can exist at all.
Do nothing for TDX vCPUs as TDX doesn't support disabling HLT-exiting and KVM cannot access a TD's VMCS, i.e. the VMCS used to run the vCPU can't in HALTED state, and even if it were, KVM can't change it.
--- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 7 +++++++ arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 13 +++++++++++++ 4 files changed, 22 insertions(+)
arch/x86/include/asm/kvm-x86-ops.h +1 -0
@@ -71,6 +71,7 @@ KVM_X86_OP(interrupt_allowed) KVM_X86_OP(nmi_allowed) KVM_X86_OP(get_nmi_mask) KVM_X86_OP(set_nmi_mask) +KVM_X86_OP_NULL(clear_hlt) KVM_X86_OP(enable_nmi_window) KVM_X86_OP(enable_irq_window) KVM_X86_OP(update_cr8_intercept)
arch/x86/include/asm/kvm_host.h +7 -0
@@ -1394,6 +1394,13 @@ struct kvm_x86_ops {int (*nmi_allowed)(struct kvm_vcpu *vcpu,bool for_injection);bool (*get_nmi_mask)(struct kvm_vcpu *vcpu);void (*set_nmi_mask)(struct kvm_vcpu *vcpu,bool masked); +/* +* Force the vCPU out of any hardware-tracked halted/inactive state so +* that it will fetch and execute instructions on the next VM-Enter. +* Only needed by VMX, where VMCS.GUEST_ACTIVITY_STATE persists across +* VM-Exit/VM-Enter; SVM has no equivalent VMCB field. +*/ +void (*clear_hlt)(struct kvm_vcpu *vcpu);void (*enable_nmi_window)(struct kvm_vcpu *vcpu);void (*enable_irq_window)(struct kvm_vcpu *vcpu);void (*update_cr8_intercept)(struct kvm_vcpu *vcpu,int tpr,int irr);
arch/x86/kvm/vmx/vmx.c +1 -0
@@ -7810,6 +7810,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .nmi_allowed = vmx_nmi_allowed, .get_nmi_mask = vmx_get_nmi_mask, .set_nmi_mask = vmx_set_nmi_mask, + .clear_hlt = vmx_clear_hlt, .enable_nmi_window = vmx_enable_nmi_window, .enable_irq_window = vmx_enable_irq_window, .update_cr8_intercept = vmx_update_cr8_intercept,
arch/x86/kvm/x86.c +13 -0
@@ -10666,6 +10666,19 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,set_bit (KVM_APIC_SIPI , &vcpu->arch.apic->pending_events); }else vcpu->arch.mp_state = mp_state->mp_state; + +/* +* Force the vCPU out of any hardware-tracked halted state, e.g. VMX's +* GUEST_ACTIVITY_STATE=HLT, when userspace puts the vCPU into a state +* other than HALTED. The hardware state is sticky across VM-Exit and +* VM-Enter and is not touched by any other ioctl, so a vCPU that halted +* with HLT-exiting disabled stays wedged even after userspace rewrites +* its registers, e.g. when a VMM emulates a machine reset. +*/ +if (kvm_hlt_in_guest (vcpu->kvm) && + mp_state->mp_state !=KVM_MP_STATE_HALTED ) +static_call_cond (kvm_x86_clear_hlt)(vcpu); +kvm_make_request (KVM_REQ_EVENT , vcpu); ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 790/2214 KVM: x86: Preserve DR6.BLD (Bus Lock Detect) when delivering #DB payload
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 719a1d58bf43edd03b271df90b67c58c1e9a7da4 ]
Preserve Bus Lock Detect if it isn't present in the payload. Unlike RTM, which is explicitly modified on every #DB, DR6.BLD is modified if and only if the #DB is due to a (coincident) Bus Lock Detect.
Per Intel's SDM:
Other debug exceptions do not modify this bit.
And AMD's APM
All other #DB exceptions leave DR6[BLD] unmodified,
Restore the explicit RTM handling that was clobbered by commit 9a3ecd5e2aa1 ("KVM: X86: Rename DR6_INIT to DR6_ACTIVE_LOW"), as the semantics of any given bit are feature specific, i.e. are obviously not consistent for active-high versus active-low. In other words, while the bug was technically introduced when support for Bus Lock Detect was added, it's really that attempt to genericize handling of active-low bits that set KVM up to fail.
--- arch/x86/kvm/x86.c | 52 ++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-)
arch/x86/kvm/x86.c +30 -22
@@ -569,30 +569,37 @@ void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu)switch (nr) {case DB_VECTOR :/* -* "Certain debug exceptions may clear bit 0-3. The -* remaining contents of the DR6 register are never -* cleared by the processor". -*/ - vcpu->arch.dr6 &= ~DR_TRAP_BITS ; -/* -* In order to reflect the #DB exception payload in guest -* dr6, three components need to be considered: active low -* bit, FIXED_1 bits and active high bits (e.g. DR6_BD, -* DR6_BS and DR6_BT) -* DR6_ACTIVE_LOW contains the FIXED_1 and active low bits. -* In the target guest dr6: -* FIXED_1 bits should always be set. -* Active low bits should be cleared if 1-setting in payload. -* Active high bits should be set if 1-setting in payload. +* DR6 is a mess. Reserved/unused bits are fixed-to-1, and so +* to maintain backwards compatibility with existing software, +* features that use previously-reserved bits have active-low +* semantics, i.e. clear the bit when the feature is present in +* the payload. +* +* Further complicating matters, some DR6 bits are preserved by +* hardware, while others are explicitly modified on every #DB. +* The trap bits are always set based on the payload, as is the +* RTM flag (but it's active low). All other bits are modified +* if and only if a relevant debug exception occurs, e.g. BD, +* BS, and BT are never cleared by hardware, and BLD is never +* set by hardware (when supported, excepting RESET). * -* Note, the payload is compatible with the pending debug -* exceptions/exit qualification under VMX, that active_low bits -* are active high in payload. -* So they need to be flipped for DR6. +* Lastly, the payload does NOT have active-low semantics, e.g. +* so that it's compatible VMX's pending debug exceptions and +* qualification fields, and to avoid bleeding the DR6 madness +* into other KVM code. +* +* To compute DR6: +* +* 1. "Reset" the bits that are modified on all #DBs +* 2. Clear active-low bits that are present in the payload. +* 3. Set active-high bits that are present in the payload. +* 4. Clear fixed-0 bits. +* 5. Set fixed-1 bits. */ - vcpu->arch.dr6 |=DR6_ACTIVE_LOW ; - vcpu->arch.dr6 |= payload; - vcpu->arch.dr6 ^= payload &DR6_ACTIVE_LOW ; + vcpu->arch.dr6 &= ~DR_TRAP_BITS ; + vcpu->arch.dr6 |=DR6_RTM ; + vcpu->arch.dr6 &= ~(payload &DR6_ACTIVE_LOW ); + vcpu->arch.dr6 |= (payload & ~DR6_ACTIVE_LOW );/* * The #DB payload is defined as compatible with the 'pending
@@ -601,6 +608,7 @@ void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu)* breakpoint), it is reserved and must be zero in DR6. */ vcpu->arch.dr6 &= ~BIT (12 ); + vcpu->arch.dr6 |=DR6_FIXED_1 ;break ;case PF_VECTOR : vcpu->arch.cr2 = payload;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 791/2214 HID: hid-prodikeys: remove struct pk_device
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 16d0e1d469cc16aefa8ef745e926eda473a9b221 ]
First, quirks was unused in struct pk_device.
And I see no reason for this additional level of indirection. struct pcmidi_snd is far enough for the driver. Unless I am missing something?
So drop struct pk_device and convert all the users to use struct pcmidi_snd directly. No need for doubled kmalloc+kfrees now.
Found by https://github.com/jirislaby/clang-struct.
Stable-dep-of: 0ff37294c41b ("HID: prodikeys: validate fixed-format MIDI reports")
--- drivers/hid/hid-prodikeys.c | 113 +++++++++++++----------------------- 1 file changed, 40 insertions(+), 73 deletions(-)
drivers/hid/hid-prodikeys.c +40 -73
@@ -32,13 +32,6 @@struct pcmidi_snd ; -struct pk_device { -unsigned long quirks; - -struct hid_device *hdev; -struct pcmidi_snd *pm;/* pcmidi device context */ -}; -struct pcmidi_sustain {unsigned long in_use;struct pcmidi_snd *pm;
@@ -50,7 +43,7 @@ struct pcmidi_sustain {#define PCMIDI_SUSTAINED_MAX 32struct pcmidi_snd { -struct pk_device *pk; +struct hid_device *hdev;unsigned short ifnum;struct hid_report *pcmidi_report6;struct input_dev *input_ep82;
@@ -100,11 +93,11 @@ static ssize_t show_channel(struct device *dev, struct device_attribute *attr, char *buf) { struct hid_device *hdev = to_hid_device(dev); -struct pk_device *pk =hid_get_drvdata (hdev); +struct pcmidi_snd *pm =hid_get_drvdata (hdev); -dbg_hid ("pcmidi sysfs read channel=%u\n" , pk->pm->midi_channel); +dbg_hid ("pcmidi sysfs read channel=%u\n" , pm->midi_channel); -return sprintf (buf,"%u (min:%u, max:%u)\n" , pk->pm->midi_channel, +return sprintf (buf,"%u (min:%u, max:%u)\n" , pm->midi_channel,PCMIDI_CHANNEL_MIN ,PCMIDI_CHANNEL_MAX ); }
@@ -113,13 +106,13 @@ static ssize_t store_channel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct hid_device *hdev = to_hid_device(dev); -struct pk_device *pk =hid_get_drvdata (hdev); +struct pcmidi_snd *pm =hid_get_drvdata (hdev);unsigned channel =0 ;if (sscanf (buf,"%u" , &channel) >0 && channel <=PCMIDI_CHANNEL_MAX ) {dbg_hid ("pcmidi sysfs write channel=%u\n" , channel); - pk->pm->midi_channel = channel; + pm->midi_channel = channel;return strlen (buf); }return -EINVAL ;
@@ -137,11 +130,11 @@ static ssize_t show_sustain(struct device *dev, struct device_attribute *attr, char *buf) { struct hid_device *hdev = to_hid_device(dev); -struct pk_device *pk =hid_get_drvdata (hdev); +struct pcmidi_snd *pm =hid_get_drvdata (hdev); -dbg_hid ("pcmidi sysfs read sustain=%u\n" , pk->pm->midi_sustain); +dbg_hid ("pcmidi sysfs read sustain=%u\n" , pm->midi_sustain); -return sprintf (buf,"%u (off:%u, max:%u (ms))\n" , pk->pm->midi_sustain, +return sprintf (buf,"%u (off:%u, max:%u (ms))\n" , pm->midi_sustain,PCMIDI_SUSTAIN_MIN ,PCMIDI_SUSTAIN_MAX ); }
@@ -150,15 +143,14 @@ static ssize_t store_sustain(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct hid_device *hdev = to_hid_device(dev); -struct pk_device *pk =hid_get_drvdata (hdev); +struct pcmidi_snd *pm =hid_get_drvdata (hdev);unsigned sustain =0 ;if (sscanf (buf,"%u" , &sustain) >0 && sustain <=PCMIDI_SUSTAIN_MAX ) {dbg_hid ("pcmidi sysfs write sustain=%u\n" , sustain); - pk->pm->midi_sustain = sustain; - pk->pm->midi_sustain_mode = - (0 == sustain || !pk->pm->midi_mode) ?0 :1 ; + pm->midi_sustain = sustain; + pm->midi_sustain_mode = (0 == sustain || !pm->midi_mode) ?0 :1 ;return strlen (buf); }return -EINVAL ;
@@ -176,11 +168,11 @@ static ssize_t show_octave(struct device *dev, struct device_attribute *attr, char *buf) { struct hid_device *hdev = to_hid_device(dev); -struct pk_device *pk =hid_get_drvdata (hdev); +struct pcmidi_snd *pm =hid_get_drvdata (hdev); -dbg_hid ("pcmidi sysfs read octave=%d\n" , pk->pm->midi_octave); +dbg_hid ("pcmidi sysfs read octave=%d\n" , pm->midi_octave); -return sprintf (buf,"%d (min:%d, max:%d)\n" , pk->pm->midi_octave, +return sprintf (buf,"%d (min:%d, max:%d)\n" , pm->midi_octave,PCMIDI_OCTAVE_MIN ,PCMIDI_OCTAVE_MAX ); }
@@ -189,14 +181,14 @@ static ssize_t store_octave(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct hid_device *hdev = to_hid_device(dev); -struct pk_device *pk =hid_get_drvdata (hdev); +struct pcmidi_snd *pm =hid_get_drvdata (hdev);int octave =0 ;if (sscanf (buf,"%d" , &octave) >0 && octave >=PCMIDI_OCTAVE_MIN && octave <=PCMIDI_OCTAVE_MAX ) {dbg_hid ("pcmidi sysfs write octave=%d\n" , octave); - pk->pm->midi_octave = octave; + pm->midi_octave = octave;return strlen (buf); }return -EINVAL ;
@@ -270,7 +262,7 @@ static void stop_sustain_timers(struct pcmidi_snd *pm)static int pcmidi_get_output_report (struct pcmidi_snd *pm) { -struct hid_device *hdev = pm->pk->hdev; +struct hid_device *hdev = pm->hdev;struct hid_report *report; list_for_each_entry(report,
@@ -295,7 +287,7 @@ static int pcmidi_get_output_report(struct pcmidi_snd *pm)static void pcmidi_submit_output_report (struct pcmidi_snd *pm,int state) { -struct hid_device *hdev = pm->pk->hdev; +struct hid_device *hdev = pm->hdev;struct hid_report *report = pm->pcmidi_report6; report->field[0 ]->value[0 ] =0x01 ; report->field[0 ]->value[1 ] = state;
@@ -626,7 +618,7 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm)/* Setup sound card */ - err =snd_card_new (&pm->pk->hdev->dev, index[dev], id[dev], + err =snd_card_new (&pm->hdev->dev, index[dev], id[dev],THIS_MODULE ,0 , &card);if (err <0 ) {pk_error ("failed to create pc-midi sound card\n" );
@@ -664,7 +656,7 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm) &pcmidi_in_ops);/* create sysfs variables */ - err =device_create_file (&pm->pk->hdev->dev, + err =device_create_file (&pm->hdev->dev, sysfs_device_attr_channel);if (err <0 ) { pk_error("failed to create sysfs attribute channel: error %d\n",
@@ -672,7 +664,7 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm) goto fail; } - err =device_create_file (&pm->pk->hdev->dev, + err =device_create_file (&pm->hdev->dev, sysfs_device_attr_sustain);if (err <0 ) { pk_error("failed to create sysfs attribute sustain: error %d\n",
@@ -680,7 +672,7 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm) goto fail_attr_sustain; } - err =device_create_file (&pm->pk->hdev->dev, + err =device_create_file (&pm->hdev->dev, sysfs_device_attr_octave);if (err <0 ) { pk_error("failed to create sysfs attribute octave: error %d\n",
@@ -710,11 +702,11 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm) fail_register:stop_sustain_timers (pm); -device_remove_file (&pm->pk->hdev->dev, sysfs_device_attr_octave); +device_remove_file (&pm->hdev->dev, sysfs_device_attr_octave); fail_attr_octave: -device_remove_file (&pm->pk->hdev->dev, sysfs_device_attr_sustain); +device_remove_file (&pm->hdev->dev, sysfs_device_attr_sustain); fail_attr_sustain: -device_remove_file (&pm->pk->hdev->dev, sysfs_device_attr_channel); +device_remove_file (&pm->hdev->dev, sysfs_device_attr_channel); fail:if (pm->card) {snd_card_free (pm->card);
@@ -728,12 +720,9 @@ static int pcmidi_snd_terminate(struct pcmidi_snd *pm)if (pm->card) {stop_sustain_timers (pm); -device_remove_file (&pm->pk->hdev->dev, - sysfs_device_attr_channel); -device_remove_file (&pm->pk->hdev->dev, - sysfs_device_attr_sustain); -device_remove_file (&pm->pk->hdev->dev, - sysfs_device_attr_octave); +device_remove_file (&pm->hdev->dev, sysfs_device_attr_channel); +device_remove_file (&pm->hdev->dev, sysfs_device_attr_sustain); +device_remove_file (&pm->hdev->dev, sysfs_device_attr_octave);snd_card_disconnect (pm->card);snd_card_free_when_closed (pm->card);
@@ -763,10 +752,7 @@ static int pk_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { - struct pk_device *pk = hid_get_drvdata(hdev); -struct pcmidi_snd *pm; - - pm = pk->pm; + struct pcmidi_snd *pm = hid_get_drvdata(hdev);if (HID_UP_MSVENDOR == (usage->hid &HID_USAGE_PAGE ) &&1 == pm->ifnum) {
@@ -781,16 +767,16 @@ static int pk_input_mapping(struct hid_device *hdev, struct hid_input *hi,static int pk_raw_event (struct hid_device *hdev,struct hid_report *report,u8 *data,int size) { -struct pk_device *pk =hid_get_drvdata (hdev); +struct pcmidi_snd *pm =hid_get_drvdata (hdev);int ret =0 ; -if (1 == pk->pm->ifnum) { +if (1 == pm->ifnum) {if (report->id == data[0 ])switch (report->id) {case 0x01 :/* midi keys (qwerty)*/ case 0x03 :/* midi keyboard (musical)*/ case 0x04 :/* extra/midi keys (qwerty)*/ - ret =pcmidi_handle_report (pk->pm, + ret =pcmidi_handle_report (pm, report->id, data, size);break ; }
@@ -805,8 +791,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)struct usb_interface *intf;unsigned short ifnum;unsigned long quirks = id->driver_data; -struct pk_device *pk; -struct pcmidi_snd *pm =NULL ; +struct pcmidi_snd *pm;if (!hid_is_usb (hdev))return -EINVAL ;
@@ -814,26 +799,16 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id) intf =to_usb_interface (hdev->dev.parent); ifnum = intf->cur_altsetting->desc.bInterfaceNumber; - pk =kzalloc (sizeof (*pk),GFP_KERNEL ); -if (pk ==NULL ) { -hid_err (hdev,"can't alloc descriptor\n" ); -return -ENOMEM ; - } - - pk->hdev = hdev; - pm =kzalloc (sizeof (*pm),GFP_KERNEL );if (pm ==NULL ) {hid_err (hdev,"can't alloc descriptor\n" ); - ret = -ENOMEM ; - goto err_free_pk; +return -ENOMEM ; } - pm->pk = pk; - pk->pm = pm; + pm->hdev = hdev; pm->ifnum = ifnum; -hid_set_drvdata (hdev, pk); +hid_set_drvdata (hdev, pm); ret =hid_parse (hdev);if (ret) {
@@ -860,26 +835,18 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)hid_hw_stop (hdev); err_free:kfree (pm); -err_free_pk: -kfree (pk);return ret; }static void pk_remove (struct hid_device *hdev) { -struct pk_device *pk =hid_get_drvdata (hdev); -struct pcmidi_snd *pm; - - pm = pk->pm; -if (pm) { -pcmidi_snd_terminate (pm); -kfree (pm); - } +struct pcmidi_snd *pm =hid_get_drvdata (hdev); +pcmidi_snd_terminate (pm);hid_hw_stop (hdev); -kfree (pk); +kfree (pm); }static const struct hid_device_id pk_devices[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 792/2214 HID: prodikeys: validate fixed-format MIDI 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 0ff37294c41bd925258893310398bc2b45fcd4a7 ]
The HID core invokes raw_event callbacks before validating the report length. Prodikeys reports 0x01 and 0x04 are passed to handlers that always read bytes one through three, regardless of the supplied size. A truncated report can therefore cause an out-of-bounds read.
Require four bytes for the two fixed-format reports. Keep report 0x03 on its existing variable-length path, which derives the number of note pairs from size and only accesses complete pairs.
Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init sequence") added the same kind of raw_event length validation to hid-asus.
--- drivers/hid/hid-prodikeys.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hid/hid-prodikeys.c +6 -1
@@ -774,8 +774,13 @@ static int pk_raw_event(struct hid_device *hdev, struct hid_report *report,if (report->id == data[0 ])switch (report->id) {case 0x01 :/* midi keys (qwerty)*/ -case 0x03 :/* midi keyboard (musical)*/ case 0x04 :/* extra/midi keys (qwerty)*/ +if (size <4 ) +break ; + ret =pcmidi_handle_report (pm, report->id, + data, size); +break ; +case 0x03 :/* midi keyboard (musical)*/ ret =pcmidi_handle_report (pm, report->id, data, size);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 793/2214 mlxsw: Initialize register query payloads
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Til Kaiser <[email protected]>
[ Upstream commit 15b7a86a8888dc6a8fd19e181757e32389de9064 ]
MFGD register queries can exhaust EMAD retries and leave Mellanox Spectrum switches stuck during boot or shutdown when running OpenWrt built with GCC 15.
An example failure is shown below with the second line wrapped:
EMAD retries (5/5) (tid=9b544fc100001f35)
EMAD reg access failed (tid=9b544fc100001f35,reg_id=90f0(mfgd),
type=query,status=0(operation performed))
On an SN2100, the failure occurs during driver teardown on reboot. On an SN3420, it occurs while probing mlxsw_spectrum during boot.
The register query API transmits the supplied payload to the device before replacing it with the response. Both MFGD callers pass an uninitialized stack buffer, so the request contains arbitrary register field values and reserved bits. This makes the request depend on stack contents and compiler code generation.
Initialize both MFGD query buffers in the firmware fatal event configuration and reporter test paths. The initialization has been confirmed to eliminate the boot and shutdown hangs on both switches. The subsequent read-modify-write still preserves the other fields returned by the device.
Also initialize the FORE fan fault query and the MOGCR mirroring policer base query, which pass entirely uninitialized payloads.
This follows commit 5b0907407e7f ("mlxsw: core: Zero payload buffers for couple of registers"), which initialized other query payloads after a firmware field length bug caused firmware to consume uninitialized data.
Tested with firmware 2020.1148 and with 2016.3900 from linux-firmware.
--- drivers/net/ethernet/mellanox/mlxsw/core.c | 4 ++-- drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core.c +2 -2
@@ -1829,7 +1829,7 @@ mlxsw_core_health_fw_fatal_test(struct devlink_health_reporter *reporter, struct netlink_ext_ack *extack) {struct mlxsw_core *mlxsw_core =devlink_health_reporter_priv (reporter); -char mfgd_pl[MLXSW_REG_MFGD_LEN ]; +char mfgd_pl[MLXSW_REG_MFGD_LEN ] = {0 };int err;/* Read the register first to make sure no other bits are changed. */
@@ -1850,7 +1850,7 @@ mlxsw_core_health_fw_fatal_ops = {static int mlxsw_core_health_fw_fatal_config (struct mlxsw_core *mlxsw_core,bool enable) { -char mfgd_pl[MLXSW_REG_MFGD_LEN ]; +char mfgd_pl[MLXSW_REG_MFGD_LEN ] = {0 };int err;/* Read the register first to make sure no other bits are changed. */
drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c +1 -1
@@ -160,7 +160,7 @@ static ssize_t mlxsw_hwmon_fan_fault_show(struct device *dev,struct mlxsw_hwmon_attr *mlwsw_hwmon_attr = container_of(attr, struct mlxsw_hwmon_attr, dev_attr);struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; -char fore_pl[MLXSW_REG_FORE_LEN ]; +char fore_pl[MLXSW_REG_FORE_LEN ] = {0 };bool fault;int err;
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c +1 -1
@@ -1703,7 +1703,7 @@ static int mlxsw_sp2_span_init(struct mlxsw_sp *mlxsw_sp)static int mlxsw_sp2_span_policer_id_base_set (struct mlxsw_sp *mlxsw_sp,u16 policer_id_base) { -char mogcr_pl[MLXSW_REG_MOGCR_LEN ]; +char mogcr_pl[MLXSW_REG_MOGCR_LEN ] = {0 };int err; err =mlxsw_reg_query (mlxsw_sp->core,MLXSW_REG (mogcr), mogcr_pl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 794/2214 fsverity: Explicitly require FMODE_READ to retrieve hashes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 1acb4fd2d011c4bd6cc961095ae17361c71ff61a upstream.
The comment in fsverity_ioctl_read_metadata(), which justifies not checking for FMODE_READ, doesn't consider that the nonstandard access mode 3 (ioctl-only) exists.
Opening an ioctl-only fd generally requires read (and write) permission. However, there are gaps with certain LSMs: an ioctl-only fd requests read (and write) permission via security_inode_permission, but not security_file_open. With certain LSMs relying on the latter, such as Landlock and AppArmor, an ioctl-only fd can be opened without the LSM granting read (and write) permission.
Since FS_IOC_READ_VERITY_METADATA returns hashes of file contents blocks, it should require read permission. This also applies to FS_IOC_MEASURE_VERITY, which returns a hash for the whole file.
Meanwhile, ioctl-only fds are a rarely-used feature, not known to be used with either ioctl.
Therefore, just disallow these ioctls on ioctl-only file descriptors, similar to what was already done with FS_IOC_ENABLE_VERITY.
More specifically, explicitly check for FMODE_READ. This also covers write-only fds to non-verity files which otherwise would have failed with ENODATA. This change in error code for write-only fds should be fine too, as these ioctls cannot be usefully used with write-only fds anyway, but it's worth noting as another technicality.
--- Documentation/filesystems/fsverity.rst | 3 +++ fs/verity/measure.c | 10 ++++++++++ fs/verity/read_metadata.c | 14 ++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-)
Documentation/filesystems/fsverity.rst +3 -0
@@ -146,6 +146,7 @@ fatal signal), no changes are made to the file. FS_IOC_ENABLE_VERITY can fail with the following errors: - ``EACCES``: the process does not have write access to the file +- ``EBADF``: the file descriptor is not open for reading - ``EBADMSG``: the signature is malformed - ``EBUSY``: this ioctl is already running on the file - ``EEXIST``: the file already has verity enabled
@@ -208,6 +209,7 @@ regardless of the size of the file. FS_IOC_MEASURE_VERITY can fail with the following errors: +- ``EBADF``: the file descriptor is not open for reading - ``EFAULT``: the caller provided inaccessible memory - ``ENODATA``: the file is not a verity file - ``ENOTTY``: this type of filesystem does not implement fs-verity
@@ -280,6 +282,7 @@ blocks from disk without actually verifying the path to the root node. FS_IOC_READ_VERITY_METADATA can fail with the following errors: +- ``EBADF``: the file descriptor is not open for reading - ``EFAULT``: the caller provided inaccessible memory - ``EINTR``: the ioctl was interrupted before any data was read - ``EINVAL``: reserved fields were set, or ``offset + length``
fs/verity/measure.c +10 -0
@@ -28,6 +28,16 @@ int fsverity_ioctl_measure(struct file *filp, void __user *_uarg)const struct fsverity_hash_alg *hash_alg;struct fsverity_digest arg; +/* +* This ioctl returns a hash of the file contents, so it should require +* read permission. Disallow it on ioctl-only (i.e., nonstandard access +* mode 3) fds, which can in some cases be acquired without passing all +* LSM read-permission checks. Also disallow write-only fds, which can +* refer only to non-verity files which would fail with ENODATA anyway. +*/ +if (!(filp->f_mode &FMODE_READ )) +return -EBADF ; + vi =fsverity_get_info (inode);if (!vi)return -ENODATA ;/* not a verity file */
fs/verity/read_metadata.c +10 -4
@@ -157,13 +157,19 @@ int fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg)int length;void __user *buf; +/* +* This ioctl returns file contents block hashes, so it should require +* read permission. Disallow it on ioctl-only (i.e., nonstandard access +* mode 3) fds, which can in some cases be acquired without passing all +* LSM read-permission checks. Also disallow write-only fds, which can +* refer only to non-verity files which would fail with ENODATA anyway. +*/ +if (!(filp->f_mode &FMODE_READ )) +return -EBADF ; + vi =fsverity_get_info (inode);if (!vi)return -ENODATA ;/* not a verity file */ -/* -* Note that we don't have to explicitly check that the file is open for -* reading, since verity files can only be opened for reading. -*/ if (copy_from_user (&arg, uarg,sizeof (arg)))return -EFAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 795/2214 xor: add missing vzeroupper to AVX code
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 7b8fc26c40d6cf4c6751a045c9e42bbb7e78d81b upstream.
Since the AVX optimized XOR code uses YMM registers, execute vzeroupper before returning from it. This is needed to avoid degrading the performance of any later SSE code that may happen to be executed.
(Backported to the old organization of the XOR code.)
--- arch/x86/include/asm/xor_avx.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/include/asm/xor_avx.h +4 -0
@@ -49,6 +49,7 @@ do { \ p1 = (unsigned long *)((uintptr_t )p1 +512 ); } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -79,6 +80,7 @@ do { \ p2 = (unsigned long *)((uintptr_t )p2 +512 ); } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -112,6 +114,7 @@ do { \ p3 = (unsigned long *)((uintptr_t )p3 +512 ); } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -148,6 +151,7 @@ do { \ p4 = (unsigned long *)((uintptr_t )p4 +512 ); } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 796/2214 raid6: add missing vzeroupper to AVX-512 code
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit b82cf9e49c1be7cf1fd8e1bd806b0cdd25ab8127 upstream.
Since the AVX-512 optimized RAID6 code uses ZMM registers, execute vzeroupper before returning from it. This is needed to avoid degrading the performance of any later SSE code that may happen to be executed.
--- lib/raid6/avx512.c | 6 ++++++ lib/raid6/recov_avx512.c | 2 ++ 2 files changed, 8 insertions(+)
lib/raid6/avx512.c +6 -0
@@ -95,6 +95,7 @@ static void raid6_avx5121_gen_syndrome(int disks, size_t bytes, void **ptrs) } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -154,6 +155,7 @@ static void raid6_avx5121_xor_syndrome(int disks, int start, int stop, } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -227,6 +229,7 @@ static void raid6_avx5122_gen_syndrome(int disks, size_t bytes, void **ptrs) } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -311,6 +314,7 @@ static void raid6_avx5122_xor_syndrome(int disks, int start, int stop, } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -417,6 +421,7 @@ static void raid6_avx5124_gen_syndrome(int disks, size_t bytes, void **ptrs) } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -550,6 +555,7 @@ static void raid6_avx5124_xor_syndrome(int disks, int start, int stop, "m" (q[d+128]), "m" (q[d+192])); } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }const struct raid6_calls raid6_avx512x4 = {
lib/raid6/recov_avx512.c +2 -0
@@ -221,6 +221,7 @@ static void raid6_2data_recov_avx512(int disks, size_t bytes, int faila,#endif } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -363,6 +364,7 @@ static void raid6_datap_recov_avx512(int disks, size_t bytes, int faila,#endif } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 797/2214 ACPI: CPPC: Validate FFH register fields before hardware access
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Loehle <[email protected]>
commit 6b016c5c96448c0a5f09328d37f66562d154a5e5 upstream.
The x86 CPPC FFH accessors construct masks and shift values using the firmware's Bit Width and Bit Offset without checking that the field fits in an MSR. A zero-width field or a field extending beyond bit 63 can therefore cause an invalid shift. The safe MSR accessors only handle an access fault, not invalid field arithmetic after a successful read.
Also, the 64-bit GAS address is implicitly narrowed to the 32-bit MSR number. A descriptor with nonzero upper address bits can access a different MSR from the one described by firmware.
The arm64 AMU counter readers have the same unchecked field arithmetic. Validate the field bounds before reading a counter, including both descriptors in the paired counter path.
Dispatch FFH accesses before decoding the GAS Access Size in the common read and write paths. Otherwise, a large access_width can trigger an invalid shift in GET_BIT_WIDTH() before the architecture validates its register. That field has architecture-specific FFH semantics and is not needed by the generic memory/port accessor on this path.
Validate x86 MSR addresses and share the field-bounds checks between related accessors within each architecture.
--- arch/arm64/kernel/topology.c | 9 +++++++++ arch/x86/kernel/acpi/cppc_msr.c | 15 +++++++++++++++ drivers/acpi/cppc_acpi.c | 10 ++++++---- 3 files changed, 30 insertions(+), 4 deletions(-)
arch/arm64/kernel/topology.c +9 -0
@@ -332,10 +332,19 @@ bool cpc_ffh_supported(void)return true; } +static bool cpc_ffh_reg_valid (const struct cpc_reg *reg) +{ +return reg->bit_width && reg->bit_width <=64 && + reg->bit_offset <=64 - reg->bit_width; +} +int cpc_read_ffh (int cpu,struct cpc_reg *reg,u64 *val) {int ret = -EOPNOTSUPP ; +if (!cpc_ffh_reg_valid (reg)) +return -EINVAL ; +switch ((u64 )reg->address) {case 0x0 : ret =counters_read_on_cpu (cpu, cpu_read_corecnt, val);
arch/x86/kernel/acpi/cppc_msr.c +15 -0
@@ -4,6 +4,8 @@* Copyright (c) 2016, Intel Corporation. */ +#include <linux/limits.h> +#include <acpi/cppc_acpi.h> #include <asm/msr.h>
@@ -14,10 +16,20 @@ bool cpc_ffh_supported(void)return true; } +static bool cpc_ffh_reg_valid (const struct cpc_reg *reg) +{ +return reg->address <=U32_MAX && reg->bit_width && + reg->bit_width <=64 && + reg->bit_offset <=64 - reg->bit_width; +} +int cpc_read_ffh (int cpunum,struct cpc_reg *reg,u64 *val) {int err; +if (!cpc_ffh_reg_valid (reg)) +return -EINVAL ; + err =rdmsrl_safe_on_cpu (cpunum, reg->address, val);if (!err) { u64 mask = GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
@@ -34,6 +46,9 @@ int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)u64 rd_val;int err; +if (!cpc_ffh_reg_valid (reg)) +return -EINVAL ; + err =rdmsrl_safe_on_cpu (cpunum, reg->address, &rd_val);if (!err) { u64 mask = GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
drivers/acpi/cppc_acpi.c +6 -4
@@ -967,6 +967,9 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) } *val =0 ; +if (reg->space_id ==ACPI_ADR_SPACE_FIXED_HARDWARE ) +return cpc_read_ffh (cpu, reg, val); + size =GET_BIT_WIDTH (reg);if (reg->space_id ==ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >=0 ) {
@@ -979,8 +982,6 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) }else if (reg->space_id ==ACPI_ADR_SPACE_SYSTEM_MEMORY ) vaddr = reg_res->sys_mem_vaddr; -else if (reg->space_id ==ACPI_ADR_SPACE_FIXED_HARDWARE ) -return cpc_read_ffh (cpu, reg, val);else return acpi_os_read_memory ((acpi_physical_address )reg->address, val, size);
@@ -1026,6 +1027,9 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)struct cpc_desc *cpc_desc;unsigned long flags; +if (reg->space_id ==ACPI_ADR_SPACE_FIXED_HARDWARE ) +return cpc_write_ffh (cpu, reg, val); + size =GET_BIT_WIDTH (reg);if (reg->space_id ==ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >=0 ) {
@@ -1038,8 +1042,6 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val) }else if (reg->space_id ==ACPI_ADR_SPACE_SYSTEM_MEMORY ) vaddr = reg_res->sys_mem_vaddr; -else if (reg->space_id ==ACPI_ADR_SPACE_FIXED_HARDWARE ) -return cpc_write_ffh (cpu, reg, val);else return acpi_os_write_memory ((acpi_physical_address )reg->address, val, size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 798/2214 ACPI: CPPC: Propagate errors from cross-CPU FFH calls
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Loehle <[email protected]>
commit 36e96b469da24868f727b4cd168d7cf01cbd163d upstream.
The arm64 and RISC-V CPPC FFH accessors ignore the return value of smp_call_function_single(). If the target CPU is offline, the call can return -ENXIO without running the callback. The accessors then consume callback output which was never initialized and may report success.
CPU offlining leaves the CPU's CPPC sysfs attributes present. On arm64, the AMU feature mask does not exclude an offline CPU, so a paired counter read can expose uninitialized stack values through feedback_ctrs. RISC-V has the same problem in both SBI and CSR reads, and its write paths also inspect an uninitialized callback status after a failed cross-CPU call.
Return the SMP call error before using callback output. The arm64 single and paired counter readers already check the helper's return value. For RISC-V, also check the callback status before copying a read value: an unsupported CSR sets the error but does not initialize the value.
--- arch/arm64/kernel/topology.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/kernel/topology.c +1 -3
@@ -303,9 +303,7 @@ int counters_read_on_cpu(int cpu, smp_call_func_t func, u64 *val)if (WARN_ON_ONCE (irqs_disabled ()))return -EPERM ; -smp_call_function_single (cpu, func, val,1 ); - -return 0 ; +return smp_call_function_single (cpu, func, val,1 ); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 799/2214 debugobjects,locking: Annotate debug_object_fill_pool() wait type violation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 0cce06ba859a515bd06224085d3addb870608b6d upstream.
There is an explicit wait-type violation in debug_object_fill_pool() for PREEMPT_RT=n kernels which allows them to more easily fill the object pool and reduce the chance of allocation failures.
Lockdep's wait-type checks are designed to check the PREEMPT_RT locking rules even for PREEMPT_RT=n kernels and object to this, so create a lockdep annotation to allow this to stand.
Specifically, create a 'lock' type that overrides the inner wait-type while it is held -- allowing one to temporarily raise it, such that the violation is hidden.
--- include/linux/lockdep.h | 14 ++++++++++++++ include/linux/lockdep_types.h | 1 + kernel/locking/lockdep.c | 28 +++++++++++++++++++++------- lib/debugobjects.c | 15 +++++++++++++-- 4 files changed, 49 insertions(+), 9 deletions(-)
include/linux/lockdep.h +14 -0
@@ -345,6 +345,16 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);#define lockdep_repin_lock (l,c) lock_repin_lock(&(l)->dep_map, (c))#define lockdep_unpin_lock (l,c) lock_unpin_lock(&(l)->dep_map, (c)) +/* +* Must use lock_map_aquire_try() with override maps to avoid +* lockdep thinking they participate in the block chain. +*/ +#define DEFINE_WAIT_OVERRIDE_MAP (_name, _wait_type) \ + struct lockdep_map _name = { \ + .name = #_name "-wait-type-override", \ + .wait_type_inner = _wait_type, \ + .lock_type = LD_LOCK_WAIT_OVERRIDE, } +#else /* !CONFIG_LOCKDEP */ static inline void lockdep_init_task (struct task_struct *task)
@@ -432,6 +442,9 @@ extern int lockdep_is_held(const void *);#define lockdep_repin_lock (l, c) do { (void)(l); (void)(c); } while (0)#define lockdep_unpin_lock (l, c) do { (void)(l); (void)(c); } while (0) +#define DEFINE_WAIT_OVERRIDE_MAP (_name, _wait_type) \ + struct lockdep_map __maybe_unused _name = {} +#endif /* !LOCKDEP */ #ifdef CONFIG_PROVE_LOCKING
@@ -582,6 +595,7 @@ do { \#define rwsem_release (l, i) lock_release(l, i)#define lock_map_acquire (l) lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_) +#define lock_map_acquire_try (l) lock_acquire_exclusive(l, 0, 1, NULL, _THIS_IP_)#define lock_map_acquire_read (l) lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_)#define lock_map_acquire_tryread (l) lock_acquire_shared_recursive(l, 0, 1, NULL, _THIS_IP_)#define lock_map_release (l) lock_release(l, _THIS_IP_)
include/linux/lockdep_types.h +1 -0
@@ -33,6 +33,7 @@ enum lockdep_wait_type {enum lockdep_lock_type {LD_LOCK_NORMAL =0 ,/* normal, catch all */ LD_LOCK_PERCPU ,/* percpu */ +LD_LOCK_WAIT_OVERRIDE ,/* annotation */ LD_LOCK_MAX , };
kernel/locking/lockdep.c +21 -7
@@ -2253,6 +2253,9 @@ static inline bool usage_match(struct lock_list *entry, void *mask)static inline bool usage_skip (struct lock_list *entry,void *mask) { +if (entry->class->lock_type ==LD_LOCK_NORMAL ) +return false; +/* * Skip local_lock() for irq inversion detection. *
@@ -2279,14 +2282,16 @@ static inline bool usage_skip(struct lock_list *entry, void *mask)* As a result, we will skip local_lock(), when we search for irq * inversion bugs. */ -if (entry->class->lock_type ==LD_LOCK_PERCPU ) { -if (DEBUG_LOCKS_WARN_ON (entry->class->wait_type_inner <LD_WAIT_CONFIG )) -return false; +if (entry->class->lock_type ==LD_LOCK_PERCPU && +DEBUG_LOCKS_WARN_ON (entry->class->wait_type_inner <LD_WAIT_CONFIG )) +return false; -return true; - } +/* +* Skip WAIT_OVERRIDE for irq inversion detection -- it's not actually +* a lock and only used to override the wait_type. +*/ -return false; +return true; }/*
@@ -4781,7 +4786,8 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next)for (; depth < curr->lockdep_depth; depth++) {struct held_lock *prev = curr->held_locks + depth; -u8 prev_inner =hlock_class (prev)->wait_type_inner; +struct lock_class *class =hlock_class (prev); +u8 prev_inner = class->wait_type_inner;if (prev_inner) {/*
@@ -4791,6 +4797,14 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next)* Also due to trylocks. */ curr_inner =min (curr_inner, prev_inner); + +/* +* Allow override for annotations -- this is typically +* only valid/needed for code that only exists when +* CONFIG_PREEMPT_RT=n. +*/ +if (unlikely (class->lock_type ==LD_LOCK_WAIT_OVERRIDE )) + curr_inner = prev_inner; } }
lib/debugobjects.c +13 -2
@@ -609,10 +609,21 @@ __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack/* * On RT enabled kernels the pool refill must happen in preemptible -* context: +* context -- for !RT kernels we rely on the fact that spinlock_t and +* raw_spinlock_t are basically the same type and this lock-type +* inversion works just fine. */ -if (!IS_ENABLED (CONFIG_PREEMPT_RT ) ||preemptible ()) +if (!IS_ENABLED (CONFIG_PREEMPT_RT ) ||preemptible ()) { +/* +* Annotate away the spinlock_t inside raw_spinlock_t warning +* by temporarily raising the wait-type to LD_WAIT_SLEEP, +* allowing the allocator's spinlock_t and local_lock_t locks. +*/ + static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_SLEEP); +lock_map_acquire_try (&fill_pool_map);fill_pool (); +lock_map_release (&fill_pool_map); + } db =get_bucket ((unsigned long ) addr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 800/2214 debugobjects: Use LD_WAIT_CONFIG instead of LD_WAIT_SLEEP
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
commit 37de2dbc318ee10577c1c2704de5a803e75e55a2 upstream.
fill_pool_map is used to suppress nesting violations caused by acquiring a spinlock_t (from within the memory allocator) while holding a raw_spinlock_t. The used annotation is wrong.
LD_WAIT_SLEEP is for always sleeping lock types such as mutex_t. LD_WAIT_CONFIG is for lock type which are sleeping while spinning on PREEMPT_RT such as spinlock_t.
Use LD_WAIT_CONFIG as override.
--- lib/debugobjects.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/debugobjects.c +2 -2
@@ -616,10 +616,10 @@ __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstackif (!IS_ENABLED (CONFIG_PREEMPT_RT ) ||preemptible ()) {/* * Annotate away the spinlock_t inside raw_spinlock_t warning -* by temporarily raising the wait-type to LD_WAIT_SLEEP, +* by temporarily raising the wait-type to LD_WAIT_CONFIG, * allowing the allocator's spinlock_t and local_lock_t locks. */ - static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_SLEEP); + static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_CONFIG);lock_map_acquire_try (&fill_pool_map);fill_pool ();lock_map_release (&fill_pool_map);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 801/2214 pppoe: delete session hash entries by pointer match
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingfang Deng <[email protected]>
[ Upstream commit b5b8c81836e2bec7b444dfa2b14fd14e912e9d63 ]
pppoe_connect() copies the requested PPPoE address to a socket before attempting to insert the socket into the session hash table. If the tuple already exists, __set_item() returns -EALREADY, but the copied address and ifindex remain set on the failed socket.
Closing that socket then deletes the existing socket's hash entry through pppoe_release(), preventing it from receiving further session traffic. An unprivileged process in the same network namespace can trigger this through a duplicate connection attempt.
To avoid the accidental delete, pass the pppox_sock to __delete_item(), and unlink only an entry whose pointer matches the requested socket.
[ Resolve conflict, and remove const qualifier of pppox_sock to match
hash_item(). ]
--- drivers/net/ppp/pppoe.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/net/ppp/pppoe.c +8 -14
@@ -194,18 +194,16 @@ static int __set_item(struct pppoe_net *pn, struct pppox_sock *po)return 0 ; } -static void __delete_item (struct pppoe_net *pn,__be16 sid, -char *addr,int ifindex) +static void __delete_item (struct pppoe_net *pn,struct pppox_sock *po) { -int hash =hash_item (sid, addr); +int hash =hash_item (po->pppoe_pa.sid, po->pppoe_pa.remote);struct pppox_sock *ret, **src; ret = pn->hash_table[hash]; src = &pn->hash_table[hash];while (ret) { -if (cmp_addr (&ret->pppoe_pa, sid, addr) && - ret->pppoe_ifindex == ifindex) { +if (ret == po) { *src = ret->next;break ; }
@@ -255,11 +253,10 @@ static inline struct pppox_sock *get_item_by_addr(struct net *net,return pppox_sock; } -static inline void delete_item (struct pppoe_net *pn,__be16 sid, -char *addr,int ifindex) +static void delete_item (struct pppoe_net *pn,struct pppox_sock *po) {write_lock_bh (&pn->hash_lock); -__delete_item (pn, sid, addr, ifindex); +__delete_item (pn, po);write_unlock_bh (&pn->hash_lock); }
@@ -599,8 +596,7 @@ static int pppoe_release(struct socket *sock)* protect "po" from concurrent updates * on pppoe_flush_dev */ -delete_item (pn, po->pppoe_pa.sid, po->pppoe_pa.remote, - po->pppoe_ifindex); +delete_item (pn, po);sock_orphan (sk); sock->sk =NULL ;
@@ -651,8 +647,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,if (stage_session (po->pppoe_pa.sid)) {pppox_unbind_sock (sk); pn =pppoe_pernet (sock_net (sk)); -delete_item (pn, po->pppoe_pa.sid, - po->pppoe_pa.remote, po->pppoe_ifindex); +delete_item (pn, po);if (po->pppoe_dev) {dev_put (po->pppoe_dev); po->pppoe_dev =NULL ;
@@ -702,8 +697,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr, error =ppp_register_net_channel (dev_net (dev), &po->chan);if (error) { -delete_item (pn, po->pppoe_pa.sid, - po->pppoe_pa.remote, po->pppoe_ifindex); +delete_item (pn, po); goto err_put; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 802/2214 xfs: allow softlimit with no hardlimit in quota scrub
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 342c2e00b3a99099a7088f7b8c8f075670c603a9 ]
LOLLM observes that the sysadmin can set a user's soft limit to a nonzero value and the hard limit to zero, so those aren't corruptions.
--- fs/xfs/scrub/quota.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/scrub/quota.c +4 -4
@@ -102,21 +102,21 @@ xchk_quota_item(* suspect, which is why we flag it for review. * * Complain about corruption if the soft limit is greater than -* the hard limit. +* the hard limit and there's a hard limit set. */ if (dq->q_blk.hardlimit > mp->m_sb.sb_dblocks)xchk_fblock_set_warning (sc,XFS_DATA_FORK , offset); -if (dq->q_blk.softlimit > dq->q_blk.hardlimit) +if (dq->q_blk.hardlimit && dq->q_blk.softlimit > dq->q_blk.hardlimit)xchk_fblock_set_corrupt (sc,XFS_DATA_FORK , offset);if (dq->q_ino.hardlimit >M_IGEO (mp)->maxicount)xchk_fblock_set_warning (sc,XFS_DATA_FORK , offset); -if (dq->q_ino.softlimit > dq->q_ino.hardlimit) +if (dq->q_ino.hardlimit && dq->q_ino.softlimit > dq->q_ino.hardlimit)xchk_fblock_set_corrupt (sc,XFS_DATA_FORK , offset);if (dq->q_rtb.hardlimit > mp->m_sb.sb_rblocks)xchk_fblock_set_warning (sc,XFS_DATA_FORK , offset); -if (dq->q_rtb.softlimit > dq->q_rtb.hardlimit) +if (dq->q_rtb.hardlimit && dq->q_rtb.softlimit > dq->q_rtb.hardlimit)xchk_fblock_set_corrupt (sc,XFS_DATA_FORK , offset);/* Check the resource counts. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 803/2214 xfs: rescan the AGs if incore delalloc counter is negative
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 47b1e941bb55f735d82ba2649412260da78b98f8 ]
LOLLM complains that percpu_counter_sum can return a negative number but we instead misinterpret that into a huge unsigned value and do bad things to fdblocks. It shouldn't do that, so let's add a retry loop and an attempt to freeze the filesystem to (hopefully) zero out the incore delalloc counter. It probably won't work, but at least failing the repair beats doing the wrong thing.
--- fs/xfs/scrub/fscounters.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/xfs/scrub/fscounters.c +6 -1
@@ -173,7 +173,7 @@ xchk_fscount_aggregate_agcounts( {struct xfs_mount *mp = sc->mp;struct xfs_perag *pag; -uint64_t delayed; +int64_t delayed;xfs_agnumber_t agno;int tries =8 ;int error =0 ;
@@ -233,6 +233,11 @@ xchk_fscount_aggregate_agcounts(* of the computation. */ delayed =percpu_counter_sum (&mp->m_delalloc_blks); +if (delayed <0 ) { +ASSERT (delayed >=0 ); +xchk_set_incomplete (sc); +return -EFSCORRUPTED ; + } fsc->fdblocks -= delayed; trace_xchk_fscounters_calc(mp, fsc->icount, fsc->ifree, fsc->fdblocks,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 804/2214 xfs: reject absurdly large xattr value lengths in xchk_xattr_actor
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit fd012955641881169a9f01a00f656f6ca73842ec ]
LOLLM suggests that we shouldn't try to allocate absurdly large buffers for xattr value checks because that will push reclaim very hard, never succeed, and is pointless because nobody can create xattrs that large. Since the xattr repair code ignores values larger than XATTR_SIZE_MAX, we can flag the corruption and return early.
--- fs/xfs/scrub/attr.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/xfs/scrub/attr.c +6 -0
@@ -133,6 +133,12 @@ xchk_xattr_listent(return ; } +/* Don't even try to handle a bizarrely large xattr. */ +if (valuelen >XATTR_SIZE_MAX ) { +xchk_fblock_set_corrupt (sx->sc,XFS_ATTR_FORK , args.blkno); + goto fail_xref; + } +/* * Try to allocate enough memory to extrat the attr value. If that * doesn't work, we overload the seen_enough variable to convey
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 805/2214 xfs: bound da-node entry count against the correct geometry
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
[ Upstream commit 3df5e5aaa3bc0913236c48ab29b7df3a785aa29f ]
xfs_da3_node_verify() bounds the node entry count against the larger of the directory and attribute geometries because, as a buffer verifier, it cannot tell whether the block belongs to the directory or the attribute tree. When the directory block size exceeds the fs block size (e.g. mkfs.xfs -n size=64k -b size=4k), an attribute node buffer is a single fs block that holds only m_attr_geo->node_ents entries, yet a crafted attr node may claim a count up to m_dir_geo->node_ents and still pass the verifier.
xfs_da3_node_lookup_int() then indexes btree[] up to that count during its binary search -- an out-of-bounds read via getxattr/listxattr on a mounted crafted image.
The buffer verifier is the wrong place to tighten this: it has no fork context, and the transaction-less read path used by getxattr does not run xfs_da3_node_set_type() either. xfs_da3_node_lookup_int(), on the other hand, always runs on that path and holds args->geo, the geometry of the fork actually being searched. Bound the entry count against args->geo->node_ents there, before walking the entries.
--- fs/xfs/libxfs/xfs_da_btree.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/xfs/libxfs/xfs_da_btree.c +13 -0
@@ -1658,6 +1658,19 @@ xfs_da3_node_lookup_int( }else expected_level--; +/* +* The node verifier cannot tell whether this block belongs to +* the directory or the attribute tree, so it only bounds the +* entry count against the larger of the two geometries. Here +* args->geo is the geometry of the fork we are actually +* searching, so reject a count that would walk btree[] off the +* end of this node buffer. +*/ +if (nodehdr.count > args->geo->node_ents) { +xfs_buf_mark_corrupt (blk->bp); +return -EFSCORRUPTED ; + } + max = nodehdr.count; blk->hashval =be32_to_cpu (btree[max -1 ].hashval);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 806/2214 raid6: add missing vzeroupper to AVX2 code
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 24f1241cdb056fd630e6710a916e0f7c8c910a70 upstream.
Since the AVX2 optimized RAID6 code uses YMM registers, execute vzeroupper before returning from it. This is needed to avoid degrading the performance of any later SSE code that may happen to be executed.
--- lib/raid6/avx2.c | 6 ++++++ lib/raid6/recov_avx2.c | 2 ++ 2 files changed, 8 insertions(+)
lib/raid6/avx2.c +6 -0
@@ -76,6 +76,7 @@ static void raid6_avx21_gen_syndrome(int disks, size_t bytes, void **ptrs) } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -124,6 +125,7 @@ static void raid6_avx21_xor_syndrome(int disks, int start, int stop, } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -186,6 +188,7 @@ static void raid6_avx22_gen_syndrome(int disks, size_t bytes, void **ptrs) } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -254,6 +257,7 @@ static void raid6_avx22_xor_syndrome(int disks, int start, int stop, } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -347,6 +351,7 @@ static void raid6_avx24_gen_syndrome(int disks, size_t bytes, void **ptrs) } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -457,6 +462,7 @@ static void raid6_avx24_xor_syndrome(int disks, int start, int stop, asmvolatile ("vmovntdq %%ymm14,%0" :"=m" (q[d+96 ])); } asmvolatile ("sfence" : : :"memory" ); + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
lib/raid6/recov_avx2.c +2 -0
@@ -180,6 +180,7 @@ static void raid6_2data_recov_avx2(int disks, size_t bytes, int faila,#endif } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
@@ -297,6 +298,7 @@ static void raid6_datap_recov_avx2(int disks, size_t bytes, int faila,#endif } + asmvolatile ("vzeroupper" );kernel_fpu_end (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 807/2214 xfs: always report scrub errors in tracepoints
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 1ccc8f553d885d49c1bfe141ea1f331511940b3a ]
LOLLM complains that the error processing functions in scrub will sometimes zero out *error before recording a tracepoint. This makes diagnosing problems harder, so let's fix that.
--- fs/xfs/scrub/btree.c | 8 +++++++- fs/xfs/scrub/common.c | 7 +++++-- fs/xfs/scrub/dabtree.c | 6 +++++- 3 files changed, 17 insertions(+), 4 deletions(-)
fs/xfs/scrub/btree.c +7 -1
@@ -45,8 +45,14 @@ __xchk_btree_process_error(case -ENODATA :/* Note the badness but don't abort. */ sc->sm->sm_flags |= errflag; +if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) +trace_xchk_ifork_btree_op_error (sc, cur, level, + *error, ret_ip); +else +trace_xchk_btree_op_error (sc, cur, level, + *error, ret_ip); *error =0 ; - fallthrough; +break ;default :if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) trace_xchk_ifork_btree_op_error(sc, cur, level,
fs/xfs/scrub/common.c +5 -2
@@ -84,8 +84,9 @@ __xchk_process_error(case -ENODATA :/* Note the badness but don't abort. */ sc->sm->sm_flags |= errflag; +trace_xchk_op_error (sc, agno, bno, *error, ret_ip); *error =0 ; - fallthrough; +break ;default :trace_xchk_op_error (sc, agno, bno, *error, ret_ip);
@@ -139,8 +140,10 @@ __xchk_fblock_process_error(case -ENODATA :/* Note the badness but don't abort. */ sc->sm->sm_flags |= errflag; +trace_xchk_file_op_error (sc, whichfork, offset, *error, + ret_ip); *error =0 ; - fallthrough; +break ;default :trace_xchk_file_op_error (sc, whichfork, offset, *error, ret_ip);
fs/xfs/scrub/dabtree.c +5 -1
@@ -48,8 +48,12 @@ xchk_da_process_error(case -ENODATA :/* Note the badness but don't abort. */ sc->sm->sm_flags |=XFS_SCRUB_OFLAG_CORRUPT ; +trace_xchk_file_op_error (sc, ds->dargs.whichfork, +xfs_dir2_da_to_db (ds->dargs.geo, + ds->state->path.blk[level].blkno), + *error, __return_address); *error =0 ; - fallthrough; +break ;default : trace_xchk_file_op_error(sc, ds->dargs.whichfork, xfs_dir2_da_to_db(ds->dargs.geo,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 808/2214 mtd: rawnand: ndfc: use ioread32be/iowrite32be and allow COMPILE_TEST
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 4f2692a5383e4bdd43ae940cda012360f7217a2d ]
Replace ppc4xx-specific in_be32/out_be32 with generic ioread32be/ iowrite32be to make the driver portable. Add COMPILE_TEST dependency to get build coverage on non-ppc4xx architectures.
While at it, replace 4xx with 44x. The latter was removed a while ago and is only kept for compatibility.
--- drivers/mtd/nand/raw/Kconfig | 2 +- drivers/mtd/nand/raw/ndfc.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/mtd/nand/raw/Kconfig +1 -1
@@ -70,7 +70,7 @@ config MTD_NAND_AU1550 config MTD_NAND_NDFC tristate "IBM/MCC 4xx NAND controller" - depends on 4xx + depends on 44x || COMPILE_TEST select MTD_NAND_ECC_SW_HAMMING select MTD_NAND_ECC_SW_HAMMING_SMC help
drivers/mtd/nand/raw/ndfc.c +10 -10
@@ -44,13 +44,13 @@ static void ndfc_select_chip(struct nand_chip *nchip, int chip)uint32_t ccr;struct ndfc_controller *ndfc =nand_get_controller_data (nchip); - ccr =in_be32 (ndfc->ndfcbase +NDFC_CCR ); + ccr =ioread32be (ndfc->ndfcbase +NDFC_CCR );if (chip >=0 ) { ccr &= ~NDFC_CCR_BS_MASK ; ccr |=NDFC_CCR_BS (chip + ndfc->chip_select); }else ccr |=NDFC_CCR_RESET_CE ; -out_be32 (ndfc->ndfcbase +NDFC_CCR , ccr); +iowrite32be (ccr, ndfc->ndfcbase +NDFC_CCR ); }static void ndfc_hwcontrol (struct nand_chip *chip,int cmd,unsigned int ctrl)
@@ -70,7 +70,7 @@ static int ndfc_ready(struct nand_chip *chip) {struct ndfc_controller *ndfc =nand_get_controller_data (chip); -return in_be32 (ndfc->ndfcbase +NDFC_STAT ) &NDFC_STAT_IS_READY ; +return ioread32be (ndfc->ndfcbase +NDFC_STAT ) &NDFC_STAT_IS_READY ; }static void ndfc_enable_hwecc (struct nand_chip *chip,int mode)
@@ -78,9 +78,9 @@ static void ndfc_enable_hwecc(struct nand_chip *chip, int mode)uint32_t ccr;struct ndfc_controller *ndfc =nand_get_controller_data (chip); - ccr =in_be32 (ndfc->ndfcbase +NDFC_CCR ); + ccr =ioread32be (ndfc->ndfcbase +NDFC_CCR ); ccr |=NDFC_CCR_RESET_ECC ; -out_be32 (ndfc->ndfcbase +NDFC_CCR , ccr); +iowrite32be (ccr, ndfc->ndfcbase +NDFC_CCR );wmb (); }
@@ -92,7 +92,7 @@ static int ndfc_calculate_ecc(struct nand_chip *chip,uint8_t *p = (uint8_t *)&ecc;wmb (); - ecc =in_be32 (ndfc->ndfcbase +NDFC_ECC ); + ecc =ioread32be (ndfc->ndfcbase +NDFC_ECC );/* The NDFC uses Smart Media (SMC) bytes order */ ecc_code[0 ] = p[1 ]; ecc_code[1 ] = p[2 ];
@@ -123,7 +123,7 @@ static void ndfc_read_buf(struct nand_chip *chip, uint8_t *buf, int len)uint32_t *p = (uint32_t *) buf;for (;len >0 ; len -=4 ) - *p++ =in_be32 (ndfc->ndfcbase +NDFC_DATA ); + *p++ =ioread32be (ndfc->ndfcbase +NDFC_DATA ); }static void ndfc_write_buf (struct nand_chip *chip,const uint8_t *buf,int len)
@@ -132,7 +132,7 @@ static void ndfc_write_buf(struct nand_chip *chip, const uint8_t *buf, int len)uint32_t *p = (uint32_t *) buf;for (;len >0 ; len -=4 ) -out_be32 (ndfc->ndfcbase +NDFC_DATA , *p++); +iowrite32be (*p++, ndfc->ndfcbase +NDFC_DATA ); }/*
@@ -232,13 +232,13 @@ static int ndfc_probe(struct platform_device *ofdev)if (reg) ccr |=be32_to_cpup (reg); -out_be32 (ndfc->ndfcbase +NDFC_CCR , ccr); +iowrite32be (ccr, ndfc->ndfcbase +NDFC_CCR );/* Set the bank settings if given */ reg =of_get_property (ofdev->dev.of_node,"bank-settings" ,NULL );if (reg) {int offset =NDFC_BCFG0 + (ndfc->chip_select <<2 ); -out_be32 (ndfc->ndfcbase + offset,be32_to_cpup (reg)); +iowrite32be (be32_to_cpup (reg), ndfc->ndfcbase + offset); } err =ndfc_chip_init (ndfc, ofdev->dev.of_node);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 809/2214 mtd: rawnand: ndfc: add CONFIG_OF dependency
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
[ Upstream commit 97f9e509d839f7e5b9a32105ae322e5223c86786 ]
When compile-testing on x86 without CONFIG_OF, the ndfc driver produces a harmless warning:
drivers/mtd/nand/raw/ndfc.c: In function 'ndfc_probe':include/linux/dev_printk.h:154:31: error: 'len' is used uninitialized [-Werror=uninitialized]
154 | dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
| ^drivers/mtd/nand/raw/ndfc.c:196:17: note: in expansion of macro 'dev_err'
196 | dev_err(&ofdev->dev, "unable read reg property (%d)\n", len);
Limit compile-testing to configurations with CONFIG_OF to trivially avoid this. The driver will still be built in allmodconfig and many randconfig builds.
--- drivers/mtd/nand/raw/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/Kconfig +1 -0
@@ -71,6 +71,7 @@ config MTD_NAND_AU1550 config MTD_NAND_NDFC tristate "IBM/MCC 4xx NAND controller" depends on 44x || COMPILE_TEST + depends on OF select MTD_NAND_ECC_SW_HAMMING select MTD_NAND_ECC_SW_HAMMING_SMC help
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 810/2214 mtd: rawnand: ndfc: fix gcc uninitialized var
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit cceca8cb776b03e83985578f84bd730c30d57f70 ]
Now that this can be built with COMPILE_TEST, an unassigned variable was found. Set to 0 to fix the W=1 error under GCC.
--- drivers/mtd/nand/raw/ndfc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/ndfc.c +1 -1
@@ -197,7 +197,7 @@ static int ndfc_probe(struct platform_device *ofdev)const __be32 *reg;u32 ccr;u32 cs; -int err, len; +int err, len =0 ;/* Read the reg property to get the chip select */ reg =of_get_property (ofdev->dev.of_node,"reg" , &len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 811/2214 mtd: rawnand: ndfc: use devm_platform_ioremap_resource()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 0d66f9895f286d2fab396a71e6efeb95c4a7e5a6 ]
Replace the open-coded of_iomap()/iounmap() with the managed devm_platform_ioremap_resource() helper. This fixes a mapping leak on driver remove (the old code never called iounmap()) and simplifies the error path by dropping the manual cleanup in ndfc_probe().
There is no overlapping memory-region concern introduced by this
change: each supported board DT describes a single ndfc node with a unique 0x2000 register region, and the EBC parent uses dcr-reg rather than a MEM reg resource, so the newly added request_mem_region() cannot conflict with an existing reservation. Distinct chip selects map to distinct 64-bit physical addresses, so CS instances do not overlap.
--- drivers/mtd/nand/raw/ndfc.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/mtd/nand/raw/ndfc.c +8 -13
@@ -194,10 +194,15 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,static int ndfc_probe (struct platform_device *ofdev) {struct ndfc_controller *ndfc; +void __iomem *ndfcbase;const __be32 *reg;u32 ccr;u32 cs; -int err, len =0 ; +int len =0 ; + + ndfcbase =devm_platform_ioremap_resource (ofdev,0 ); +if (IS_ERR (ndfcbase)) +return PTR_ERR (ndfcbase);/* Read the reg property to get the chip select */ reg =of_get_property (ofdev->dev.of_node,"reg" , &len);
@@ -219,11 +224,7 @@ static int ndfc_probe(struct platform_device *ofdev) ndfc->ofdev = ofdev;dev_set_drvdata (&ofdev->dev, ndfc); - ndfc->ndfcbase =of_iomap (ofdev->dev.of_node,0 ); -if (!ndfc->ndfcbase) { -dev_err (&ofdev->dev,"failed to get memory\n" ); -return -EIO ; - } + ndfc->ndfcbase = ndfcbase; ccr =NDFC_CCR_BS (ndfc->chip_select);
@@ -241,13 +242,7 @@ static int ndfc_probe(struct platform_device *ofdev)iowrite32be (be32_to_cpup (reg), ndfc->ndfcbase + offset); } - err =ndfc_chip_init (ndfc, ofdev->dev.of_node); -if (err) { -iounmap (ndfc->ndfcbase); -return err; - } - -return 0 ; +return ndfc_chip_init (ndfc, ofdev->dev.of_node); }static int ndfc_remove (struct platform_device *ofdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 812/2214 net: bgmac: enable interrupts only after NAPI is ready
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit ac1f6e58cb77bb66b8811f7d98703e0f076a8f65 ]
bgmac_open() calls bgmac_chip_init(), which unmasks the interrupts and enables the MAC receiver, before request_irq() and napi_enable(). bgmac_enet_resume() also enables NAPI only after bgmac_chip_init().
When frames arrive in that window, the first RX interrupt masks all interrupts in bgmac_interrupt() and calls napi_schedule() on a NAPI instance that is still disabled, so nothing is scheduled. Nothing unmasks the interrupts again, the RX ring fills up and the interface stays deaf until it is brought down and up without traffic.
On an Asus RT-N16 (BCM4716) a single "ip link set eth0 down/up" while a host sends UDP to the router left INT_MASK at 0, INT_STATUS with RX pending and the RX DMA idle on a full ring, with the RX packet and interrupt counters no longer moving. With this change, 10 of 10 such cycles recovered on their own.
Request the IRQ and enable NAPI before the chip is initialized.
--- drivers/net/ethernet/broadcom/bgmac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +5 -5
@@ -1183,9 +1183,6 @@ static int bgmac_open(struct net_device *net_dev)if (err)return err; -/* Specs say about reclaiming rings here, but we do that in DMA init */ -bgmac_chip_init (bgmac); - err =request_irq (bgmac->irq, bgmac_interrupt,IRQF_SHARED , net_dev->name, net_dev);if (err <0 ) {
@@ -1195,6 +1192,9 @@ static int bgmac_open(struct net_device *net_dev) }napi_enable (&bgmac->napi); +/* Specs say about reclaiming rings here, but we do that in DMA init */ +bgmac_chip_init (bgmac); +phy_start (net_dev->phydev);netif_start_queue (net_dev);
@@ -1609,10 +1609,10 @@ int bgmac_enet_resume(struct bgmac *bgmac)if (rc)return rc; -bgmac_chip_init (bgmac); -napi_enable (&bgmac->napi); +bgmac_chip_init (bgmac); +netif_tx_lock (bgmac->net_dev);netif_device_attach (bgmac->net_dev);netif_tx_unlock (bgmac->net_dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 813/2214 spi: zynq-qspi: fix address buffer corruption and support 4-byte address
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pufan Jin <[email protected]>
[ Upstream commit dc5ca34f5e8dc10c566ef39aa3b1a201a17ca734 ]
In zynq_qspi_exec_mem_op(), when transmitting address bytes, the driver iterates over op->addr.nbytes and populates xqspi->txbuf[i]. However, xqspi->txbuf is never re-assigned before populating the address, meaning it still points to (u8 *)&op->cmd.opcode from the command phase.
This causes two severe issues:
1. Memory corruption: Writing into xqspi->txbuf writes past the opcode buffer on the stack (which was passed as const struct spi_mem_op *). If opcode is zero, xqspi->txbuf is uninitialized.
2. In zynq_qspi_supports_op(), operations with op->addr.nbytes > 3 are rejected. When paired with SPI NOR flashes larger than 16MB (such as Winbond W25Q256), spi_nor_spimem_check_read_pp_op() tests 4-byte address support, which fails and causes spi_nor_select_read() to drop all read capabilities, failing probe with -EINVAL (-22).
The Zynq-7000 QSPI controller hardware in manual I/O mode natively supports transmitting 1 to 4 address bytes via its TXD FIFO registers (ZYNQ_QSPI_TXD_00_00_OFFSET).
Fix this by introducing a local opaddr[4] buffer in zynq_qspi_exec_mem_op() and explicitly setting xqspi->txbuf = opaddr before populating address bytes. Also allow up to 4 address bytes in zynq_qspi_supports_op().
--- drivers/spi/spi-zynq-qspi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/spi/spi-zynq-qspi.c +4 -2
@@ -231,7 +231,7 @@ static bool zynq_qspi_supports_op(struct spi_mem *mem,/* * The number of address bytes should be equal to or less than 3 bytes. */ -if (op->addr.nbytes >3 ) +if (op->addr.nbytes >4 )return false;return true;
@@ -535,6 +535,7 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) {struct zynq_qspi *xqspi =spi_controller_get_devdata (mem->spi->master); +u8 opaddr[4 ]__aligned(4) ;int err =0 , i;u8 *tmpbuf;
@@ -561,11 +562,12 @@ static int zynq_qspi_exec_mem_op(struct spi_mem *mem,if (op->addr.nbytes) {for (i =0 ; i < op->addr.nbytes; i++) { - xqspi->txbuf[i] = op->addr.val >> + opaddr[i] = op->addr.val >> (8 * (op->addr.nbytes - i -1 )); }reinit_completion (&xqspi->data_completion); + xqspi->txbuf = opaddr; xqspi->rxbuf =NULL ; xqspi->tx_bytes = op->addr.nbytes; xqspi->rx_bytes = op->addr.nbytes;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 814/2214 s390/vmcp: Initialize full session info to zero
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
[ Upstream commit f63eb4ee4a30fc5d8de07a229d92310e3c8d560c ]
The cma_alloc bit as well as the response can contain old data. cma_release will not free the kmalloced memory in that case and the response code might leak kernel stack data to CAP_SYS_ADMIN users.
--- drivers/s390/char/vmcp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/s390/char/vmcp.c +1 -3
@@ -105,13 +105,11 @@ static int vmcp_open(struct inode *inode, struct file *file)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; - session =kmalloc (sizeof (*session),GFP_KERNEL ); + session =kzalloc (sizeof (*session),GFP_KERNEL );if (!session)return -ENOMEM ; session->bufsize =PAGE_SIZE ; - session->response =NULL ; - session->resp_size =0 ;mutex_init (&session->mutex); file->private_data = session;return nonseekable_open (inode, file);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 815/2214 jbd2: dont advance j_fc_off before the buffer is recorded
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
commit 9f359c031885bb50add7d23c7a5a0e9755b134c9 upstream.
jbd2_fc_get_buf() increments journal->j_fc_off before jbd2_journal_bmap() and __getblk() have had a chance to fail. When either does, the slot j_fc_wbuf[fc_off] is never assigned, but j_fc_off already counts it.
ext4 then fails the fast commit and falls back, and the fallback path reaches jbd2_fc_release_bufs() via ext4_fc_commit -> jbd2_fc_end_commit_fallback -> __jbd2_fc_end_commit -> ext4_fc_cleanup. That walks down from j_fc_off - 1 and put_bh()es every slot until it sees NULL, so it also touches the slot that was never written. j_fc_wbuf comes from a plain kmalloc() and is never zeroed, so a slot used for the first time holds uninitialised heap data.
Advance j_fc_off only after the buffer head has been stored. That restores the invariant that j_fc_off covers exactly the filled slots, which is what jbd2_fc_release_bufs() relies on: the live buffers of the current fast commit sit above the NULLs the previous one released, so stopping at the first NULL is correct.
Reproduced on a KASAN kernel with an ext4 fast_commit filesystem on a loop device, truncating the backing file under the live mount so that only the journal's fast-commit region falls past the end of the device. __getblk() then fails for the first fast-commit block while the rest of the journal is still addressable, so the journal is not aborted and the fast commit reaches the fallback path. j_fc_wbuf was poisoned to make the read of the never-written slot visible:
BUG: KASAN: wild-memory-access in jbd2_fc_release_bufs+0x6b/0xd0 Write of size 4 at addr 5a5a5a5a5a5a5ab2 by task sync/961 jbd2_fc_release_bufs+0x6b/0xd0 ext4_fc_cleanup+0x97/0x830 __jbd2_fc_end_commit+0x37/0xc0 ext4_fc_commit+0x524/0x560 ext4_sync_file+0x3c4/0x4b0 __x64_sys_fsync+0x20/0x30
With this patch the same run leaves j_fc_off at 0 across repeated __getblk() failures and completes cleanly.
[ Context: in 5.15.y, jbd2_fc_get_buf() still advances j_fc_off inside
the if/else bounds check, so the increment is removed from there. The change is otherwise the same as upstream. ]
--- fs/jbd2/journal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jbd2/journal.c +1 -1
@@ -884,7 +884,6 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)if (journal->j_fc_off + journal->j_fc_first < journal->j_fc_last) { fc_off = journal->j_fc_off; blocknr = journal->j_fc_first + fc_off; - journal->j_fc_off++; }else { ret = -EINVAL ; }
@@ -902,6 +901,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out) journal->j_fc_wbuf[fc_off] = bh; + journal->j_fc_off++; *bh_out = bh;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 816/2214 spi: bcm-qspi: reject oversized dummy bytes in mspi exec_mem_op
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit 9e44f0df3fff215d9033089e85980048c3ac132a ]
bcm_qspi_mspi_exec_mem_op() builds a local command buffer cmd[6] holding one opcode byte, up to four address bytes and one spare byte, and sets t[0].len = op->addr.nbytes + op->dummy.nbytes + 1. bcm_qspi_exec_mem_op() only validates op->addr.nbytes <= 4 and never bounds op->dummy.nbytes, which spi_mem_check_op() also leaves unrestricted. With addr.nbytes = 4 and dummy.nbytes >= 2 the length becomes 7 or more, so write_to_hw() reads past cmd[] on the kernel stack and pushes the leaked bytes into the hardware TXRAM.
Reject operations whose dummy phase does not fit the remaining byte of cmd[] by requiring op->dummy.nbytes <= 1, so such transfers fall back to the generic SPI path instead of overrunning the buffer.
--- drivers/spi/spi-bcm-qspi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-bcm-qspi.c +2 -1
@@ -1025,8 +1025,9 @@ static int bcm_qspi_exec_mem_op(struct spi_mem *mem,u32 addr =0 , len;u_char *buf; +/* cmd[] holds 1 opcode + 4 address + 1 dummy byte at most */ if (!op->data.nbytes || !op->addr.nbytes || op->addr.nbytes >4 || - op->data.dir !=SPI_MEM_DATA_IN ) + op->dummy.nbytes >1 || op->data.dir !=SPI_MEM_DATA_IN )return -ENOTSUPP ; buf = op->data.buf.in;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 817/2214 pwm: tiehrpwm: Clear period on disable to allow reconfiguration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Sverdlin <[email protected]>
[ Upstream commit e74b9a7ee50071aad25d3989bf985292f90b0c6e ]
Both channels share one period register, so ehrpwm_pwm_config() rejects a period differing from the sibling's period_cycles[]. That value was cleared only in .free(), not in .disable(), so a stopped channel kept blocking the sibling from switching to a new frequency. Clear it in .disable() too.
Testcase:
cd /sys/class/pwm/pwmchip0; echo 0 > export; echo 1 > export for p in pwm0 pwm1; do
echo 1000000 > $p/period; echo 500000 > $p/duty_cycle
echo 1 > $p/enable; echo 0 > $p/enable; echo 2000000 > $p/period done
echo 1 > pwm0/enable # before: -EINVAL, after: succeeds
--- drivers/pwm/pwm-tiehrpwm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pwm/pwm-tiehrpwm.c +3 -0
@@ -386,6 +386,9 @@ static void ehrpwm_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)/* Disable clock on PWM disable */ pm_runtime_put_sync (chip->dev); + +/* A disabled channel must not constrain the sibling's period */ + pc->period_cycles[pwm->hwpwm] =0 ; }static void ehrpwm_pwm_free (struct pwm_chip *chip,struct pwm_device *pwm)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 818/2214 ALSA: usb-audio: Dont try to submit URBs after disconnection
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit ab574d1629552b6831cd91b926b38092c15d6142 upstream.
USB-audio driver can still submit URBs while the device is being disconnected, and it may result in spurious error messages like:
usb 1-2: cannot submit urb (err = -19)
usb 1-2: Unable to submit urb #0: -19 at snd_usb_queue_pending_output_urbs usb 1-2: cannot submit urb 0, error -19: no device
Although those are harmless, they are just ugly.
This patch tries to avoid spewing such error messages when the device is already at the disconnected state. It also skips the superfluous xfer notification, too.
--- sound/usb/endpoint.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
sound/usb/endpoint.c +27 -13
@@ -519,13 +519,18 @@ int snd_usb_queue_pending_output_urbs(struct snd_usb_endpoint *ep,return -EPIPE ; } - err =usb_submit_urb (ctx->urb,GFP_ATOMIC ); +if (!atomic_read (&ep->chip->shutdown)) + err =usb_submit_urb (ctx->urb,GFP_ATOMIC ); +else + err = -ENODEV ;if (err <0 ) { -usb_audio_err (ep->chip, -"Unable to submit urb #%d: %d at %s\n" , - ctx->index, err, __func__); -if (!in_stream_lock) -notify_xrun (ep); +if (!atomic_read (&ep->chip->shutdown)) { +usb_audio_err (ep->chip, +"Unable to submit urb #%d: %d at %s\n" , + ctx->index, err, __func__); +if (!in_stream_lock) +notify_xrun (ep); + }return -EPIPE ; }
@@ -592,12 +597,17 @@ static void snd_complete_urb(struct urb *urb)prepare_inbound_urb (ep, ctx); } - err =usb_submit_urb (urb,GFP_ATOMIC ); +if (!atomic_read (&ep->chip->shutdown)) + err =usb_submit_urb (urb,GFP_ATOMIC ); +else + err = -ENODEV ;if (err ==0 )return ; -usb_audio_err (ep->chip,"cannot submit urb (err = %d)\n" , err); -notify_xrun (ep); +if (!atomic_read (&ep->chip->shutdown)) { +usb_audio_err (ep->chip,"cannot submit urb (err = %d)\n" , err); +notify_xrun (ep); + } exit_clear:clear_bit (ctx->index, &ep->active_mask);
@@ -1641,11 +1651,15 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) goto __error; } - err =usb_submit_urb (urb,GFP_ATOMIC ); +if (!atomic_read (&ep->chip->shutdown)) + err =usb_submit_urb (urb,GFP_ATOMIC ); +else + err = -ENODEV ;if (err <0 ) { -usb_audio_err (ep->chip, -"cannot submit urb %d, error %d: %s\n" , - i, err,usb_error_string (err)); +if (!atomic_read (&ep->chip->shutdown)) +usb_audio_err (ep->chip, +"cannot submit urb %d, error %d: %s\n" , + i, err,usb_error_string (err)); goto __error; }set_bit (i, &ep->active_mask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 819/2214 media: require two-byte Cypress type 04 records
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit e22872703386c3885d8c6bd595124587bc4e5081 ]
Both Cypress Intel HEX parsers read two address bytes from type 04 records. Generic record framing permits any record length, so a short record can make the parser consume the checksum or bytes beyond the firmware record. A longer record also violates the Intel HEX type 04 layout.
Require the type 04 payload length to be exactly two bytes in both implementations.
--- drivers/media/common/cypress_firmware.c | 2 ++ drivers/media/usb/dvb-usb/dvb-usb-firmware.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/media/common/cypress_firmware.c +2 -0
@@ -59,6 +59,8 @@ static int cypress_get_hexline(const struct firmware *fw,if (hx->type ==0x04 ) {/* b[4] and b[5] are the Extended linear address record data * field */ +if (hx->len !=2 ) +return -EINVAL ; hx->addr |= (b[4 ] <<24 ) | (b[5 ] <<16 ); }
drivers/media/usb/dvb-usb/dvb-usb-firmware.c +2 -0
@@ -141,6 +141,8 @@ int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx,if (hx->type ==0x04 ) {/* b[4] and b[5] are the Extended linear address record data field */ +if (hx->len !=2 ) +return -EINVAL ; hx->addr |= (b[4 ] <<24 ) | (b[5 ] <<16 );/* hx->len -= 2; data_offs += 2; */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 820/2214 media: adv748x: Fix endpoint reference leaks on probe failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 359db09cf055497075a668b192f4578a0ed00955 ]
adv748x_parse_dt() takes an extra reference for every endpoint saved in state->endpoints. If parsing later fails, adv748x_probe() skips adv748x_dt_cleanup(), so the saved references remain held. A CSI-2 lane parsing error also returns from for_each_endpoint_of_node() without dropping the iterator's reference.
Save the endpoint reference only after lane parsing succeeds. Drop the iterator reference before returning a lane parsing error and route all parse failures through the endpoint cleanup path to release any saved references. This retains the endpoints only for a successful probe.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/media/i2c/adv748x/adv748x-core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/i2c/adv748x/adv748x-core.c +7 -6
@@ -675,9 +675,6 @@ static int adv748x_parse_dt(struct adv748x_state *state)continue ; } -of_node_get (ep_np); - state->endpoints[ep.port] = ep_np; -/* * At least one input endpoint and one output endpoint shall * be defined.
@@ -689,8 +686,13 @@ static int adv748x_parse_dt(struct adv748x_state *state)/* Store number of CSI-2 lanes used for TXA and TXB. */ ret =adv748x_parse_csi2_lanes (state, ep.port, ep_np); -if (ret) +if (ret) { +of_node_put (ep_np);return ret; + } + +of_node_get (ep_np); + state->endpoints[ep.port] = ep_np; }return in_found && out_found ?0 : -ENODEV ;
@@ -739,7 +741,7 @@ static int adv748x_probe(struct i2c_client *client) ret =adv748x_parse_dt (state);if (ret) {adv_err (state,"Failed to parse device tree" ); - goto err_free_mutex; + goto err_cleanup_dt; }/* Configure IO Regmap region */
@@ -809,7 +811,6 @@ static int adv748x_probe(struct i2c_client *client)adv748x_unregister_clients (state); err_cleanup_dt:adv748x_dt_cleanup (state); -err_free_mutex:mutex_destroy (&state->mutex);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 821/2214 iio: pressure: dps310: fix CFG_REG bit definitions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rupesh Majhi <[email protected]>
[ Upstream commit 4334dc4092c271e6cd010c2ee70b7f4415c4c199 ]
Driver defines them as BIT(4), BIT(5) and BIT(6). Per datasheet P_SHIFT is bit 2, FIFO_EN is bit 1 and SPI_MODE is bit 0.
Only P_SHIFT has a user. dps310_set_pres_precision() sets it at oversampling 16 or above, so with wrong bit the result register is never shifted and stops matching the scale factor compensation divides by. in_pressure_input returns -ERANGE at oversampling 16, 32 and 64.
FIFO_EN needed by FIFO support later in this series.
--- drivers/iio/pressure/dps310.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/pressure/dps310.c +3 -3
@@ -50,9 +50,9 @@#define DPS310_CFG_REG 0x09#define DPS310_INT_HL BIT(7)#define DPS310_TMP_SHIFT_EN BIT(3) -#define DPS310_PRS_SHIFT_EN BIT(4) -#define DPS310_FIFO_EN BIT(5) -#define DPS310_SPI_EN BIT(6) +#define DPS310_PRS_SHIFT_EN BIT(2) +#define DPS310_FIFO_EN BIT(1) +#define DPS310_SPI_EN BIT(0)#define DPS310_RESET 0x0c#define DPS310_RESET_MAGIC 0x09#define DPS310_COEF_BASE 0x10
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 822/2214 media: mediatek: jpeg: Avoid context access after job finish
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kazuki Hanai <[email protected]>
[ Upstream commit 7c7f31405b76acd95a628c834ee8a2d6da439782 ]
v4l2_m2m_job_finish() publishes job completion and wakes waiters before it returns. A concurrent file release can therefore finish v4l2_m2m_ctx_release() and free the context while the single-core IRQ handler continues with its tail.
Both handlers only need the device for the matching runtime PM put. Use the IRQ-owned jpeg pointer instead of dereferencing ctx after completion has been published. This preserves the get/put pairing and removes the post-completion context access.
--- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +2 -2
@@ -1096,7 +1096,7 @@ static irqreturn_t mtk_jpeg_enc_done(struct mtk_jpeg_dev *jpeg)v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); -pm_runtime_put (ctx->jpeg->dev); +pm_runtime_put (jpeg->dev);return IRQ_HANDLED ; }
@@ -1163,7 +1163,7 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); -pm_runtime_put (ctx->jpeg->dev); +pm_runtime_put (jpeg->dev);return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 823/2214 NFSD: Resolve the recall-any mask names in the trace format
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit c563a1f0679566d7d586802e5346591d0af8da78 ]
RCA4_TYPE_MASK_* are enum constants, so the preprocessor cannot fold them into the print format that show_rca_mask() builds for the nfsd_cb_recall_any event. Nothing declares an eval map for them either, so trace_event_eval_update() has no substitution to apply at module load, and the event's format file ships the enumerator names verbatim. trace-cmd and perf cannot decode the bmval0 field.
Declare the eval maps for the nine mask bits show_rca_mask() decodes. The format then carries the shift counts as integers, the same shape the SUNRPC trace points already emit from their BIT() flag decoders.
--- include/trace/misc/nfs.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/trace/misc/nfs.h +10 -0
@@ -359,6 +359,16 @@ TRACE_DEFINE_ENUM(IOMODE_ANY); { IOMODE_RW, "RW" }, \ { IOMODE_ANY, "ANY" }) +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_RDATA_DLG ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_WDATA_DLG ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_DIR_DLG ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_FILE_LAYOUT ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_BLK_LAYOUT ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_OBJ_LAYOUT_MIN ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_OBJ_LAYOUT_MAX ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_OTHER_LAYOUT_MIN ); +TRACE_DEFINE_ENUM (RCA4_TYPE_MASK_OTHER_LAYOUT_MAX ); +#define show_rca_mask (x) \ __print_flags(x, "|", \ { BIT(RCA4_TYPE_MASK_RDATA_DLG), "RDATA_DLG" }, \
Signature · 1 line
2.53.0