7.3.4-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 703/1257 clk: qcom: ipq5332: add 24MHz rate for USB UTMI clock
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kathiravan Thirumoorthy <[email protected]>
[ Upstream commit 19b62f31e15ef70dc927aab91b1576ea6c37f992 ]
The USB UTMI reference clock must operate at 24 MHz, as recommended by the hardware team, for reliable USB operation.
Validation showed that USB 3.2 hub enumeration with USB 2.0 devices fails when the UTMI reference clock is not configured to the required 24 MHz rate. Configuring the UTMI reference clock to 24 MHz to resolve the enumeration failure and ensure successful device detection.
--- drivers/clk/qcom/gcc-ipq5332.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/qcom/gcc-ipq5332.c +1 -0
@@ -1038,6 +1038,7 @@ static struct clk_rcg2 gcc_usb0_master_clk_src = { };static const struct freq_tbl ftbl_gcc_usb0_mock_utmi_clk_src[] = { +F (24000000 ,P_XO ,1 ,0 ,0 ),F (60000000 ,P_GPLL4_OUT_AUX ,10 ,1 ,2 ), { } };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 704/1257 clk: qcom: ipq5210: add 24MHz rate for USB UTMI clock
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kathiravan Thirumoorthy <[email protected]>
[ Upstream commit 4d61492b5fa910ed59c4cbc699d2e5a03a5777d3 ]
The USB UTMI reference clock must operate at 24 MHz, as recommended by the hardware team, for reliable USB operation.
Validation showed that USB 3.2 hub enumeration with USB 2.0 devices fails when the UTMI reference clock is not configured to the required 24 MHz rate. Configuring the UTMI reference clock to 24 MHz to resolve the enumeration failure and ensure successful device detection.
--- drivers/clk/qcom/gcc-ipq5210.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/qcom/gcc-ipq5210.c +1 -0
@@ -716,6 +716,7 @@ static struct clk_rcg2 gcc_usb0_master_clk_src = { };static const struct freq_tbl ftbl_gcc_usb0_mock_utmi_clk_src[] = { +F (24000000 ,P_XO ,1 ,0 ,0 ),F (60000000 ,P_GPLL4_OUT_AUX ,10 ,1 ,2 ), { } };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 705/1257 iomap: dont lose a fiemap iteration error when emitting the last extent
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit 0d0104adc2c8316433b660cdf6d182a09881864f ]
iomap_fiemap() emits extents one behind: iomap_fiemap_iter() flushes the previous extent and remembers the current one, and the remembered extent is written with FIEMAP_EXTENT_LAST after the iteration loop.
That final flush overwrites ret, so when ->iomap_begin() fails partway through the iteration the error is replaced by the result of iomap_to_fiemap() (zero on success) and iomap_fiemap() returns success with a truncated extent list whose last entry is wrongly marked as the last extent in the file. The pre-iomap_iter code returned the error from inside the loop, before flushing the pending extent.
Check for the iteration error before flushing the pending extent, so that real errors are propagated and only a successful iteration emits the final FIEMAP_EXTENT_LAST extent. -ENOENT (no mapping) is still not an error, and the pending extent is still emitted in that case.
--- fs/iomap/fiemap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/iomap/fiemap.c +4 -4
@@ -76,15 +76,15 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi,while ((ret =iomap_iter (&iter, ops)) >0 ) iter.status =iomap_fiemap_iter (&iter, fi, &prev); +/* inode with no (attribute) mapping will give ENOENT */ +if (ret <0 && ret != -ENOENT ) +return ret; +if (prev.type !=IOMAP_HOLE ) { ret =iomap_to_fiemap (fi, &prev,FIEMAP_EXTENT_LAST );if (ret <0 )return ret; } - -/* inode with no (attribute) mapping will give ENOENT */ -if (ret <0 && ret != -ENOENT ) -return ret;return 0 ; }EXPORT_SYMBOL_GPL (iomap_fiemap);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 706/1257 iomap: dont lose a failed direct I/O bios error when zeroing the tail
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit a9fd24bcbe690ed4a5b8ea6a7516fa297fae9360 ]
iomap_dio_bio_iter() falls through to the sub-block tail zeroing when the data bio submission fails, so that the rest of the block is still zeroed and stale data is not exposed. The zeroing result was assigned to ret, which overwrote the submission error with the successful zeroing result (zero) and the failed write was reported as success.
iomap_dio_zero() can only return an error from a can't-happen WARN_ON_ONCE() (nr_vecs exceeding BIO_MAX_VECS, which the existing comment there says "shall never be reached" for any in-tree filesystem), so it isn't a real runtime failure worth reporting to userspace, let alone one worth losing the actual submission error for. Make iomap_dio_zero() return void and drop the error handling at both call sites instead of threading the result through a separate variable.
--- fs/iomap/direct-io.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
fs/iomap/direct-io.c +5 -11
@@ -296,7 +296,7 @@ u32 iomap_finish_ioend_direct(struct iomap_ioend *ioend)return vec_count; } -static int iomap_dio_zero (const struct iomap_iter *iter,struct iomap_dio *dio, +static void iomap_dio_zero (const struct iomap_iter *iter,struct iomap_dio *dio,loff_t pos,unsigned len) {struct inode *inode =file_inode (dio->iocb->ki_filp);
@@ -305,14 +305,14 @@ static int iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio,int nr_vecs =max (1 ,i_blocksize (inode) /folio_size (zero_folio));if (!len) -return 0 ; +return ;/* * This limit shall never be reached as most filesystems have a * maximum blocksize of 64k. */ if (WARN_ON_ONCE (nr_vecs >BIO_MAX_VECS )) -return -EINVAL ; +return ; bio =iomap_dio_alloc_bio (iter, dio, nr_vecs,REQ_OP_WRITE |REQ_SYNC |REQ_IDLE );
@@ -328,8 +328,6 @@ static int iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, len -= io_len; }iomap_dio_submit_bio (iter, dio, bio, pos); - -return 0 ; } static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
@@ -541,10 +539,7 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)if (need_zeroout) {/* zero out from the start of the block to the write offset */ pad = pos & (fs_block_size -1 ); - - ret =iomap_dio_zero (iter, dio, pos - pad, pad); -if (ret) - goto out; +iomap_dio_zero (iter, dio, pos - pad, pad); } do {
@@ -582,8 +577,7 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)/* zero out from the end of the write to the end of the block */ pad = pos & (fs_block_size -1 );if (pad) - ret =iomap_dio_zero (iter, dio, pos, - fs_block_size - pad); +iomap_dio_zero (iter, dio, pos, fs_block_size - pad); } out:/* Undo iter limitation to current extent */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 707/1257 nvme-rdma: dont complete a request after a bogus remote invalidation
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit 909307cea08aff4e486cdb7491de5c76a2c31341 ]
When a remote invalidation names an rkey that is not the one we handed out for this request, nvme_rdma_process_nvme_rsp() logs and schedules error recovery, then falls through to nvme_rdma_end_request(). The request is completed with req->mr never invalidated, and nvme_rdma_unmap_data() hands it back with ib_mr_pool_put(), which only puts it on a list. The rkey stays valid and still maps the pages the completed read filled, so a controller that sent the bogus invalidation can write into those pages after pread() has returned.
Return instead, the way the local invalidation path below already does, and leave the request for error recovery to cancel.
--- drivers/nvme/host/rdma.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/rdma.c +1 -0
@@ -1748,6 +1748,7 @@ static void nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue,"Bogus remote invalidation for rkey %#x\n" , req->mr ? req->mr->rkey : 0);nvme_rdma_error_recovery (queue->ctrl); +return ; } }else if (req->mr) {int ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 708/1257 nvmet: fix preempt of another registrant by the reservation holder
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit d9e84d4e19994818b80846bd2abb7b396e4116a9 ]
Unless the reservation is of an All Registrants type, nvmet_pr_preempt() treats every Reservation Acquire command with the Preempt or Preempt and Abort action that is sent by the reservation holder as the holder preempting itself. It updates the reservation type to RTYPE and completes the command successfully without looking at PRKEY.
NVMe Base Specification 2.1, section 8.1.22.7 makes the action depend on PRKEY for these reservation types, no matter which registrant sends the command:
- PRKEY matches the key of the reservation holder: the reservation is preempted. This is how a holder preempts itself.
- PRKEY does not match the key of the holder and is not 0h: the registrants whose key matches PRKEY are unregistered.
- PRKEY does not match the key of the holder and is 0h: the command is aborted with Invalid Field in Command.
With the current code, a holder that preempts with the key of another registrant leaves that registrant registered, changes the reservation type to RTYPE and still gets a successful completion. With hosts A, B and C registered with the keys 0xa, 0xb and 0xc, and A holding an Exclusive Access - Registrants Only reservation, A sends:
# nvme resv-acquire /dev/nvme1 -n 1 --crkey=0xa --prkey=0xb \
--rtype=4 --racqa=1
NVME Reservation Acquire success
# nvme resv-report /dev/nvme1 -n 1 --eds | grep '^regctl '
regctl : 3and B can still write to the namespace. Preempt and Abort (--racqa=2) gives the same result. When C sends the preempt instead (--crkey=0xc), B is unregistered and its writes fail with Reservation Conflict.
This defeats fencing in the pNFS SCSI layout server. nfsd holds the reservation and fences a client that does not return its layout by calling pr_preempt() with the key of that client and the abort flag, which is the command RFC 9561 section 2.2.3 asks for. On an nvmet namespace the preempt succeeds, nfsd logs the client as fenced, and the client keeps writing to the device. In a test with an nfsd server and two clients on an nvmet-tcp namespace, the namespace still had three registrants after the fence and the fenced client went on writing to it. With this patch two registrants are left and the writes of the fenced client fail with a reservation conflict.
Take the self preempt path only when PRKEY is the key of the holder. Any other PRKEY sent by the holder is then handled by the code that already serves a non-holder registrant, for Preempt and for Preempt and Abort. For a host that holds the reservation this changes the following:
- A preempt with the key of another registrant unregisters the registrants with that key, sends them the registration preempted notification and leaves the reservation type alone.
- A preempt with PRKEY 0h fails with Invalid Field in Command. A holder that changed its reservation type this way has to pass its own key in PRKEY, which works with and without this patch.
- A preempt with a PRKEY that matches no registrant fails with Reservation Conflict. The specification defines that status only for the All Registrants types. It is what nvmet already returns to a non-holder registrant in this case and what the SCSI target returns for an unregistered key. nfsd treats it as a successful fence.
Not changed: when the holder preempts itself, registrants that share its key stay registered.
--- drivers/nvme/target/pr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/pr.c +1 -1
@@ -589,7 +589,7 @@ static u16 nvmet_pr_preempt(struct nvmet_req *req, &ctrl->hostid, abort); } -if (holder == reg) { +if (holder == reg && prkey == holder->rkey) { status =nvmet_pr_update_reg_attr (pr, holder, nvmet_pr_update_holder_rtype, &rtype);if (!status && original_rtype != rtype)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 709/1257 nvme-auth: fail when the controller does not authenticate itself
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit f9e43d924bc74feeb56197de82b2845de2a4b85a ]
nvme_auth_process_dhchap_success1() returns success as soon as the controller clears the rvalid flag in its DH-HMAC-CHAP success1 message, without looking at whether the host had asked the controller to authenticate. A host configured with a controller secret sends a challenge in its reply, computes the expected controller response, and sets chap->bi_directional; if the controller then answers with rvalid = 0 the response is never compared, the host still sends success2, and the queue is marked as authenticated.
A malicious or man-in-the-middle controller therefore only has to clear one flag to turn the configured bidirectional authentication into a one-way one, without holding any secret of its own. The target side already treats the mirror image of this as fatal: when the host supplied a challenge but no controller key is configured, nvmet_auth_success1() fails the authentication rather than answering with rvalid = 0.
Refuse the connection if the controller returns no response although bidirectional authentication was requested. chap->bi_directional is the right condition rather than ctrl->ctrl_key, because secure concatenation sends a challenge only to derive the PSK and deliberately clears bi_directional; a one-way setup without a controller secret keeps returning success as before.
--- drivers/nvme/host/auth.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/nvme/host/auth.c +14 -1
@@ -358,8 +358,21 @@ static int nvme_auth_process_dhchap_success1(struct nvme_ctrl *ctrl,nvme_auth_hmac_name (chap->hash_id), nvme_auth_dhgroup_name(chap->dhgroup_id)); -if (!data->rvalid) +if (!data->rvalid) { +/* +* The controller did not return a response. If we asked it to +* authenticate itself the session must not be used, otherwise +* mutual authentication would silently degrade to one-way. +*/ +if (chap->bi_directional) { +dev_warn (ctrl->device, +"qid %d: controller did not authenticate\n" , + chap->qid); + chap->status =NVME_AUTH_DHCHAP_FAILURE_FAILED ; +return -ECONNREFUSED ; + }return 0 ; + }/* Validate controller response */ if (crypto_memneq (chap->response, data->rval, data->hl)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 710/1257 nvmet: free the bvec on file namespace range errors
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 9d820d55b3cb4859c7cf42a74dc78f6154f97398 ]
nvmet_file_execute_rw() allocates the bvec before nvmet_file_execute_io() checks whether the request fits in the backing file. If the request extends beyond the file, nvmet_file_execute_io() calls nvmet_req_complete() to return an error. This skips nvmet_file_io_done(), so the allocated memory is never freed. Repeated requests can exhaust memory.
Use nvmet_file_io_done() to free the bvec before returning the range error to the client.
--- drivers/nvme/target/io-cmd-file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/io-cmd-file.c +2 -2
@@ -133,8 +133,8 @@ static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags) pos =le64_to_cpu (req->cmd->rw.slba) << req->ns->blksize_shift;if (unlikely (pos + req->transfer_len > req->ns->size)) { -nvmet_req_complete (req,errno_to_nvme_status (req, -ENOSPC )); -return true; + ret = -ENOSPC ; + goto complete; }memset (&req->f.iocb,0 ,sizeof (struct kiocb ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 711/1257 nvmet: require authentication before property set
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sung Byeongchan <[email protected]>
[ Upstream commit 44512543ff0413031516a02cde67323a55e0f769 ]
I/O queues do not perform independent DH-HMAC-CHAP authentication. They instead rely on authentication of the controller's admin queue. Fabrics property commands, however, are dispatched before the general admin command authentication check.
An unauthenticated peer can consequently set CC.EN, connect an I/O queue, and access a namespace after admin CONNECT reported that authentication was required. Reject PROPERTY_SET until the admin queue has authenticated. Targets without a configured authentication key are unchanged.
This was found by source review with AI assistance. A localhost NVMe/TCP wire reproducer retrieved a known 4 KiB namespace block in two independent boots without completing AUTH_SEND or AUTH_RECEIVE. With this change, PROPERTY_SET returned NVME_SC_AUTH_REQUIRED and the namespace data was not returned; the no-authentication control continued to work.
--- drivers/nvme/target/fabrics-cmd.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nvme/target/fabrics-cmd.c +4 -0
@@ -14,6 +14,10 @@ static void nvmet_execute_prop_set(struct nvmet_req *req)if (!nvmet_check_transfer_len (req,0 ))return ; +if (!nvmet_check_auth_status (req)) { + status =NVME_SC_AUTH_REQUIRED |NVME_STATUS_DNR ; + goto out; + }if (req->cmd->prop_set.attrib &1 ) { req->error_loc =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 712/1257 nvme: bound FDP config log reads to the received buffer
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
[ Upstream commit 3cf6de080d97d0d9641fbdb613d546c0734905dd ]
nvme_query_fdp_granularity() parses the FDP Configurations log using sizes the controller returns, without checking that they fit the buffer it was given. The log size is only bounded from above before kvmalloc(), so a size below the log header makes le16_to_cpu(h->numfdpc) read past the allocation, and a size of zero yields ZERO_SIZE_PTR and faults. Each configuration descriptor is then dereferenced (dsze while walking, and nrg and runs on the selected one) without checking that the whole descriptor lies within the buffer, so a descriptor at or past the end is read out of bounds. The out-of-bounds runs value is then exposed to userspace through /sys/block/nvmeXnY/queue/write_stream_granularity.
A device-supplied dsze that is not a multiple of eight also leaves the following descriptors unaligned, and the structure is not packed, so reading nrg and runs from one can fault on architectures without efficient unaligned access.
A malicious or buggy controller triggers this during namespace scan with a short FDP Configurations log:
[ 1.104828] BUG: KASAN: slab-out-of-bounds in nvme_alloc_ns+0x39a6/0x4480 [ 1.104848] Read of size 8 at addr ffff888009fd8fe0 by task kworker/u8:3/52 [ 1.104852] [ 1.104857] CPU: 1 UID: 0 PID: 52 Comm: kworker/u8:3 Not tainted 7.3.0-rc6-00063-g0c2669a9f4a1 #1 PREEMPT(lazy) [ 1.104862] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.17.0-0-gb52ca86e094d-prebuilt.qemu.org 04/01/2014 [ 1.104866] Workqueue: async async_run_entry_fn [ 1.104873] Call Trace: [ 1.104876] <TASK> [ 1.104878] dump_stack_lvl+0x66/0xa0 [ 1.104886] print_report+0xd0/0x630 [ 1.104893] ? nvme_alloc_ns+0x39a6/0x4480 [ 1.104897] ? __virt_addr_valid+0x209/0x3f0 [ 1.104903] ? nvme_alloc_ns+0x39a6/0x4480 [ 1.104907] kasan_report+0xe4/0x120 [ 1.104913] ? nvme_alloc_ns+0x39a6/0x4480 [ 1.104919] nvme_alloc_ns+0x39a6/0x4480 [ 1.104926] ? __pfx_nvme_alloc_ns+0x10/0x10 [ 1.104931] ? check_prev_add+0xfd/0xe80 [ 1.104942] ? lock_acquire+0x18d/0x300 [ 1.104948] ? nvme_find_get_ns+0xbb/0x2e0 [ 1.104952] ? find_held_lock+0x2b/0x80 [ 1.104956] ? nvme_find_get_ns+0x221/0x2e0 [ 1.104962] ? nvme_find_get_ns+0x231/0x2e0 [ 1.104967] ? nvme_scan_ns+0x2e1/0x8d0 [ 1.104971] ? kfree+0x2e5/0x510 [ 1.104976] ? __lock_acquire+0x570/0x1b00 [ 1.104982] nvme_scan_ns+0x56a/0x8d0 [ 1.104987] ? __pfx_nvme_scan_ns+0x10/0x10 [ 1.104994] ? lockdep_hardirqs_on_prepare+0xdc/0x190 [ 1.104999] ? trace_hardirqs_on+0x18/0x160 [ 1.105005] ? kvm_clock_get_cycles+0x19/0x40 [ 1.105011] ? __pfx_nvme_scan_ns_async+0x10/0x10 [ 1.105015] async_run_entry_fn+0x8d/0x290 [ 1.105020] process_one_work+0x8ac/0x1b00 [ 1.105029] ? __pfx_process_one_work+0x10/0x10 [ 1.105034] ? lock_acquire+0x18d/0x300 [ 1.105040] ? lock_is_held_type+0x8f/0x100 [ 1.105046] ? __pfx_async_run_entry_fn+0x10/0x10 [ 1.105050] worker_thread+0x4ee/0xe70 [ 1.105056] ? lockdep_hardirqs_on_prepare+0xdc/0x190 [ 1.105061] ? trace_hardirqs_on+0x18/0x160 [ 1.105066] ? __pfx_worker_thread+0x10/0x10 [ 1.105071] ? __pfx_worker_thread+0x10/0x10 [ 1.105076] kthread+0x2ce/0x3b0 [ 1.105080] ? __pfx_kthread+0x10/0x10 [ 1.105085] ret_from_fork+0x52e/0x780 [ 1.105090] ? __pfx_ret_from_fork+0x10/0x10 [ 1.105094] ? __switch_to+0x572/0xde0 [ 1.105101] ? __pfx_kthread+0x10/0x10 [ 1.105105] ret_from_fork_asm+0x1a/0x30 [ 1.105114] </TASK> [ 1.105116] [ 1.105117] Allocated by task 52: [ 1.105119] kasan_save_stack+0x33/0x60 [ 1.105123] kasan_save_track+0x14/0x30 [ 1.105126] __kasan_kmalloc+0x8f/0xa0 [ 1.105129] __kvmalloc_node_noprof+0x2e1/0x820 [ 1.105134] nvme_alloc_ns+0x1097/0x4480 [ 1.105138] nvme_scan_ns+0x56a/0x8d0 [ 1.105142] async_run_entry_fn+0x8d/0x290 [ 1.105145] process_one_work+0x8ac/0x1b00 [ 1.105148] worker_thread+0x4ee/0xe70 [ 1.105152] kthread+0x2ce/0x3b0 [ 1.105155] ret_from_fork+0x52e/0x780 [ 1.105159] ret_from_fork_asm+0x1a/0x30 [ 1.105163] [ 1.105164] The buggy address belongs to the object at ffff888009fd8fc0 [ 1.105164] which belongs to the cache kmalloc-32 of size 32 [ 1.105167] The buggy address is located 8 bytes to the right of [ 1.105167] allocated 24-byte region [ffff888009fd8fc0, ffff888009fd8fd8) [ 1.105171] [ 1.105172] The buggy address belongs to the physical page: [ 1.105175] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x9fd8 [ 1.105179] flags: 0x100000000000000(node=0|zone=1) [ 1.105183] page_type: f5(slab) [ 1.105188] raw: 0100000000000000 ffff888008c41780 dead000000000100 dead000000000122 [ 1.105192] raw: 0000000000000000 0000000000400040 00000000f5000000 0000000000000000 [ 1.105194] page dumped because: kasan: bad access detected [ 1.105195] [ 1.105196] Memory state around the buggy address: [ 1.105198] ffff888009fd8e80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 1.105201] ffff888009fd8f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 1.105203] >ffff888009fd8f80: fc fc fc fc fc fc fc fc 00 00 00 fc fc fc fc fc [ 1.105205] ^ [ 1.105207] ffff888009fd9000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fc [ 1.105210] ffff888009fd9080: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00 [ 1.105212] ==================================================================
Reject a log smaller than its header plus one configuration descriptor, zero the buffer so a short transfer leaves no uninitialized tail to parse, require each descriptor's declared size to be at least a descriptor and to leave room for the next one before walking it, and read the descriptor fields with the unaligned accessors.
--- drivers/nvme/host/core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/nvme/host/core.c +10 -5
@@ -2273,13 +2273,18 @@ static int nvme_query_fdp_granularity(struct nvme_ctrl *ctrl, } size =le32_to_cpu (hdr.sze); +if (size <sizeof (*h) +sizeof (*desc)) { +dev_warn (ctrl->device,"FDP config size too small:%zu\n" , + size); +return 0 ; + }if (size >PAGE_SIZE *MAX_ORDER_NR_PAGES ) {dev_warn (ctrl->device,"FDP config size too large:%zu\n" , size);return 0 ; } - h =kvmalloc (size,GFP_KERNEL ); + h =kvzalloc (size,GFP_KERNEL );if (!h)return -ENOMEM ;
@@ -2305,9 +2310,9 @@ static int nvme_query_fdp_granularity(struct nvme_ctrl *ctrl, desc = log; end = log + size -sizeof (*h);for (i =0 ; i < fdp_idx; i++) { -u16 dsze =le16_to_cpu (desc->dsze); +u16 dsze =get_unaligned_le16 (&desc->dsze); -if (!dsze || log + dsze > end) { +if (dsze <sizeof (*desc) || log + dsze +sizeof (*desc) > end) {dev_warn (ctrl->device,"FDP invalid config descriptor at index %d\n" , i); ret =0 ;
@@ -2317,13 +2322,13 @@ static int nvme_query_fdp_granularity(struct nvme_ctrl *ctrl, desc = log; } -if (le32_to_cpu (desc->nrg) >1 ) { +if (get_unaligned_le32 (&desc->nrg) >1 ) {dev_warn (ctrl->device,"FDP NRG > 1 not supported\n" ); ret =0 ; goto out; } - info->runs =le64_to_cpu (desc->runs); + info->runs =get_unaligned_le64 (&desc->runs); out:kvfree (h);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 713/1257 nvmet: zns: dont leak stale memory in zone management receive
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit 31b8a6af19b73e6167c4b655cd5e86681bac1c41 ]
A Zone Management Receive report returns the full buffer the host asked for, but nvmet_bdev_zone_zmgmt_recv_work() writes only the 8-byte Number of Zones field and one 64-byte descriptor for each matching zone that fits. The 56 reserved header bytes and every descriptor slot past the last match keep whatever the buffer held before. A 4096-byte report covering a single zone leaves 4024 bytes unwritten.
The tcp, rdma and fc transports allocate that buffer with sgl_alloc() and pci-epf with kmalloc(), none with __GFP_ZERO, and on success each sends the whole buffer to the host (nvmet_setup_c2h_data_pdu() for tcp), so the host receives old kernel memory from the target.
nvmet_bdev_execute_zone_mgmt_recv() also never checks the transport data length against NUMD, so on transports where the host sets that length, the buffer sent back can be much larger than the report NUMD describes. pci-epf derives its data length from NUMD, so the length check below does not apply there, but the zeroing still covers the report.
Reject a data length that does not match NUMD with nvmet_check_transfer_len(), as nvmet_bdev_execute_zone_append() does, and zero the report with nvmet_zero_sgl() before filling it. Zeroing NUMD bytes is only enough because of the length check, so the two go together.
Allocating with __GFP_ZERO in the transports would also close the leak, but it adds a memset to every read command to fix one handler, so the transports are left alone.
Tested over the loop, tcp, rdma and fc transports with a zoned null_blk namespace: before this patch, zone reports carried stale bytes and a data length larger than NUMD was accepted; with it, reports are fully initialized and such a length fails with Data SGL Length Invalid.
--- drivers/nvme/target/zns.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/nvme/target/zns.c +10 -0
@@ -282,6 +282,11 @@ static void nvmet_bdev_zone_zmgmt_recv_work(struct work_struct *w)if (status) goto out; +/* Only the zone count and matching descriptors are written below. */ + status =nvmet_zero_sgl (req,0 , out_bufsize); +if (status) + goto out; +if (!req_slba_nr_zones) { status =NVME_SC_SUCCESS ; goto out;
@@ -317,6 +322,11 @@ static void nvmet_bdev_zone_zmgmt_recv_work(struct work_struct *w)void nvmet_bdev_execute_zone_mgmt_recv (struct nvmet_req *req) { +u32 out_bufsize = (le32_to_cpu (req->cmd->zmr.numd) +1 ) <<2 ; + +if (!nvmet_check_transfer_len (req, out_bufsize)) +return ; +INIT_WORK (&req->z.zmgmt_work, nvmet_bdev_zone_zmgmt_recv_work);queue_work (zbd_wq, &req->z.zmgmt_work); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 714/1257 f2fs: convert inline quota files when turning quota on
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daeho Jeong <[email protected]>
[ Upstream commit a85e09bd6cc80059b9e0ef5cd1467719aa3129a8 ]
With a block size larger than 4KB, the inline data area is large enough to hold a freshly created quota file (quotacheck writes 6KB), so aquota.user/aquota.group stay inline after quotaon. f2fs does not expect quota files to be inline, and this causes two problems:
1. Quota file corruption. f2fs_write_single_data_page() sends quota inodes straight to f2fs_do_write_data_page(), which sees NULL_ADDR for index 0, treats the folio as truncated and drops it. Updates to the quota file are lost once the folio is reclaimed, so the quota tree reads stale data: chown/chgrp fail with EIO and quota entries of users disappear. For example, the kernel log shows:
find_free_dqentry: Data block full but it shouldn't
qtree_write_dquot: Error -5 occurred while creating quota
2. Deadlock. Writing a quota file past MAX_INLINE_DATA converts it from f2fs_write_begin() under f2fs_lock_op(). dquot_transfer() is called from f2fs_setattr() with f2fs_lock_op() already held, so chown/chgrp take cp_rwsem for read twice and hang, together with the checkpoint and every other writer, once a checkpoint waits for cp_rwsem in between (seen with generic/232).
Quota files only grow and there are at most MAXQUOTAS of them, so there is no point in keeping them inline. Convert them in f2fs_quota_on() and after dquot_quota_on_mount(), which keeps every block size on the same path as 4KB blocks, where quota files never fit inline. Quota sysfiles are created by mkfs with real blocks and are not affected.
--- fs/f2fs/super.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
fs/f2fs/super.c +32 -1
@@ -3305,15 +3305,42 @@ static qsize_t *f2fs_get_reserved_space(struct inode *inode)return &F2FS_I (inode)->i_reserved_quota; } +/* +* Quota files only grow and there are at most MAXQUOTAS of them, so there is +* no point in keeping them inline. Writeback of quota files does not handle +* inline data and would drop what was written to them. +*/ +static int f2fs_quota_convert_inline (struct inode *inode) +{ +int err; + +if (!f2fs_has_inline_data (inode)) +return 0 ; + +inode_lock (inode); + err =f2fs_convert_inline_inode (inode); +inode_unlock (inode); +return err; +} +static int f2fs_quota_on_mount (struct f2fs_sb_info *sbi,int type) { +int err; +if (is_set_ckpt_flags (sbi,CP_QUOTA_NEED_FSCK_FLAG )) {f2fs_err (sbi,"quota sysfile may be corrupted, skip loading it" );return 0 ; } -return dquot_quota_on_mount (sbi->sb,F2FS_OPTION (sbi).s_qf_names[type], + err =dquot_quota_on_mount (sbi->sb,F2FS_OPTION (sbi).s_qf_names[type],F2FS_OPTION (sbi).s_jquota_fmt, type); +if (err) +return err; + + err =f2fs_quota_convert_inline (sb_dqopt (sbi->sb)->files[type]); +if (err) +dquot_quota_off (sbi->sb, type); +return err; }int f2fs_enable_quota_files (struct f2fs_sb_info *sbi,bool rdonly)
@@ -3518,6 +3545,10 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, inode =d_inode (path->dentry); + err =f2fs_quota_convert_inline (inode); +if (err) + goto out; + err =filemap_fdatawrite (inode->i_mapping);if (err) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 715/1257 PCI: rockchip-ep: Do not attempt 5.0 GT/s retraining
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geraldo Nascimento <[email protected]>
[ Upstream commit 7f173bfa6d42742de4ab647e001232c1165ab28e ]
Drop the 5.0 GT/s Link Speed retraining code block from Rockchip PCIe EP driver. The reason is that Shawn Lin from Rockchip has reiterated that there may be danger of "catastrophic failure" in using their PCIe with 5.0 GT/s speeds.
While Rockchip has done so informally without issuing a proper errata, and the particulars are thus unknown, this may cause data loss or worse.
This change is corroborated by RK3399 official datasheet [1], which states maximum link speed for this platform is 2.5 GT/s.
[1] https://opensource.rock-chips.com/images/d/d7/Rockchip_RK3399_Datasheet_V2.1-20200323.pdf
--- drivers/pci/controller/pcie-rockchip-ep.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/pci/controller/pcie-rockchip-ep.c +0 -13
@@ -553,19 +553,6 @@ static void rockchip_pcie_ep_link_training(struct work_struct *work)if (ret) goto again; -/* -* Check the current speed: if gen2 speed was requested and we are not -* at gen2 speed yet, retrain again for gen2. -*/ - val =rockchip_pcie_read (rockchip,PCIE_CORE_CTRL ); -if (!PCIE_LINK_IS_GEN2 (val) && rockchip->link_gen ==2 ) { -/* Enable retrain for gen2 */ -rockchip_pcie_ep_retrain_link (rockchip); -readl_poll_timeout (rockchip->apb_base +PCIE_CORE_CTRL , - val,PCIE_LINK_IS_GEN2 (val),50 , -LINK_TRAIN_TIMEOUT ); - } -/* Check again that the link is up */ if (!rockchip_pcie_ep_link_up (rockchip)) goto again;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 716/1257 PCI: rockchip-host: Do not attempt 5.0 GT/s retraining
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geraldo Nascimento <[email protected]>
[ Upstream commit 2a1e6c382fb7567679c07bd6a7060fefc7a5edc9 ]
Drop the 5.0 GT/s Link Speed retraining from Rockchip PCIe Root Complex Mode Operation, so-called host driver.
The reason is that Shawn Lin from Rockchip has reiterated that there may be danger of "catastrophic failure" in using their PCIe with 5.0GT/s speeds.
While Rockchip has done so informally without issuing a proper errata, and the particulars are thus unknown, this may cause data loss or worse.
This change is corroborated by RK3399 official datasheet [1], which states maximum link speed for this platform is 2.5 GT/s.
[1] https://opensource.rock-chips.com/images/d/d7/Rockchip_RK3399_Datasheet_V2.1-20200323.pdf
--- drivers/pci/controller/pcie-rockchip-host.c | 20 -------------------- 1 file changed, 20 deletions(-)
drivers/pci/controller/pcie-rockchip-host.c +0 -20
@@ -328,26 +328,6 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) goto err_power_off_phy; } -if (rockchip->link_gen ==2 ) { -/* -* Enable retrain for gen2. This should be configured only after -* gen1 finished. -*/ - status =rockchip_pcie_read (rockchip,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL2 ); - status &= ~PCI_EXP_LNKCTL2_TLS ; - status |=PCI_EXP_LNKCTL2_TLS_5_0GT ; -rockchip_pcie_write (rockchip, status,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL2 ); - status =rockchip_pcie_read (rockchip,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL ); - status |=PCI_EXP_LNKCTL_RL ; -rockchip_pcie_write (rockchip, status,PCIE_RC_CONFIG_CR +PCI_EXP_LNKCTL ); - - err =readl_poll_timeout (rockchip->apb_base +PCIE_CORE_CTRL , - status,PCIE_LINK_IS_GEN2 (status),20 , -500 *USEC_PER_MSEC ); -if (err) -dev_dbg (dev,"PCIe link training gen2 timeout, fall back to gen1!\n" ); - } -/* Check the final link width from negotiated lane counter from MGMT */ status =rockchip_pcie_read (rockchip,PCIE_CORE_CTRL ); status = 0x1 << ((status & PCIE_CORE_PL_CONF_LANE_MASK) >>
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 717/1257 PCI: rockchip: Drive at 2.5 GT/s, error other speeds
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geraldo Nascimento <[email protected]>
[ Upstream commit 84d08ff902f1ec01177fef1a21a38934927f5aee ]
Configure the core to be driven at 2.5 GT/s Link Speed and ignore any other speed with a warning. Also drop the 5.0 GT/s Link Speed defines from Rockchip PCIe header.
The reason is that Shawn Lin from Rockchip has reiterated that there may be danger of "catastrophic failure" in using their PCIe with 5.0 GT/s speeds.
While Rockchip has done so informally without issuing a proper errata, and the particulars are thus unknown, this may cause data loss or worse.
This change is corroborated by RK3399 official datasheet [1], which states maximum link speed for this platform is 2.5 GT/s.
[1] https://opensource.rock-chips.com/images/d/d7/Rockchip_RK3399_Datasheet_V2.1-20200323.pdf
--- drivers/pci/controller/pcie-rockchip.c | 14 ++++++-------- drivers/pci/controller/pcie-rockchip.h | 3 --- 2 files changed, 6 insertions(+), 11 deletions(-)
drivers/pci/controller/pcie-rockchip.c +6 -8
@@ -66,8 +66,10 @@ int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip) } rockchip->link_gen =of_pci_get_max_link_speed (node); -if (rockchip->link_gen <0 || rockchip->link_gen >2 ) - rockchip->link_gen =2 ; +if (rockchip->link_gen <0 || rockchip->link_gen >=2 ) { + rockchip->link_gen =1 ; +dev_warn (dev,"invalid max-link-speed, limited to 2.5 GT/s\n" ); + }for (i =0 ; i <ROCKCHIP_NUM_PM_RSTS ; i++) rockchip->pm_rsts[i].id = rockchip_pci_pm_rsts[i];
@@ -147,12 +149,8 @@ int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) goto err_exit_phy; } -if (rockchip->link_gen ==2 ) -rockchip_pcie_write (rockchip,PCIE_CLIENT_GEN_SEL_2 , -PCIE_CLIENT_CONFIG ); -else -rockchip_pcie_write (rockchip,PCIE_CLIENT_GEN_SEL_1 , -PCIE_CLIENT_CONFIG ); +rockchip_pcie_write (rockchip,PCIE_CLIENT_GEN_SEL_1 , +PCIE_CLIENT_CONFIG ); regs =PCIE_CLIENT_ARI_ENABLE |PCIE_CLIENT_CONF_LANE_NUM (rockchip->lanes);
drivers/pci/controller/pcie-rockchip.h +0 -3
@@ -42,7 +42,6 @@#define PCIE_CLIENT_MODE_RC HWORD_SET_BIT(0x0040)#define PCIE_CLIENT_MODE_EP HWORD_CLR_BIT(0x0040)#define PCIE_CLIENT_GEN_SEL_1 HWORD_CLR_BIT(0x0080) -#define PCIE_CLIENT_GEN_SEL_2 HWORD_SET_BIT(0x0080)#define PCIE_CLIENT_LEGACY_INT_CTRL (PCIE_CLIENT_BASE + 0x0c)#define PCIE_CLIENT_INT_IN_ASSERT HWORD_SET_BIT(0x0002)#define PCIE_CLIENT_INT_IN_DEASSERT HWORD_CLR_BIT(0x0002)
@@ -197,8 +196,6 @@ (((x) & PCIE_CORE_PL_CONF_LS_MASK) == PCIE_CORE_PL_CONF_LS_READY)#define PCIE_LINK_UP (x) \ (((x) & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_UP) -#define PCIE_LINK_IS_GEN2 (x) \ - (((x) & PCIE_CORE_PL_CONF_SPEED_MASK) == PCIE_CORE_PL_CONF_SPEED_5G)#define RC_REGION_0_ADDR_TRANS_H 0x00000000#define RC_REGION_0_ADDR_TRANS_L 0x00000000
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 718/1257 sh: intc: Sort the prio and sense lists after filling them
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 94a219eda3b5fb1d1753a5ecf28b171c8f308a27 ]
register_intc_controller() sorts d->prio and d->sense right after allocating them, with hw->nr_prio_regs and hw->nr_sense_regs as the element count. The lists hold hw->nr_vectors entries and are only filled later, by intc_register_irq().
On SH7785, sh7785-irq0123 and sh7785-irq4567 have four vectors but the SoC's eleven priority registers, so sort() swaps 88 bytes in a 32 byte kmalloc object at boot. slub_debug=FZPU reports "Right Redzone overwritten" in kmalloc-32, and v6.5 and v6.6 panic in __kmem_cache_alloc_node() while registering sh7785-irq0123.
Found with a custom QEMU model of the SH7785LCR. On it, v6.4 sh7785lcr_defconfig boots with SLAB, the defconfig default before v6.5, and hangs before the console is up when built with SLUB.
Sort the lists once all vectors are registered, with the number of entries that were added.
--- drivers/sh/intc/core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/sh/intc/core.c +5 -6
@@ -275,9 +275,6 @@ int __init register_intc_controller(struct intc_desc *desc) k +=save_reg (d, k, hw->prio_regs[i].set_reg, smp); k +=save_reg (d, k, hw->prio_regs[i].clr_reg, smp); } - -sort (d->prio, hw->nr_prio_regs,sizeof (*d->prio), - intc_handle_int_cmp,NULL ); }if (hw->sense_regs) {
@@ -287,9 +284,6 @@ int __init register_intc_controller(struct intc_desc *desc)for (i =0 ; i < hw->nr_sense_regs; i++) k +=save_reg (d, k, hw->sense_regs[i].reg,0 ); - -sort (d->sense, hw->nr_sense_regs,sizeof (*d->sense), - intc_handle_int_cmp,NULL ); }if (hw->subgroups)
@@ -357,6 +351,11 @@ int __init register_intc_controller(struct intc_desc *desc) } } +sort (d->prio, d->nr_prio,sizeof (*d->prio), + intc_handle_int_cmp,NULL ); +sort (d->sense, d->nr_sense,sizeof (*d->sense), + intc_handle_int_cmp,NULL ); +intc_subgroup_init (desc, d);/* enable bits matching force_enable after registering irqs */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 719/1257 accel/qaic: Cancel Sahara read data work on removal
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 018e5a021904707b91cecd77e7f759937ec04643 ]
Sahara removal cancels fw_work and dump_work, but leaves read_data_work pending or running. The latter accesses the firmware and the device-managed context and transfer buffer, which are released during removal.
Cancel read_data_work after fw_work, which can schedule it, and before releasing the firmware. The MHI core suspends and resets the channels before invoking the driver's remove callback.
This issue was identified during our ongoing static-analysis research while reviewing kernel code. The same omission was also reported by the Sashiko bot while reviewing the Sahara relocation series.
--- drivers/accel/qaic/sahara.c | 1 + 1 file changed, 1 insertion(+)
drivers/accel/qaic/sahara.c +1 -0
@@ -880,6 +880,7 @@ static void sahara_mhi_remove(struct mhi_device *mhi_dev)cancel_work_sync (&context->fw_work);cancel_work_sync (&context->dump_work); +cancel_work_sync (&context->read_data_work);vfree (context->mem_dump);sahara_release_image (context);mhi_unprepare_from_transfer (mhi_dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 720/1257 f2fs: remove mappedtodisk flag usage in mmap write path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nanzhe Zhao <[email protected]>
[ Upstream commit b3c9843589257631bac18f30655e82d88970688a ]
PG_mappedtodisk was inherited from the nobh/buffer-head era. However, f2fs has no buffer heads and the flag is no longer meaningful. The only user of the flag is the "no holes" shortcut in f2fs_vm_page_mkwrite(), which makes mmap write faults skip marking the folio dirty. Moreover, it causes the following race condition with filesystem freezing:
CPU0 (write fault) CPU1 (freeze_super)
---- ----
f2fs_vm_page_mkwrite()
sb_start_pagefault()
/* shortcut: no dirty */
sb_end_pagefault()
sb_wait_write(SB_FREEZE_PAGEFAULT)
/* no waiter, passes */
sync_filesystem()
/* folio not dirty, skipped */ finish_fault()
/* PTE writable */
fault_dirty_shared_page()
folio_mark_dirty()
/* dirty folio on a frozen fs */
It will also skip APP_MAPPED_IO iostat/REQ_TIME updates and post-EOF folio zeroing.
Remove this shortcut in f2fs_vm_page_mkwrite() and stop setting it in f2fs_read_single_page().
--- fs/f2fs/data.c | 1 - fs/f2fs/file.c | 6 ------ 2 files changed, 7 deletions(-)
fs/f2fs/data.c +0 -1
@@ -2260,7 +2260,6 @@ static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi, got_it:if ((map->m_flags &F2FS_MAP_MAPPED )) { block_nr = map->m_pblk + block_in_file - map->m_lblk; -folio_set_mappedtodisk (folio);if (!f2fs_is_valid_blkaddr (F2FS_I_SB (inode), block_nr,DATA_GENERIC_ENHANCE_READ )) {
fs/f2fs/file.c +0 -6
@@ -217,12 +217,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)/* wait for GCed page writeback via META_MAPPING */ f2fs_wait_on_block_writeback (inode, dn.data_blkaddr); -/* -* check to see if the page is mapped already (no holes) -*/ -if (folio_test_mappedtodisk (folio)) - goto out_sem; -/* page is wholly or partially inside EOF */ if (((loff_t)(folio->index +1 ) <<PAGE_SHIFT ) >i_size_read (inode)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 721/1257 f2fs: allow pinning empty compressed files
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Chang <[email protected]>
[ Upstream commit 2eebc31ae5f53e1066bb6238c8087c23b688ad17 ]
Commit a64a3fec11e7 ("f2fs: force out-place update for all writes on compressed file") updated f2fs_should_update_outplace() to always return true for compressed files. However, this function is also called during f2fs_ioc_set_pin_file() validation, so pinning an empty file with compression enabled now fails with -EINVAL before the compression flag can be stripped.
Fix this by guarding the f2fs_compressed_file(inode) check with fio in f2fs_should_update_outplace(). This preserves forced OPU for actual compressed writes (fio != NULL), while allowing f2fs_ioc_set_pin_file() (fio == NULL) to proceed to f2fs_disable_compressed_file(inode).
--- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c +1 -1
@@ -2913,7 +2913,7 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)* If IO comes from compressed write path and fallback to raw write, * force out‑place to prevent metadata‑data inconsistency. */ -if (f2fs_compressed_file (inode)) +if (fio &&f2fs_compressed_file (inode))return true;/* swap file is migrating in aligned write mode */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 722/1257 f2fs: read i_size once in f2fs_vm_page_mkwrite
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nanzhe Zhao <[email protected]>
[ Upstream commit c04f209773ecb31e592cababce0d6658ee0b8d58 ]
f2fs_vm_page_mkwrite() reads i_size twice: once to check whether the folio is partially beyond EOF, and once to calculate the offset for folio_zero_segment(). But a concurrent buffered write can extend isize and cause the following race condition to corrupt data:
buffered write writes [0,3500)
CPU0 (write fault) CPU1 (buffered write)
---- ----
f2fs_vm_page_mkwrite()
folio_lock(folio)
if (((loff_t)(folio->index + 1) << PAGE_SHIFT) >
i_size_read(inode))
/* i_size_read() = 3500 */
write(fd, buf, 200, 4096)
/* writes into page1, does not
wait for folio lock */
i_size_write(inode, 4296) offset = i_size_read(inode) & ~PAGE_MASK
/* i_size_read() = 4296, offset = 200 */ folio_zero_segment(folio, offset, folio_size(folio)) /* valid data [200, 3500) is zeroed */
Fix this by reading i_size once and using the same value for both the EOF check and the zeroing offset.
--- fs/f2fs/file.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
fs/f2fs/file.c +10 -4
@@ -124,6 +124,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct dnode_of_data dn;bool need_alloc = !f2fs_is_pinned_file (inode); +loff_t isize;int err =0 ;vm_fault_t ret;
@@ -187,8 +188,14 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)filemap_invalidate_lock_shared (inode->i_mapping);folio_lock (folio); +/* +* A concurrent buffered write can extend isize, so we store isize in a +* local variable to let the zeroing offset match the EOF check below. +*/ + isize =i_size_read (inode); +if (unlikely (folio->mapping != inode->i_mapping || -folio_pos (folio) >i_size_read (inode) || +folio_pos (folio) > isize || !folio_test_uptodate (folio))) {folio_unlock (folio); err = -EFAULT ;
@@ -218,11 +225,10 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)f2fs_wait_on_block_writeback (inode, dn.data_blkaddr);/* page is wholly or partially inside EOF */ -if (((loff_t)(folio->index +1 ) <<PAGE_SHIFT ) > -i_size_read (inode)) { +if (((loff_t)(folio->index +1 ) <<PAGE_SHIFT ) > isize) {loff_t offset; - offset =i_size_read (inode) & ~PAGE_MASK ; + offset = isize & ~PAGE_MASK ;folio_zero_segment (folio, offset,folio_size (folio)); }folio_mark_dirty (folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 723/1257 f2fs: check every cur_*_segno[] entry on readonly images
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kaixuan Li <[email protected]>
[ Upstream commit 9c4ee79190c8c23a9fb5c07d3bc87eaac514b2bb ]
sanity_check_ckpt() bounds-checks cur_node_segno[] and cur_data_segno[] against main_segs, but on an image with the RO feature the goto that skips the duplicate-segno cross-checks also leaves the enclosing loop, so only index 0 of each array is ever checked.
An unchecked index reaches __set_sit_entry_type() through build_curseg() -> reset_curseg(), which writes se->type through &sit_i->sentries[segno]. With segment_count_main 120 and cur_data_segno[1] set to 200, KASAN reports three out-of-bounds writes during mount and the mount then succeeds.
Use continue so every index is bounds-checked, and skip the node-vs-data cross-check explicitly, which is the other thing the old goto skipped.
--- fs/f2fs/super.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/super.c +6 -3
@@ -4307,7 +4307,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)return 1 ;if (f2fs_sb_has_readonly (sbi)) - goto check_data; +continue ;for (j = i +1 ; j <NR_CURSEG_NODE_TYPE ; j++) { if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
@@ -4319,14 +4319,14 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) } } } -check_data: +for (i =0 ; i <NR_CURSEG_DATA_TYPE ; i++) {if (le32_to_cpu (ckpt->cur_data_segno[i]) >= main_segs ||le16_to_cpu (ckpt->cur_data_blkoff[i]) >= blocks_per_seg)return 1 ;if (f2fs_sb_has_readonly (sbi)) - goto skip_cross; +continue ;for (j = i +1 ; j <NR_CURSEG_DATA_TYPE ; j++) { if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
@@ -4338,6 +4338,9 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) } } } +if (f2fs_sb_has_readonly (sbi)) + goto skip_cross; +for (i =0 ; i <NR_CURSEG_NODE_TYPE ; i++) {for (j =0 ; j <NR_CURSEG_DATA_TYPE ; j++) { if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 724/1257 f2fs: allow empty strings for journaled quota options
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hengyu Liang <[email protected]>
[ Upstream commit 0354a04b8c34e26cc66d0f43785d388163b6bacc ]
Commit 2a3db1e02ce0 ("f2fs: allow empty mount string for Opt_usr|grp|projjquota") added support for passing usrjquota, grpjquota and prjjquota as flags to disable journaled quotas.
However, it also replaced fsparam_string_empty() with fsparam_string(), which rejects an empty string. As of now, mount(2) and fsconfig(FSCONFIG_SET_STRING) reject usrjquota=, grpjquota= and prjjquota= with EINVAL, although these forms are still documented in Documentation/filesystems/f2fs.rst.
The issue can be reproduced on an F2FS device with:
mount -t f2fs -o usrjquota= /dev/loop5 /mnt/f
Before this commit, the command succeeds. Afterwards, it fails with EINVAL and logs "f2fs: Bad value for 'usrjquota'".
The same failure occurs when remounting to clear a quota file name.
This patch will restore fsparam_string_empty() for the three options while retaining the flag entries, so both forms are accepted.
--- fs/f2fs/super.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/super.c +3 -3
@@ -338,11 +338,11 @@ static const struct fs_parameter_spec f2fs_param_specs[] = {fsparam_flag ("usrquota" , Opt_usrquota),fsparam_flag ("grpquota" , Opt_grpquota),fsparam_flag ("prjquota" , Opt_prjquota), -fsparam_string ("usrjquota" , Opt_usrjquota), +fsparam_string_empty ("usrjquota" , Opt_usrjquota),fsparam_flag ("usrjquota" , Opt_usrjquota), -fsparam_string ("grpjquota" , Opt_grpjquota), +fsparam_string_empty ("grpjquota" , Opt_grpjquota),fsparam_flag ("grpjquota" , Opt_grpjquota), -fsparam_string ("prjjquota" , Opt_prjjquota), +fsparam_string_empty ("prjjquota" , Opt_prjjquota),fsparam_flag ("prjjquota" , Opt_prjjquota),fsparam_flag ("nat_bits" , Opt_nat_bits), fsparam_enum("jqfmt", Opt_jqfmt, f2fs_param_jqfmt),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 725/1257 f2fs: fix defragment writeback range truncation on 32-bit
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 92154fe28c3701bebf75176dc5522bec62519a8f ]
f2fs_defragment_range() flushes the range it is about to defragment:
filemap_write_and_wait_range(inode->i_mapping, pg_start << PAGE_SHIFT, (pg_end << PAGE_SHIFT) - 1);
pg_start and pg_end are pgoff_t, 32 bits on 32-bit kernels, so both shifts are evaluated in 32 bits and truncated before they are widened to the loff_t parameters. pg_end is only capped by the file's page count, so for a file larger than 4 GiB the shift wraps.
For a 5 GiB file pg_end is 1310720 and the range collapses from [0, 5 GiB) to [0, 1 GiB), leaving the rest of the dirty pages unwritten before the blocks are moved. For 8 GiB the shift yields 0, the minus one makes it (loff_t)-1, and the range becomes [0, LLONG_MAX].
The matching call in f2fs_collapse_range() already casts:
filemap_write_and_wait_range(inode->i_mapping, (loff_t)index << PAGE_SHIFT, ((loff_t)pg_end << PAGE_SHIFT) - 1);
Do the same here. On i386 the shift changes from "shl $0xc,%ecx" to "shld", i.e. from a 32-bit shift to a double-precision one.
--- fs/f2fs/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/file.c +2 -2
@@ -3029,8 +3029,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,/* writeback all dirty pages in the range */ err =filemap_write_and_wait_range (inode->i_mapping, - pg_start <<PAGE_SHIFT , - (pg_end <<PAGE_SHIFT ) -1 ); + (loff_t )pg_start <<PAGE_SHIFT , + ((loff_t )pg_end <<PAGE_SHIFT ) -1 );if (err) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 726/1257 f2fs: disallow mmap write and data-modifying fallocate on atomic files
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daeho Jeong <[email protected]>
[ Upstream commit 06dfe4a7eb696d868b196c2a49873142f19bd862 ]
Stores through a shared writable mapping and fallocate with FALLOC_FL_PUNCH_HOLE, FALLOC_FL_ZERO_RANGE, FALLOC_FL_COLLAPSE_RANGE or FALLOC_FL_INSERT_RANGE do not go through ->write_begin, so they bypass the COW inode and modify the original inode directly. Reject them while the file is in atomic write mode, as fallocate already does for pinned and compressed files. A write fault gets SIGBUS and fallocate gets -EOPNOTSUPP.
fallocate without these flags only preallocates blocks and stays allowed.
f2fs_vm_page_mkwrite() cannot take inode_lock, so check the flag under invalidate_lock, and hold invalidate_lock in f2fs_ioc_start_atomic_write() from the flush until the flag is set. Otherwise a fault could check the flag, then start_atomic_write could flush and set the flag, and the fault would dirty the folio afterwards.
--- fs/f2fs/file.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
fs/f2fs/file.c +18 -2
@@ -187,6 +187,17 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)file_update_time (vmf->vma->vm_file);filemap_invalidate_lock_shared (inode->i_mapping); +/* +* mmap stores bypass the COW inode and would break atomicity. Check +* under invalidate_lock: f2fs_ioc_start_atomic_write() holds it while +* flushing dirty folios and setting FI_ATOMIC_FILE, so either it sees +* our dirty folio and writes it back, or we see the flag. +*/ +if (unlikely (f2fs_is_atomic_file (inode))) { + err = -EOPNOTSUPP ; + goto out_sem; + } +folio_lock (folio);/* * A concurrent buffered write can extend isize, so we store isize in a
@@ -2107,9 +2118,11 @@ static long f2fs_fallocate(struct file *file, int mode,/* * Pinned file should not support partial truncation since the block -* can be used by applications. +* can be used by applications. Atomic files should not either, since +* these modify the original inode directly and break atomicity. */ -if ((f2fs_compressed_file (inode) ||f2fs_is_pinned_file (inode)) && +if ((f2fs_compressed_file (inode) ||f2fs_is_pinned_file (inode) || +f2fs_is_atomic_file (inode)) && (mode & (FALLOC_FL_PUNCH_HOLE |FALLOC_FL_COLLAPSE_RANGE |FALLOC_FL_ZERO_RANGE |FALLOC_FL_INSERT_RANGE ))) { ret = -EOPNOTSUPP ;
@@ -2397,6 +2410,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)f2fs_down_write (&fi->i_gc_rwsem[WRITE ]);f2fs_down_write (&fi->i_gc_rwsem[READ ]); +/* serialize with f2fs_vm_page_mkwrite(), see the comment there */ +filemap_invalidate_lock (inode->i_mapping);/* * Should wait end_io to count F2FS_WB_CP_DATA correctly by
@@ -2452,6 +2467,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)f2fs_i_size_write (fi->cow_inode, isize); out_unlock: +filemap_invalidate_unlock (inode->i_mapping);f2fs_up_write (&fi->i_gc_rwsem[READ ]);f2fs_up_write (&fi->i_gc_rwsem[WRITE ]);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 727/1257 f2fs: fix to use bio_in_atomic() in f2fs_read_end_io()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit a605d5d71a6d280c43c7ede9778dda63fb5c3f22 ]
f2fs_read_end_io() uses "in_task() && !irqs_disabled()" to decide whether it is safe to sleep, the result is passed down as @in_task to:
- f2fs_put_dic() -> f2fs_free_dic() -> f2fs_release_decomp_mem() -> vm_unmap_ram(), which may sleep.
- f2fs_end_read_compressed_page() -> f2fs_cache_compressed_page() -> f2fs_grab_cache() -> f2fs_lock_cache(), which may sleep in wait_on_bit_lock().
However, the check still treats below task contexts as sleepable:
- with spinlock held via spin_lock(), i.e. preempt count != 0 while irqs are enabled.
- with BH disabled via local_bh_disable().
- inside an RCU read lock on kernels with CONFIG_PREEMPTION.
- with any spinlock held on kernels without CONFIG_PREEMPT_COUNT.
So the "sleeping function called from invalid context" issue fixed by commit 08a7efc5b02a ("f2fs: vm_unmap_ram() may be called from an invalid context") can still be triggered.
The block layer provides bio_in_atomic() for exactly this purpose, it checks rcu_preempt_depth() and preemptible(), and conservatively returns true if CONFIG_PREEMPT_COUNT is disabled, let's use it instead. The difference is as below:
old: intask = in_task() && !irqs_disabled()
new: intask = !bio_in_atomic()
Context | old intask | new intask
-------------------------------------+----------------+----------------
Hard IRQ / softirq | false | false IRQs disabled | false | false spin_lock() held, IRQs enabled | true (wrong) | false BH disabled by local_bh_disable() | true (wrong) | false RCU read lock (CONFIG_PREEMPTION) | true (wrong) | false Spinlock held, w/o PREEMPT_COUNT | true (wrong) | false
Note that on kernels without CONFIG_PREEMPT_COUNT, bio_in_atomic() always returns true, so dic freeing will always be offloaded to sbi->wq, and compressed pages will not be cached in f2fs_read_end_io(); this is the price of correctness, since there is no way to tell whether the current context can sleep.
--- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c +1 -1
@@ -303,7 +303,7 @@ static void f2fs_read_end_io(struct bio *bio) {struct f2fs_sb_info *sbi =F2FS_F_SB (bio_first_folio_all (bio));struct bio_post_read_ctx *ctx; -bool intask =in_task () && !irqs_disabled (); +bool intask = !bio_in_atomic ();iostat_update_and_unbind_ctx (bio); ctx = bio->bi_private;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 728/1257 spi: ljca: validate the response length before copying the data
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit 0fe4573c822c4c9152e2fd5269ab85410c9e458f ]
ljca_spi_read_write() only checks that the response from the adapter carries the packet header and a non-zero payload length before copying r_packet->len bytes from the response into the transfer buffer.
The payload length is taken from the packet the device sent back and is neither bounded by the number of bytes actually received nor by the size of the requested transfer: a misbehaving adapter can announce a payload larger than what it actually sent, and the memcpy then reads past the end of the 60-byte input buffer and writes past the end of the caller's transfer buffer.
Check that the response carries the full header before reading r_packet->len, then reject responses whose payload is not contained in the data received or is longer than the requested transfer.
--- drivers/spi/spi-ljca.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/spi/spi-ljca.c +6 -1
@@ -105,7 +105,12 @@ static int ljca_spi_read_write(struct ljca_spi_dev *ljca_spi, const u8 *w_data, (u8 *)r_packet, LJCA_SPI_BUF_SIZE);if (ret <0 )return ret; -else if (ret <sizeof (*r_packet) || r_packet->len <=0 ) + +if (ret <sizeof (*r_packet)) +return -EIO ; + +if (!r_packet->len || ret <sizeof (*r_packet) + r_packet->len || + r_packet->len > len)return -EIO ;if (r_data)
Signature · 1 line
2.53.0
Jiri Slaby
maintainerRe: [PATCH 7.3 0728/1257] spi: ljca: validate the response length before copying the data
Quoted 7 lines · Greg Kroah-Hartman
7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit
0fe4573c822c4c9152e2fd5269ab85410c9e458f]
And this one is allegedly fixed by:5072a9fae45a ("spi: ljca: Don't require data in write replies")
thanks,
Signature · 2 lines
js suse labs
Re: [PATCH 7.3 0728/1257] spi: ljca: validate the response length before copying the data
Quoted 1 line
[PATCH 7.3 0728/1257] spi: ljca: validate the response length before copying the data
Queued the fix for 7.3, 6.18 and 6.12, so it rides with the patch it fixes. Thanks.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 729/1257 pinctrl: stm32: Fix fwnode reference leak in stm32_gpiolib_register_bank()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Ke <[email protected]>
[ Upstream commit 54c66b5e47a9b10cbf4a1efe9b01301b7ffee205 ]
stm32_gpiolib_register_bank() walks the "gpio-ranges" property with fwnode_property_get_reference_args(). As documented in drivers/base/property.c:
* The caller is responsible for calling fwnode_handle_put() on the
* returned @args->fwnode pointer.
The returned reference is never put. The function calls the helper twice, once directly and then repeatedly in a while loop, and each call overwrites args, so only the last reference is even reachable and all the earlier ones are leaked for good.
Put the reference as soon as args.args[] has been consumed, both for the initial call and for every iteration of the loop.
Found by code review.
--- drivers/pinctrl/stm32/pinctrl-stm32.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +5 -1
@@ -1666,8 +1666,12 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode/* get the last defined gpio line (offset + nb of pins) */ npins = args.args[0 ] + args.args[2 ]; -while (!fwnode_property_get_reference_args (fwnode,"gpio-ranges" ,NULL ,3 , ++i, &args)) +fwnode_handle_put (args.fwnode); + +while (!fwnode_property_get_reference_args (fwnode,"gpio-ranges" ,NULL ,3 , ++i, &args)) { npins =max (npins, (int )(args.args[0 ] + args.args[2 ])); +fwnode_handle_put (args.fwnode); + } }else { bank_nr = pctl->nbanks; bank->gpio_chip.base = bank_nr *STM32_GPIO_PINS_PER_BANK ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 730/1257 lib/decompress_bunzip2: fix off-by-one in run-length bounds check
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Turner <[email protected]>
[ Upstream commit 69919be2b93ef3922f646729ff42b4bd9a30846b ]
The run-length path rejects a block when dbufCount+t equals dbufSize, but the loop that follows writes exactly t bytes starting at dbufCount, so a block that fills the buffer exactly is legal. bzip2 allows it too: its decompressor bounds a block at 100000 * blockSize100k and checks that limit per byte appended. Use > instead of >=.
bzip2's encoder stops filling a block 19 bytes early, so nothing it produces ever reaches the limit and the bug stays hidden. Compressors that use the full block size do reach it: an lbzip2 -9 image whose block ends on a run fails to decode, and a self-extracting kernel built that way does not boot.
This code came from busybox, which fixed the same line in 2013 in commit 932e233a491b ("bunzip2: fix off-by-one check").
I ran into this because my system uses lbzip2 as /bin/bzip2 -- a common thing on Gentoo I believe. As far as I can tell, anyone using lbzip2 as their system bzip2 would run into this and it's only because it's very uncommon these days to compress a kernel with bzip2 that no one has noticed. I only noticed because I was adding support for various compression formats on alpha.
--- lib/decompress_bunzip2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/decompress_bunzip2.c +1 -1
@@ -439,7 +439,7 @@ static int INIT get_next_block(struct bunzip_data *bd)array.) */ if (runPos) { runPos =0 ; -if (dbufCount+t >= dbufSize) +if (dbufCount+t > dbufSize)return RETVAL_DATA_ERROR ; uc = symToByte[mtfSymbol[0 ]];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 731/1257 panic: fix redirect CPU race in panic_try_force_cpu()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 73554d8db4951d2a486405a2759cc0ffd282c0b2 ]
Patch series "panic: fix panic_force_cpu= redirect races and NMI bypass", v7.
The panic_force_cpu= parameter redirects a panic to a specific CPU so the crash kernel runs there. The redirect code in panic_try_force_cpu() had two races and an NMI bypass, all found by Sashiko. This series closes them and kills one more hack that the rework turned up.
Panic from NMI still goes through the redirect path first, so the crash kernel ends up on the CPU the admin asked for. The redirect buffer is a static 1KB now, no initcall, no fallback message.
This patch (of 6):
The cmpxchg() in panic_try_force_cpu() makes sure that only one CPU tries to redirect panic() to the requested CPU. It is similar to the cmpxchg() in panic_try_start() which makes sure that only one CPU does the panic(). In both situations, only the winner of cmpxchg() should proceed further. Other CPUs should go offline.
There is a bug because the cmpxchg loser returns false and falls through into vpanic(). Two non-target CPUs A and B panic, the requested CPU is C:
cpu A cpu B
---------- ----------
panic() panic()
vpanic() vpanic()
panic_try_force_cpu() panic_try_force_cpu()
cmpxchg wins cmpxchg fails
redirect = A old_cpu = A
IPI -> C return false <- BUG
return true panic_try_start() wins
panic_smp_self_stop() __crash_kexec() on B
(A stops) (target C bypassed)
The loser must stop, not fall through. It cannot just return true, though. A CPU that already won the redirect cmpxchg can reenter panic_try_force_cpu() on the same CPU, for example a nested NMI during the message formatting, before the IPI is sent:
cpu A (1st) cpu A (nested)
---------- ----------
panic()
vpanic()
panic_try_force_cpu()
cmpxchg wins (redirect = A)
vsnprintf(msg) ...
<-- NMI, nested panic -->
panic()
vpanic()
panic_try_force_cpu()
cmpxchg fails
old_cpu == A (this CPU)
return true <- would halt
panic_smp_self_stop()
(IPI never sent, panic abandoned)Check old_cpu against this_cpu so a second call from the same CPU returns false and falls through to panic_try_start() instead.
Also fix the panic_in_progress() check. We must not redirect when panic_cpu is already assigned. Return true to stop when the panic is on another CPU, false to proceed when it is this one.
Update the panic_try_force_cpu() doc comment for the new return value semantics.
--- kernel/panic.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
kernel/panic.c +12 -7
@@ -371,8 +371,9 @@ int __weak panic_smp_redirect_cpu(int target_cpu, void *msg)* for the crash kernel to function correctly. This function redirects * panic handling to the CPU specified via the panic_force_cpu= boot parameter. * -* Returns false if panic should proceed on current CPU. -* Returns true if panic was redirected. +* Returns true when this CPU must stop: the panic was redirected or is +* already running on another CPU. +* Returns false when panic() should proceed on this CPU. */ __printf(1, 0)static bool panic_try_force_cpu (const char *fmt,va_list args)
@@ -396,16 +397,20 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)return false; } -/* Another panic already in progress */ +/* +* Don't redirect when a panic is already in progress. Stop this +* CPU when it's another one, proceed when it's this one. +*/ if (panic_in_progress ()) -return false; +return panic_on_other_cpu ();/* -* Only one CPU can do the redirect. Use atomic cmpxchg to ensure -* we don't race with another CPU also trying to redirect. +* Only one CPU can do the redirection. Others should go offline. +* Continue with panic() when we already tried the redirection +* from this CPU before, for example via nmi_panic(). */ if (!atomic_try_cmpxchg (&panic_redirect_cpu, &old_cpu, this_cpu)) -return false; +return old_cpu != this_cpu;/* * Use dynamically allocated buffer if available, otherwise
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 732/1257 panic: flatten nmi_panic control flow
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 75eb687ff2bcec9fba31bbe266e5f91e5c283efe ]
panic() is __noreturn, so the else after panic_try_start() is dead. Drop it so the force_cpu path can be added cleanly on top.
--- kernel/panic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/panic.c +2 -1
@@ -517,7 +517,8 @@ void nmi_panic(struct pt_regs *regs, const char *msg) {if (panic_try_start ())panic ("%s" , msg); -else if (panic_on_other_cpu ()) + +if (panic_on_other_cpu ())nmi_panic_self_stop (regs); }EXPORT_SYMBOL (nmi_panic);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 733/1257 panic: fix va_list reuse in panic_try_force_cpu()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 245001a347f1effc09c233d1712e1efeedab59ee ]
vsnprintf() consumes the caller's va_list. When the redirect fails, vpanic() reuses it for the panic message, which is undefined behavior. Use va_copy().
--- kernel/panic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/panic.c +6 -1
@@ -417,7 +417,12 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)* fall back to static message for early boot panics or allocation failure. */ if (panic_force_buf) { -vsnprintf (panic_force_buf,PANIC_MSG_BUFSZ , fmt, args); +va_list ap; + +/* Do not consume args, the caller reuses it if we fail */ +va_copy (ap, args); +vsnprintf (panic_force_buf,PANIC_MSG_BUFSZ , fmt, ap); +va_end (ap); msg = panic_force_buf; }else { msg ="Redirected panic (buffer unavailable)" ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 734/1257 panic: restore variable arguments to nmi_panic()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit ed9e4c1ff15d5b935f467811541ca0aa6e49c5d0 ]
nmi_panic() used to accept variable arguments until commit ebc41f20d77f ("panic: change nmi_panic from macro to function") flattened it to a final message string. vpanic() did not exist back then, so the function had to format through panic("%s", msg).
Bring the variable arguments back and format with vpanic() directly. The next patch makes nmi_panic() try the panic_force_cpu= redirect before claiming panic_cpu. panic_try_force_cpu() needs to print the message but it is used also by panic() which accepts variable argument list. The string could be formatted only when a CPU gets assigned to process the redirection. Otherwise, there might be a race when writing to the panic_force_buf.
No current caller passes a string with format specifiers. The closest one is hpwdt_pretimeout(), which builds panic_msg with hex_byte_pack() and has only two variants, both plain strings. But the new __printf() annotation on nmi_panic() would warn with -Wformat-security there because the buffer is passed directly as the format argument, so switch it to nmi_panic(regs, "%s", panic_msg).
--- drivers/watchdog/hpwdt.c | 2 +- include/linux/panic.h | 3 ++- kernel/panic.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/watchdog/hpwdt.c +1 -1
@@ -199,7 +199,7 @@ static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs) }hex_byte_pack (panic_msg, nmistat); -nmi_panic (regs, panic_msg); +nmi_panic (regs,"%s" , panic_msg);return NMI_HANDLED ; }
include/linux/panic.h +2 -1
@@ -13,7 +13,8 @@ __printf(1, 2)void panic (const char *fmt, ...)__noreturn __cold ; __printf(1, 0)void vpanic (const char *fmt,va_list args)__noreturn __cold ; -void nmi_panic (struct pt_regs *regs,const char *msg); +__printf(2, 3) +void nmi_panic (struct pt_regs *regs,const char *fmt, ...);void check_panic_on_warn (const char *origin);extern void oops_enter (void );extern void oops_exit (void );
kernel/panic.c +8 -2
@@ -518,13 +518,19 @@ EXPORT_SYMBOL(panic_on_other_cpu);* nmi_panic_self_stop() which can provide architecture dependent code such * as saving register state for crash dump. */ -void nmi_panic (struct pt_regs *regs,const char *msg) +void nmi_panic (struct pt_regs *regs,const char *fmt, ...) { +va_list args; + +va_start (args, fmt); +if (panic_try_start ()) -panic ("%s" , msg); +vpanic (fmt, args);if (panic_on_other_cpu ())nmi_panic_self_stop (regs); + +va_end (args); }EXPORT_SYMBOL (nmi_panic);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 735/1257 panic: allow force_cpu redirect from an NMI
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 36c55a9625bb9ab7eb428ff8facc6d3d0a743180 ]
nmi_panic() claims panic_cpu via panic_try_start() before calling panic(). When the panic later reaches panic_try_force_cpu(), the panic_in_progress() check sees panic_cpu set and refuses to redirect. The crash kernel runs on the CPU that took the NMI instead of the CPU requested with panic_force_cpu=:
nmi_panic()
panic_try_start() wins, panic_cpu = X
panic("%s", msg)
vpanic()
panic_try_force_cpu()
panic_in_progress() true, panic_cpu is X
return false redirect bypassed
panic_try_start() already won
__crash_kexec() on X, not the requested CPU
Try the redirect before claiming panic_cpu instead, as suggested by Petr Mladek. nmi_panic() now calls panic_try_force_cpu() first and claims panic_cpu only when no redirect happened. The requested CPU claims panic_cpu itself when it runs panic(), so panic_cpu does not need to be handed off. panic_try_force_cpu() copies the arguments before formatting (patch 3), so nmi_panic() can pass them to vpanic() again when no redirect happens.
The redirect IPI is sent with smp_call_function_single_async(), which is not guaranteed to work from NMI context. Treat it as best effort. It is worth the risk because the redirection is only used when the crash kernel would not work on the panicking CPU anyway.
Keep returning when the panic is already running on this CPU. A nested NMI, for example with unknown_nmi_panic while this CPU is inside panic(), must return and let the interrupted panic() continue instead of parking the CPU in nmi_panic_self_stop().
Mark the redirecting CPU offline before stopping it, like vpanic() does, so that panic_other_cpus_shutdown() on the target CPU does not wait for it.
--- kernel/panic.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
kernel/panic.c +15 -4
@@ -513,10 +513,11 @@ bool panic_on_other_cpu(void)EXPORT_SYMBOL (panic_on_other_cpu);/* -* A variant of panic() called from NMI context. We return if we've already -* panicked on this CPU. If another CPU already panicked, loop in -* nmi_panic_self_stop() which can provide architecture dependent code such -* as saving register state for crash dump. +* A variant of panic() called from NMI context. The panic is first +* redirected to the CPU requested via panic_force_cpu=, when configured. +* We return if we've already panicked on this CPU. If another CPU already +* panicked, loop in nmi_panic_self_stop() which can provide architecture +* dependent code for saving register state for crash dump. */ void nmi_panic (struct pt_regs *regs,const char *fmt, ...) {
@@ -524,6 +525,16 @@ void nmi_panic(struct pt_regs *regs, const char *fmt, ...)va_start (args, fmt); +/* Try to redirect to the requested CPU before claiming panic_cpu. */ +if (panic_try_force_cpu (fmt, args)) { +/* +* Mark ourselves offline so panic_other_cpus_shutdown() won't +* wait for us on architectures that check num_online_cpus(). +*/ +set_cpu_online (raw_smp_processor_id (), false); +nmi_panic_self_stop (regs); + } +if (panic_try_start ())vpanic (fmt, args);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 736/1257 panic: kill the "buffer unavailable" redirect fallback
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 68d956e9e235c2e125f77a9e98831e297b624a75 ]
The redirect buffer is a disgusting terrible hack. panic_force_buf is kmalloc'ed in a late_initcall, and until then the redirect delivers this as the panic message:
Redirected panic (buffer unavailable)
The whole point of the redirect is to hand the panic message to the target CPU, so the crash kernel boots knowing it panicked and not why. And that window is the entire boot, from the early_param to the late_initcall, which is exactly when you most want the message.
Make it a static 1KB buffer and kill the initcall. The cost is 1KB of .bss in SMP crash dump builds, and it is only ever touched when panic_force_cpu= is set anyway. The local msg variable is gone too, the buffer goes directly to panic_smp_redirect_cpu().
--- kernel/panic.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-)
kernel/panic.c +7 -27
@@ -307,7 +307,7 @@ atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);atomic_t panic_redirect_cpu =ATOMIC_INIT (PANIC_CPU_INVALID );#if defined(CONFIG_SMP ) && defined(CONFIG_CRASH_DUMP ) -static char *panic_force_buf; +static char panic_force_buf[PANIC_MSG_BUFSZ ];static int __init panic_force_cpu_setup (char *str) {
@@ -326,17 +326,6 @@ static int __init panic_force_cpu_setup(char *str) }early_param ("panic_force_cpu" , panic_force_cpu_setup); -static int __init panic_force_cpu_late_init (void ) -{ -if (panic_force_cpu <0 ) -return 0 ; - - panic_force_buf =kmalloc (PANIC_MSG_BUFSZ ,GFP_KERNEL ); - -return 0 ; -} -late_initcall (panic_force_cpu_late_init); -static void do_panic_on_target_cpu (void *info) {panic ("%s" , (char *)info);
@@ -380,7 +369,7 @@ static bool panic_try_force_cpu(const char *fmt, va_list args) {int this_cpu =raw_smp_processor_id ();int old_cpu =PANIC_CPU_INVALID ; -const char *msg; +va_list ap;/* Feature not enabled via boot parameter */ if (panic_force_cpu <0 )
@@ -413,20 +402,11 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)return old_cpu != this_cpu;/* -* Use dynamically allocated buffer if available, otherwise -* fall back to static message for early boot panics or allocation failure. +* Do not consume args, the caller reuses them if we fail. */ -if (panic_force_buf) { -va_list ap; - -/* Do not consume args, the caller reuses it if we fail */ -va_copy (ap, args); -vsnprintf (panic_force_buf,PANIC_MSG_BUFSZ , fmt, ap); -va_end (ap); - msg = panic_force_buf; - }else { - msg ="Redirected panic (buffer unavailable)" ; - } +va_copy (ap, args); +vsnprintf (panic_force_buf,PANIC_MSG_BUFSZ , fmt, ap); +va_end (ap);console_verbose ();bust_spinlocks (1 );
@@ -441,7 +421,7 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)dump_stack (); } -if (panic_smp_redirect_cpu (panic_force_cpu, (void *)msg) !=0 ) { +if (panic_smp_redirect_cpu (panic_force_cpu, panic_force_buf) !=0 ) {atomic_set (&panic_redirect_cpu,PANIC_CPU_INVALID );pr_warn ("panic: failed to redirect to CPU %d, continuing on CPU %d\n" , panic_force_cpu, this_cpu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 737/1257 lib: decompress_bunzip2: fix integer overflow in run-length decoding
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
[ Upstream commit b822ad8d702df0be9fe3f24f71caeb0522d72319 ]
The RUNA/RUNB decoder in get_next_block() accumulates a run length into the signed int t with no bound. runPos doubles per symbol, so t grows as at least 2^n-1 and reaches INT_MAX after 31 RUNA symbols. The guard that follows, dbufCount+t >= dbufSize, is itself a signed addition, and as the kernel builds with -fno-strict-overflow it wraps negative once dbufCount is nonzero, so the guard is skipped. while (t--) dbuf[dbufCount++] = uc then writes INT_MAX entries into a buffer holding at most 900000. One literal symbol ahead of the run is enough to make dbufCount nonzero.
Bound t to the block size as it is accumulated. t only grows within a run, so the value tested never exceeds the final run length; any stream that decodes today satisfies dbufCount+t < dbufSize at the flush, hence t < dbufSize throughout, and no such stream is rejected. Because t grows as at least 2^n-1 the bound trips by the 20th symbol, leaving runPos at most 2^19, so the following runPos <<= 1 cannot overflow either.
--- lib/decompress_bunzip2.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/decompress_bunzip2.c +4 -0
@@ -428,6 +428,10 @@ static int INIT get_next_block(struct bunzip_data *bd) t += (runPos << nextSym);/* +runPos if RUNA; +2*runPos if RUNB */ +/* Bound the run so t and runPos cannot overflow. */ +if (t >= dbufSize) +return RETVAL_DATA_ERROR ; + runPos <<=1 ;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 738/1257 ocfs2: update xattr count before moving bucket entries
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Su Yue <[email protected]>
[ Upstream commit cd6920b6f3e5c6402d49e1128d0e53ee1c7c9b55 ]
Since commit 2f26f58df041 ("ocfs2: annotate flexible array members with __counted_by_le()"), the xh_entries array is annotated with __counted_by_le(xh_count), so FORTIFY uses xh_count to determine its bounds. When inserting an entry into a bucket, ocfs2_xa_bucket_add_entry() shifts existing entries before incrementing xh_count. The destination therefore extends one entry past the bounds described by the old count.
With CONFIG_CC_HAS_COUNTED_BY and CONFIG_FORTIFY_SOURCE enabled,
ocfs2-test: single_run-WIP.sh -t reflink triggers the following failure while adding an extended attribute:
[ 150.156484] memmove: detected buffer overflow: 352 byte write of buffer size 336 [ 150.156487] WARNING: lib/string_helpers.c:1036 at __fortify_report+0x3d/0x50, CPU#15: reflink_test/2336 [ 150.160496] RIP: 0010:__fortify_report+0x40/0x50 [ 150.164031] Call Trace: [ 150.164141] <TASK> [ 150.164232] __fortify_panic+0x9/0xb [ 150.164383] ocfs2_xa_bucket_add_entry.cold+0x17/0x28 [ocfs2] [ 150.164661] ocfs2_xa_set+0x8fb/0xf40 [ocfs2]
Increment xh_count before memmove() so the destination bounds include the new entry. Keep the local count unchanged to calculate the insertion position and move length from the original number of entries. The caller has already checked that there is enough space for the new entry.
--- fs/ocfs2/xattr.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +6 -1
@@ -2073,12 +2073,17 @@ static void ocfs2_xa_bucket_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) } } +/* +* Increment xh_count before memmove() so __counted_by_le(xh_count) +* includes the new entry in the destination bounds. +*/ +le16_add_cpu (&xh->xh_count,1 ); +if (low != count)memmove (&xh->xh_entries[low +1 ], &xh->xh_entries[low], ((count - low) *sizeof (struct ocfs2_xattr_entry ))); -le16_add_cpu (&xh->xh_count,1 ); loc->xl_entry = &xh->xh_entries[low];memset (loc->xl_entry,0 ,sizeof (struct ocfs2_xattr_entry )); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 739/1257 ocfs2: fix array out of bound access in __ocfs2_find_path()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giorgi Kobakhia <[email protected]>
[ Upstream commit 6193ce7896afb52a321a0063c8b6a45e477a84e2 ]
__ocfs2_find_path() walks down the extent tree and records path by calling find_path_ins(), which appends entry to path->p_node[]. It only has 5 spots.
A corrupted ocfs2 image whose extent block is pointing to itself causes __ocfs2_find_path() descent endlessly, writing past the end of path->p_node[] array.
UBSAN: array-index-out-of-bounds in fs/ocfs2/alloc.c:677:14 index 5 is out of range for type 'ocfs2_path_item [5]' Call Trace: <TASK> find_path_ins (fs/ocfs2/alloc.c:677 fs/ocfs2/alloc.c:1914) __ocfs2_find_path.constprop.0 (fs/ocfs2/alloc.c:1882) ocfs2_commit_truncate (fs/ocfs2/alloc.c:1924 fs/ocfs2/alloc.c:7286) ocfs2_truncate_file (fs/ocfs2/file.c:515) ocfs2_setattr (fs/ocfs2/file.c:1224) notify_change (fs/attr.c:556) do_truncate (fs/open.c:68) do_ftruncate (fs/open.c:194 (discriminator 1)) ksys_ftruncate (fs/open.c:206) __x64_sys_ftruncate (fs/open.c:211 fs/open.c:209 fs/open.c:209)
Commit a406aff8c051 ("ocfs2: validate l_tree_depth to avoid out-of-bounds access") already restricts el->l_tree_depth to be less than OCFS2_MAX_PATH_DEPTH, which is equal to 5. However, does not handle the infinite descent case.
Check if the el->l_tree_depth decreases on each descent. Maximum descents are restricted to 4 and the path->p_node[] array does not overflow.
--- fs/ocfs2/alloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/ocfs2/alloc.c +6 -3
@@ -1817,6 +1817,7 @@ static int __ocfs2_find_path(struct ocfs2_caching_info *ci,int i, ret =0 ;u32 range;u64 blkno; +u32 prev_depth =OCFS2_MAX_PATH_DEPTH ;struct buffer_head *bh =NULL ;struct ocfs2_extent_block *eb;struct ocfs2_extent_list *el;
@@ -1824,14 +1825,16 @@ static int __ocfs2_find_path(struct ocfs2_caching_info *ci, el = root_el;while (el->l_tree_depth) { -if (unlikely (le16_to_cpu (el->l_tree_depth) >=OCFS2_MAX_PATH_DEPTH )) { +if (unlikely (le16_to_cpu (el->l_tree_depth) >= prev_depth)) {ocfs2_error (ocfs2_metadata_cache_get_super (ci), -"Owner %llu has invalid tree depth %u in extent list\n" , +"Owner %llu has invalid tree depth %u in extent list (max %u)\n" , (unsigned long long )ocfs2_metadata_cache_owner (ci), -le16_to_cpu (el->l_tree_depth)); +le16_to_cpu (el->l_tree_depth), prev_depth -1 ); ret = -EROFS ; goto out; } + prev_depth =le16_to_cpu (el->l_tree_depth); +if (!el->l_next_free_rec || !el->l_count) {ocfs2_error (ocfs2_metadata_cache_get_super (ci), "Owner %llu has empty extent list at depth %u\n"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 740/1257 tmpfs: fix unicode_map leaks in casefold option handling
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kazuki Hanai <[email protected]>
[ Upstream commit f439d79e8cd19f89e04cbb3b532347edacd72c79 ]
shmem_parse_opt_casefold() stores the unicode_map returned by utf8_load() in ctx->encoding. A filesystem context can receive the casefold parameter more than once, and a second successful parse overwrites the stored map without releasing it.
The map is also leaked when an unmounted filesystem context is freed. This includes the temporary context used for remount, because shmem_reconfigure() does not take ownership of ctx->encoding.
Reject a second casefold setting, clear ctx->encoding after transferring ownership to the superblock, and release any remaining map from shmem_free_fc().
An unprivileged user can repeatedly create tmpfs filesystem contexts, set the casefold parameter, and close them from a user namespace. This causes unbounded kernel memory consumption and can result in a local denial of service.
--- mm/shmem.c | 7 +++++++ 1 file changed, 7 insertions(+)
mm/shmem.c +7 -0
@@ -4511,6 +4511,9 @@ static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *struct unicode_map *encoding;char *version_str = param->string +5 ; +if (ctx->encoding) +return invalfc (fc,"casefold parameter cannot be specified twice\n" ); +if (!latest_version) {if (strncmp (param->string,"utf8-" ,5 )) return invalfc(fc, "Only UTF-8 encodings are supported "
@@ -5000,6 +5003,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)if (ctx->encoding) { sb->s_encoding = ctx->encoding; + ctx->encoding =NULL ;set_default_d_op (sb, &shmem_ci_dentry_ops);if (ctx->strict_encoding) sb->s_encoding_flags =SB_ENC_STRICT_MODE_FL ;
@@ -5097,6 +5101,9 @@ static void shmem_free_fc(struct fs_context *fc)struct shmem_options *ctx = fc->fs_private;if (ctx) { +#if IS_ENABLED (CONFIG_UNICODE ) +utf8_unload (ctx->encoding); +#endif mpol_put (ctx->mpol);kfree (ctx); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 741/1257 ALSA: hda/tas2781: Assign total_sz at the end of the function
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gergo Koteles <[email protected]>
[ Upstream commit 35911ab70c41957b4a8ac972af137a8e5ccbe259 ]
In the tas2563_save_calibration() function, cd->total_sz is assigned in several error paths.
Move the assignment to the end of the function.
--- sound/hda/codecs/side-codecs/tas2781_hda_i2c.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
sound/hda/codecs/side-codecs/tas2781_hda_i2c.c +4 -10
@@ -335,10 +335,11 @@ static int tas2563_save_calibration(struct tas2781_hda *h) } cd->cali_dat_sz_per_dev =TAS2563_CAL_DATA_SIZE *TASDEV_CALIB_N ; + cd->total_sz =0 ;/* extra byte for each device is the device number */ - cd->total_sz = (cd->cali_dat_sz_per_dev +1 ) * p->ndev; - data = cd->data =devm_kzalloc (p->dev, cd->total_sz, + data = cd->data =devm_kzalloc (p->dev, + (cd->cali_dat_sz_per_dev +1 ) * p->ndev,GFP_KERNEL );if (!data)return -ENOMEM ;
@@ -352,7 +353,6 @@ static int tas2563_save_calibration(struct tas2781_hda *h)if (ret <0 || ret >=sizeof (var8) -1 ) {dev_err (p->dev,"%s: Read %s failed\n" , __func__, var8); - cd->total_sz =0 ;return -EINVAL ; }/*
@@ -370,7 +370,6 @@ static int tas2563_save_calibration(struct tas2781_hda *h)dev_warn (p->dev,"Dev %d: Caldat[%d] read failed %ld\n" , i, j, status); - cd->total_sz =0 ;return -EINVAL ; } bedata =cpu_to_be32 (*(uint32_t *)&data[offset]);
@@ -379,12 +378,7 @@ static int tas2563_save_calibration(struct tas2781_hda *h) } } -if (cd->total_sz != offset) { -dev_err (p->dev,"%s: tot_size(%lu) and offset(%u) mismatch\n" , - __func__, cd->total_sz, offset); - cd->total_sz =0 ; -return -EINVAL ; - } + cd->total_sz = offset; r->r0_reg =TAS2563_CAL_R0 ; r->invr0_reg =TAS2563_CAL_INVR0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 742/1257 ALSA: hda/tas2781: Skip invalid TAS2563 UEFI calibration data
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gergo Koteles <[email protected]>
[ Upstream commit a0f0325e92e505db6a6879d79da5aa88e94a36ab ]
Some Lenovo 14ARB7 laptops do not have proper calibration data.
Skip these zero calibration values and fall back to the calibration data provided by the DSP firmware.
--- sound/hda/codecs/side-codecs/tas2781_hda_i2c.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/hda/codecs/side-codecs/tas2781_hda_i2c.c +5 -0
@@ -372,6 +372,11 @@ static int tas2563_save_calibration(struct tas2781_hda *h) i, j, status);return -EINVAL ; } +if (*(uint32_t *)&data[offset] ==0 ) { +dev_warn (p->dev, +"Dev %d: Caldat[%d] is zero\n" , i, j); +return -EINVAL ; + } bedata =cpu_to_be32 (*(uint32_t *)&data[offset]);memcpy (&data[offset], &bedata,sizeof (bedata)); offset +=TAS2563_CAL_DATA_SIZE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 743/1257 ALSA: hda/realtek: keep headset mic on Acer SSID 0x1640
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
[ Upstream commit b23012149ca8e7a9c7c72e93b7639ca2a282d6b1 ]
The micmute-LED quirk for the Aspire A315-44P matches PCI SSID 1025:1640 before the Acer ALC256 pin fallback. The Aspire Go 15 AG15-42P shares that SSID and leaves nid 0x19 as 0x411111f0, so selecting the LED-only fixup drops the headset-mic pin remap that the fallback would have applied.
Chain ALC2XX_FIXUP_HEADSET_MIC before the GPIO3 micmute LED on that SSID. Leave the Swift SFG16 entry (0x169a) unchanged.
Tested on Acer Aspire AG15-42P (Callisto_BCU): PCI pick 1025:1640, Headset Mic=0x19, GPIO3 enabled with no physical micmute LED, speaker and capture paths functional.
--- sound/hda/codecs/realtek/alc269.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
sound/hda/codecs/realtek/alc269.c +15 -1
@@ -4344,6 +4344,7 @@ enum {ALC2XX_FIXUP_HEADSET_MIC ,ALC289_FIXUP_DELL_CS35L41_SPI_2 ,ALC256_FIXUP_ACER_SFG16_MICMUTE_LED , +ALC256_FIXUP_ACER_HEADSET_MICMUTE_LED ,ALC256_FIXUP_HEADPHONE_AMP_VOL ,ALC245_FIXUP_HP_SPECTRE_X360_EU0XXX , ALC245_FIXUP_HP_SPECTRE_X360_16_AA0XXX,
@@ -6934,6 +6935,13 @@ static const struct hda_fixup alc269_fixups[] = { .type = HDA_FIXUP_FUNC, .v.func = alc256_fixup_acer_sfg16_micmute_led, }, + [ALC256_FIXUP_ACER_HEADSET_MICMUTE_LED] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc256_fixup_acer_sfg16_micmute_led, + .chained = true, + .chained_before = true, + .chain_id = ALC2XX_FIXUP_HEADSET_MIC, + }, [ALC256_FIXUP_HEADPHONE_AMP_VOL] = { .type = HDA_FIXUP_FUNC, .v.func = alc256_decrease_headphone_amp_val,
@@ -7264,7 +7272,13 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1025 ,0x160e ,"Acer PT316-51S" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1025 ,0x1616 ,"Acer Aspire A515-57" ,ALC256_FIXUP_ACER_COLDBOOT ),SND_PCI_QUIRK (0x1025 ,0x161f ,"Acer S40-54" ,ALC256_FIXUP_ACER_MIC_NO_PRESENCE ), -SND_PCI_QUIRK (0x1025 ,0x1640 ,"Acer Aspire A315-44P" ,ALC256_FIXUP_ACER_SFG16_MICMUTE_LED ), +/* +* Shared SSID: A315-44P needs GPIO3 micmute LED; AG15-42P needs +* the headset pin remap (BIOS leaves 0x19 as 0x411111f0). One +* entry applies both. GPIO3 is unused on AG15. +*/ +SND_PCI_QUIRK (0x1025 ,0x1640 ,"Acer Aspire A315-44P / AG15-42P" , +ALC256_FIXUP_ACER_HEADSET_MICMUTE_LED ),SND_PCI_QUIRK (0x1025 ,0x166c ,"Acer Predator PH16-71" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1025 ,0x1679 ,"Acer Nitro 16 AN16-41" ,ALC2XX_FIXUP_HEADSET_MIC ), SND_PCI_QUIRK(0x1025, 0x169a, "Acer Swift SFG16", ALC256_FIXUP_ACER_SFG16_MICMUTE_LED),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 744/1257 PCI: imx6: Avoid dereferencing a NULL clock name
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rudi Heitbaum <[email protected]>
[ Upstream commit e60d0d4dfddfac3058753a1c2255251401c92dad ]
of_clk_bulk_get() leaves 'clk_bulk_data->id' as NULL for every clock that has no matching entry in "clock-names", which is legal: a node may list more "clocks" phandles than it names. Both scans of the bulk array dereference that id unconditionally, so such a node oopses during probe.
The loop in imx_pcie_probe() has been wrong since it was written. The loop in imx_setup_phy_mpll() was not: it read a fixed clks[] whose ids came from the driver's own clk_names[] and were never NULL, and only became wrong when the driver moved to the bulk array.
Check 'clk_bulk_data->id' before dereferencing it in both.
--- drivers/pci/controller/dwc/pci-imx6.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +3 -2
@@ -542,7 +542,7 @@ static int imx_setup_phy_mpll(struct imx_pcie *imx_pcie)return 0 ;for (i =0 ; i < imx_pcie->num_clks; i++) -if (strncmp (clks[i].id,"pcie_phy" ,8 ) ==0 ) +if (clks[i].id &&strncmp (clks[i].id,"pcie_phy" ,8 ) ==0 ) phy_rate =clk_get_rate (clks[i].clk);switch (phy_rate) {
@@ -1836,7 +1836,8 @@ static int imx_pcie_probe(struct platform_device *pdev)return dev_err_probe (dev, imx_pcie->num_clks,"failed to get clocks\n" );for (i =0 ; i < imx_pcie->num_clks; i++) -if (strncmp (imx_pcie->clks[i].id,"extref" ,6 ) ==0 ) +if (imx_pcie->clks[i].id && +strncmp (imx_pcie->clks[i].id,"extref" ,6 ) ==0 ) imx_pcie->enable_ext_refclk = true;if (imx_check_flag (imx_pcie,IMX_PCIE_FLAG_HAS_PHYDRV )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 745/1257 platform/x86/tuxedo: Fix keyboard LED map ordering
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aaron Erhardt <[email protected]>
[ Upstream commit 5c9c54dfa28c9a47c9d81322d16585f9a64d4c69 ]
The LED mappings in sirius_16_[iso|ansii]_kbl_map did contain a flipped line that caused LEDs to turn on in the wrong order when counting up the Lamp ID.
--- drivers/platform/x86/tuxedo/nb04/wmi_ab.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/platform/x86/tuxedo/nb04/wmi_ab.c +4 -4
@@ -232,8 +232,8 @@ static const struct tux_kbl_map_entry_t sirius_16_ansii_kbl_map[] = { { 0x2e, { 246000, 67500, 5250 } }, { 0x2a, { 269500, 67500, 5250 } }, { 0x53, { 294500, 67500, 5250 } }, - { 0x55, { 311200, 67500, 5250 } }, - { 0x54, { 327900, 67500, 5250 } }, + { 0x54, { 311200, 67500, 5250 } }, + { 0x55, { 327900, 67500, 5250 } }, { 0x56, { 344600, 67500, 5250 } }, { 0x2b, { 31000, 85500, 5500 } }, { 0x14, { 51500, 85500, 5500 } },
@@ -337,8 +337,8 @@ static const struct tux_kbl_map_entry_t sirius_16_iso_kbl_map[] = { { 0x2e, { 246000, 67500, 5250 } }, { 0x2a, { 269500, 67500, 5250 } }, { 0x53, { 294500, 67500, 5250 } }, - { 0x55, { 311200, 67500, 5250 } }, - { 0x54, { 327900, 67500, 5250 } }, + { 0x54, { 311200, 67500, 5250 } }, + { 0x55, { 327900, 67500, 5250 } }, { 0x56, { 344600, 67500, 5250 } }, { 0x2b, { 31000, 85500, 5500 } }, { 0x14, { 51500, 85500, 5500 } },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 746/1257 ALSA: cs46xx: fix unit mismatch in DSP code area bounds check
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis Arefev <[email protected]>
[ Upstream commit fd65108f5001ffb416dc9bd37ec1893f55cff24a ]
ins->code.offset and code->size are measured in 32-bit words, while DSP_CODE_BYTE_SIZE is the size of the DSP code area in bytes. The check ins->code.offset + code->size > DSP_CODE_BYTE_SIZE in cs46xx_dsp_load_module() therefore allowed up to four times more code than the code area can hold.
The shadow buffer ins->code.data is allocated with kmalloc(DSP_CODE_BYTE_SIZE), i.e. it holds DSP_CODE_BYTE_SIZE/4 words. A firmware file with a code segment larger than DSP_CODE_BYTE_SIZE/4 words (28 KiB) passed the check and caused an out-of-bounds write in shadow_and_reallocate_code() and an out-of-bounds read in snd_cs46xx_download().
Compare the sum in words against DSP_CODE_BYTE_SIZE/4 and cast it to u64 so that the sum cannot wrap for large code->size values.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- sound/pci/cs46xx/dsp_spos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/cs46xx/dsp_spos.c +1 -1
@@ -393,7 +393,7 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * mdev_dbg (chip->card->dev,"dsp_spos: module got no code segment\n" ); }else { -if (ins->code.offset + code->size >DSP_CODE_BYTE_SIZE ) { +if ((u64 )ins->code.offset + code->size >DSP_CODE_BYTE_SIZE /4 ) {dev_err (chip->card->dev,"dsp_spos: no space available in DSP\n" );return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 747/1257 platform/x86: hp-bioscfg: fix OOB reads in hp_get_string_from_buffer()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit 176b38b84ae5e075850b3ebb25f906d66f95a46d ]
The escape prescan loop uses 'size' as both its bound and its accumulator, so each escape character found extends the loop and reads past the end of src[].
Use the original u16 count as the loop bound. Also include the 2-byte length prefix in the bounds check, pass the u16 count instead of the byte count to utf16s_to_utf8s(), and advance the buffer by the bytes actually consumed instead of the escape-inflated count.
Tested on HP EliteBook 840 G2 (Fedora 44, Linux 7.2.7).
--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +15 -11
@@ -54,8 +54,8 @@ int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer)int hp_get_string_from_buffer (u8 **buffer,u32 *buffer_size,char *dst,u32 dst_size) {u16 *src = (u16 *)*buffer; +u16 orig_size;u16 src_size; -u16 size;int i;int conv_dst_size;
@@ -63,17 +63,21 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_if (*buffer_size <sizeof (u16))return -EINVAL ; - src_size = *(src++); -/* size value in u16 chars */ - size = src_size /sizeof (u16); + src_size = *src; -/* Ensure there is enough space remaining to read and convert -* the string +/* +* Ensure there is enough space remaining for the length prefix +* just read plus the string data it describes. */ -if (*buffer_size < src_size) +if (*buffer_size <sizeof (u16) + src_size)return -EINVAL ; -for (i =0 ; i < size; i++) + src++; +/* size value in u16 chars */ + orig_size = src_size /sizeof (u16); + size = orig_size; + +for (i =0 ; i < orig_size; i++) if (src[i] == '\\' || src[i] == '\r' || src[i] == '\n' ||
@@ -91,7 +95,7 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_/* * convert from UTF-16 unicode to ASCII */ -utf16s_to_utf8s (src, src_size,UTF16_HOST_ENDIAN , dst, conv_dst_size); +utf16s_to_utf8s (src, orig_size,UTF16_HOST_ENDIAN , dst, conv_dst_size); dst[conv_dst_size] =0 ;for (i =0 ; i < conv_dst_size; i++) {
@@ -117,8 +121,8 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ src++; } - *buffer = (u8 *)src; - *buffer_size -= size *sizeof (u16); + *buffer +=sizeof (u16) + src_size; + *buffer_size -=sizeof (u16) + src_size;return size; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 748/1257 platform/x86: hp-bioscfg: fix non-ASCII truncation in hp_get_string_from_buffer()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit 6b8d2374b32c35efa2a431b3cd2fe346f8917dcc ]
utf16s_to_utf8s() writes into dst, but the loop that follows overwrites dst from the raw UTF-16 code units with truncating casts, so any character above U+007F is mangled. For example, U+00E9 is stored as 0xe9 instead of 0xc3 0xa9.
Convert into a scratch buffer first, then escape '\\', '\r', '\n' and '\t' into dst with string_escape_mem(). Quotes are not escaped, so the existing strreplace() still handles them.
Tested on HP EliteBook 840 G2 (Fedora 44, Linux 7.2.7).
--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 62 +++++--------------- 1 file changed, 14 insertions(+), 48 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +14 -48
@@ -11,7 +11,7 @@#include <linux/module.h> #include <linux/kernel.h> #include <linux/printk.h> -#include <linux/string.h> +#include <linux/string_helpers.h> #include <linux/wmi.h> #include "bioscfg.h" #include "../../firmware_attributes_class.h"
@@ -53,12 +53,12 @@ int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer)int hp_get_string_from_buffer (u8 **buffer,u32 *buffer_size,char *dst,u32 dst_size) { +char utf8_buf[MAX_BUFF_SIZE ];u16 *src = (u16 *)*buffer; +int escaped_len;u16 orig_size;u16 src_size; -u16 size; -int i; -int conv_dst_size; +int utf8_len;if (*buffer_size <sizeof (u16))return -EINVAL ;
@@ -75,56 +75,22 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_ src++;/* size value in u16 chars */ orig_size = src_size /sizeof (u16); - size = orig_size; - -for (i =0 ; i < orig_size; i++) -if (src[i] =='\\' || - src[i] =='\r' || - src[i] =='\n' || - src[i] =='\t' ) - size++; -/* -* Conversion is limited to destination string max number of -* bytes. -*/ - conv_dst_size = size; -if (size >= dst_size) - conv_dst_size = dst_size -1 ; + utf8_len =utf16s_to_utf8s (src, orig_size,UTF16_HOST_ENDIAN , + utf8_buf,sizeof (utf8_buf)); -/* -* convert from UTF-16 unicode to ASCII -*/ -utf16s_to_utf8s (src, orig_size,UTF16_HOST_ENDIAN , dst, conv_dst_size); - dst[conv_dst_size] =0 ; - -for (i =0 ; i < conv_dst_size; i++) { -if (*src =='\\' || - *src =='\r' || - *src =='\n' || - *src =='\t' ) { - dst[i++] ='\\' ; -if (i == conv_dst_size) -break ; - } - -if (*src =='\r' ) - dst[i] ='r' ; -else if (*src =='\n' ) - dst[i] ='n' ; -else if (*src =='\t' ) - dst[i] ='t' ; -else if (*src =='"' ) - dst[i] ='\'' ; -else - dst[i] = *src; - src++; - } + escaped_len =string_escape_mem (utf8_buf, utf8_len, dst, dst_size -1 , +ESCAPE_SPACE |ESCAPE_SPECIAL , +"\\\r\n\t" ); +if (escaped_len > dst_size -1 ) + escaped_len = dst_size -1 ; + dst[escaped_len] ='\0' ; +strreplace (dst,'"' ,'\'' ); *buffer +=sizeof (u16) + src_size; *buffer_size -=sizeof (u16) + src_size; -return size; +return escaped_len; } int hp_get_common_data_from_buffer(u8 **buffer_ptr, u32 *buffer_size,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 749/1257 platform/x86: hp-bioscfg: return -E2BIG from validate_password_input()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit a4f19c589b21e18567d3c0ac7b9294f81e29b1de ]
validate_password_input() returns the positive INVALID_BIOS_AUTH on rejection. store_password_instance() skips the store on nonzero ret, but its final "return ret < 0 ? ret : count" treats the positive value as success, so userspace sees count instead of an error.
Return -E2BIG for an invalid password length.
Tested on HP EliteBook 840 G2 (Fedora 44, Linux 7.2.7): writing 999 bytes to current_password returned 999 before this change.
--- drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c +4 -3
@@ -70,12 +70,13 @@ static int validate_password_input(int instance_id, const char *buf) length--;if (length >MAX_PASSWD_SIZE ) -return INVALID_BIOS_AUTH ; +return -E2BIG ;if (password_data->min_password_length > length || password_data->max_password_length < length) -return INVALID_BIOS_AUTH ; -return SUCCESS ; +return -E2BIG ; + +return 0 ; }ATTRIBUTE_N_PROPERTY_SHOW (is_enabled, password);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 750/1257 platform/x86: hp-bioscfg: allow clearing current_password
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit acada379d5c4dd3a86d48fc69802e769eff29f7e ]
The ABI documents echo "" > current_password as the way to end a session, but validate_password_input() rejects an empty string when min_password_length is nonzero, so the password stays cached.
Skip the length check for an empty current_password so the write clears it.
Compile tested only.
--- .../platform/x86/hp/hp-bioscfg/passwdobj-attributes.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c +7 -2
@@ -60,7 +60,8 @@ int hp_get_password_instance_for_type(const char *name)return -EINVAL ; } -static int validate_password_input (int instance_id,const char *buf) +static int validate_password_input (int instance_id,const char *buf, +bool is_current) {int length;struct password_data *password_data = &bioscfg_drv.password_data[instance_id];
@@ -69,6 +70,10 @@ static int validate_password_input(int instance_id, const char *buf)if (length >0 && buf[length -1 ] =='\n' ) length--; +/* An empty current_password clears the session password */ +if (is_current && !length) +return 0 ; +if (length >MAX_PASSWD_SIZE )return -E2BIG ;
@@ -97,7 +102,7 @@ static int store_password_instance(struct kobject *kobj, const char *buf, id =get_password_instance_id (kobj);if (id >=0 ) - ret =validate_password_input (id, buf_cp); + ret =validate_password_input (id, buf_cp, is_current); }if (!ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 751/1257 platform/x86: hp-bioscfg: NUL-terminate the SPM auth token
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
[ Upstream commit f2769668959f6411ac69e83080a240f8a8785e05 ]
auth_token_store() copies the token with kmemdup(), which does not NUL terminate it, but hp_calculate_security_buffer() and hp_populate_security_buffer() use it as a C string and read past the allocation.
A lone newline (echo > auth_token) is worse: kmemdup() of 0 bytes returns ZERO_SIZE_PTR, which passes the NULL checks, so a later attribute write passes it to strlen().
A userspace replica of the two helpers under ASan reports a heap buffer overflow in hp_calculate_security_buffer() for the unterminated token and a fault at address 0x10 for the lone newline, and is clean with this change.
The token is a string, so copy it with kstrndup(), which always NUL terminates and allocates at least one byte.
--- drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +1 -1
@@ -307,7 +307,7 @@ static ssize_t auth_token_store(struct kobject *kobj, length--;/* allocate space and copy current auth token */ - bioscfg_drv.spm_data.auth_token =kmemdup (buf, length,GFP_KERNEL ); + bioscfg_drv.spm_data.auth_token =kstrndup (buf, length,GFP_KERNEL );if (!bioscfg_drv.spm_data.auth_token) { ret = -ENOMEM ; goto exit_token;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 752/1257 serial: 8250_lpss: do not touch uninitialized line in ehl_serial_exit()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 3e3ae95a3d84a6028f37a07ab7ad78bb14689f2e ]
lpss8250_probe() calls lpss->board->exit() on its error path. For the EHL board, that is ehl_serial_exit() and it does:
serial8250_get_port(lpss->data.line)->dma = NULL;
But when lpss8250_dma_setup() or serial8250_register_8250_port() fails, lpss->data.line was never assigned. As lpss is kzalloc()ed, line is 0 and ehl_serial_exit() clears the dma pointer of an unrelated port -- serial8250_ports[0], i.e. ttyS0, which is often the console.
Initialize lpss->data.line to -1 in probe and skip the clearing in ehl_serial_exit() if no port was registered.
--- drivers/tty/serial/8250/8250_lpss.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_lpss.c +4 -3
@@ -183,9 +183,8 @@ static int ehl_serial_setup(struct lpss8250 *lpss, struct uart_port *port)static void ehl_serial_exit (struct lpss8250 *lpss) { -struct uart_8250_port *up =serial8250_get_port (lpss->data.line); - - up->dma =NULL ; +if (lpss->data.line >=0 ) +serial8250_get_port (lpss->data.line)->dma =NULL ; }#ifdef CONFIG_SERIAL_8250_DMA
@@ -329,6 +328,8 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)return ret; lpss->board = (struct lpss8250_board *)id->driver_data; +/* for tests in lpss->board->exit() */ + lpss->data.line =-1 ;memset (&uart,0 ,sizeof (struct uart_8250_port ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 753/1257 serial: 8250_omap: set priv->line before enabling the IRQ
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 8276a44f0a0b68c07b2331cc0058036ac4c4190d ]
omap8250_irq() is requested in omap8250_probe() with IRQ_NOAUTOEN and enabled only in omap_8250_startup(). The handler obtains the port by serial8250_get_port(priv->line), but probe stores priv->line only after serial8250_register_8250_port() returns.
The port becomes visible to userspace already inside serial8250_register_8250_port() (uart_add_one_port()). So it can be opened -- and the IRQ enabled -- before probe stores the line. An interrupt in that window makes the handler call serial8250_get_port(-ENODEV) and dereference a pointer outside of serial8250_ports[].
Store the line in omap_8250_startup() before enable_irq(), so the handler never runs with an unset line. Keep the assignment in probe too, as remove and the system PM callbacks rely on it even when the port was never opened.
--- drivers/tty/serial/8250/8250_omap.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/tty/serial/8250/8250_omap.c +3 -0
@@ -711,6 +711,9 @@ static int omap_8250_startup(struct uart_port *port)struct uart_8250_dma *dma = &priv->omap8250_dma;int ret; +/* ISR and runtime PM need the line; probe sets it only after registration */ + priv->line = port->line; +#ifdef CONFIG_PM up->capabilities |=UART_CAP_RPM ;#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 754/1257 Revert "serial: 8250_port: Drop duplicate NULL check"
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ferry Toth <[email protected]>
[ Upstream commit 6ae994d513a6ace5462137e1025a4e7086b87348 ]
This reverts commit 7885af04df6e4efd72910200c1bfc079d61202e4.
Commit 7885af04df6e ("serial: 8250_port: Drop duplicate NULL check") added up->dma = NULL; to serial8250_release_dma(), with the stated intent of making sure DMA would not be used again after release.
However, up->dma is assigned once at probe time. serial8250_do_startup() only calls serial8250_request_dma() when up->dma is non-NULL, so after the first close the pointer stays NULL and DMA is never re-acquired.
On Intel Tangier (Edison) with HSU DMA this causes a regression: the first port open uses TX DMA, the second and later opens transmit in PIO mode, producing 64-byte FIFO bursts with ~50us gaps between them.
--- drivers/tty/serial/8250/8250_port.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_port.c +2 -2
@@ -2428,8 +2428,8 @@ void serial8250_do_shutdown(struct uart_port *port)synchronize_irq (port->irq); -serial8250_release_dma (up); - up->dma =NULL ; +if (up->dma) +serial8250_release_dma (up); scoped_guard(uart_port_lock_irqsave, port) {if (port->flags &UPF_FOURPORT ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 755/1257 serial: amba-pl011: honour delay_rts_before_send for every write
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 8a9750209596be35d109de5aa89623b049855c67 ]
While the driver waits out delay_rts_before_send, another write calls pl011_start_tx() again. pl011_rs485_tx_start() then switches straight to SEND, and the data goes out before the delay has passed.
Leave the start to the trigger_start_tx timer while it is pending.
--- drivers/tty/serial/amba-pl011.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/tty/serial/amba-pl011.c +7 -5
@@ -1420,10 +1420,6 @@ static void pl011_rs485_tx_start(struct uart_amba_port *uap)struct uart_port *port = &uap->port;u32 cr; -if (uap->rs485_tx_state ==WAIT_AFTER_RTS ) { - uap->rs485_tx_state =SEND ; -return ; - }if (uap->rs485_tx_state ==WAIT_AFTER_SEND || uap->rs485_tx_state ==WAIT_AFTER_SEND_DELAY ) {hrtimer_try_to_cancel (&uap->trigger_stop_tx);
@@ -1462,6 +1458,10 @@ static void pl011_start_tx(struct uart_port *port)if ((uap->port.rs485.flags &SER_RS485_ENABLED ) && uap->rs485_tx_state !=SEND ) { +/* trigger_start_tx starts TX once delay_rts_before_send passed */ +if (uap->rs485_tx_state ==WAIT_AFTER_RTS ) +return ; +pl011_rs485_tx_start (uap);if (uap->rs485_tx_state ==WAIT_AFTER_RTS )return ;
@@ -1478,8 +1478,10 @@ static enum hrtimer_restart pl011_trigger_start_tx(struct hrtimer *t)unsigned long flags;uart_port_lock_irqsave (&uap->port, &flags); -if (uap->rs485_tx_state ==WAIT_AFTER_RTS ) +if (uap->rs485_tx_state ==WAIT_AFTER_RTS ) { + uap->rs485_tx_state =SEND ;pl011_start_tx (&uap->port); + }uart_port_unlock_irqrestore (&uap->port, flags);return HRTIMER_NORESTART ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 756/1257 serial: amba-pl011: keep transmitter enabled when disabling RS485
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 97f85204275ae4d7fb530e451f3acc65c1ec1155 ]
Disabling RS485 on an open port calls pl011_rs485_tx_stop(), which turns off the transmitter. Only the RS485 TX path turns it back on, so any later output stays queued and tcdrain() hangs until the port is closed.
pl011_rs485_tx_stop() also checks only the hardware FIFO. If a DMA transfer has started but has not filled the FIFO yet, the transmitter is turned off under the transfer and the DMA channel never recovers.
When leaving RS485 mode, cancel pending deferred starts and stops, leave the transmitter enabled and start any TX that was still waiting for delay_rts_before_send.
--- drivers/tty/serial/amba-pl011.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/tty/serial/amba-pl011.c +24 -1
@@ -2399,8 +2399,31 @@ static int pl011_rs485_config(struct uart_port *port, struct ktermios *termios,struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port); -if (port->rs485.flags &SER_RS485_ENABLED ) +if ((port->rs485.flags &SER_RS485_ENABLED ) && + !(rs485->flags &SER_RS485_ENABLED )) { +bool tx_pending = uap->rs485_tx_state ==WAIT_AFTER_RTS ; +u32 cr =pl011_read (uap,REG_CR ); + +/* +* Leaving RS485 mode, which only enables the transmitter while +* sending. Don't stop it, as that stalls a DMA transfer still +* in flight. Drop pending deferred starts and stops and keep +* it enabled. +*/ +hrtimer_try_to_cancel (&uap->trigger_start_tx); +hrtimer_try_to_cancel (&uap->trigger_stop_tx); + uap->rs485_tx_state =OFF ; + + cr |=UART011_CR_TXE |UART011_CR_RXE ; +pl011_write (cr, uap,REG_CR ); + +/* Start TX that was still waiting for delay_rts_before_send */ +if (tx_pending && !uart_tx_stopped (port) && + !pl011_dma_tx_start (uap)) +pl011_start_tx_pio (uap); + }else if (port->rs485.flags &SER_RS485_ENABLED ) {pl011_rs485_tx_stop (uap); + }/* Make sure auto RTS is disabled */ if (rs485->flags &SER_RS485_ENABLED ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 757/1257 serial: pmac_zilog: push received data to the port that received it
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tim Douglas <[email protected]>
[ Upstream commit f3dc727da3af64abc12b625bbf1eb68d55d882cc ]
pmz_interrupt() drains both channels but, since commit 2e124b4a390c ("TTY: switch tty_flip_buffer_push"), pushes the flip buffer of the port whose handler is running rather than the port that was drained. With both ports open, data received on the other port can be left in its flip buffer until something else pushes it, so its reader may not see it.
--- drivers/tty/serial/pmac_zilog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/pmac_zilog.c +2 -2
@@ -444,7 +444,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id) skip_a:uart_port_unlock (&uap_a->port);if (push) -tty_flip_buffer_push (&uap->port.state->port); +tty_flip_buffer_push (&uap_a->port.state->port);if (!uap_b) goto out;
@@ -469,7 +469,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id) skip_b:uart_port_unlock (&uap_b->port);if (push) -tty_flip_buffer_push (&uap->port.state->port); +tty_flip_buffer_push (&uap_b->port.state->port); out:return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 758/1257 iommu/amd: Program device table when kdump reuse fails
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Fleming <[email protected]>
[ Upstream commit 05d62be400f3ae0f6856f6910a1281e67cbaabcf ]
Commit 38e5f33ee359 ("iommu/amd: Reuse device table for kdump") made iommu_set_device_table() return early in every kdump kernel. That is needed when the previous kernel's device table is reused: the base register already points at it, and on SNP-enabled systems the register is locked.
But if reuse isn't possible, early_enable_iommus() falls back to the freshly allocated table and calls early_enable_iommu(). Because of the early return, that table is never written to the base register. The IOMMU keeps using whatever table the register pointed at before, while the driver writes entries into the new one.
Only skip the write when the previous kernel's table was reused.
--- drivers/iommu/amd/init.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iommu/amd/init.c +7 -1
@@ -390,7 +390,13 @@ static void iommu_set_device_table(struct amd_iommu *iommu)BUG_ON (iommu->mmio_base ==NULL ); -if (is_kdump_kernel ()) +/* +* A kdump kernel that reuses the previous kernel's device table must +* leave the base register alone. It already points at that table, and +* with SNP enabled the register is locked. If reuse failed, program +* the freshly allocated table like a normal boot. +*/ +if (iommu->pci_seg->old_dev_tbl_cpy)return ; entry =iommu_virt_to_phys (dev_table);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 759/1257 iommu/amd: Dont allocate kdump device table from DMA32
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Fleming <[email protected]>
[ Upstream commit bae0d3760661ac77148944e88aafef698cf7b2bf ]
Booting a kdump kernel with crashkernel=X,high crashkernel=0,low on an AMD system fails the per-segment device table allocation because there is no memory below 4G:
swapper/0: page allocation failure: order:9, mode:0x40104(GFP_DMA32|__GFP_ZERO|__GFP_COMP)
iommu_alloc_pages_node_sz+0x7f/0x150 alloc_pci_segment+0x4bd/0x650 iommu_go_to_state+0x213d/0x34e0 amd_iommu_prepare+0x39/0xa0 irq_remapping_prepare+0x83/0xd0 enable_IR_x2apic+0x61/0x370
On our E810 systems, the kdump kernel booted but ice MSI-X interrupts never fired and the TX queues timed out.
Commit b336781b82cc ("iommu/amd: Allocate memory below 4G for dev table if translation pre-enabled") allocated device tables below 4G. At the time, the kdump kernel programmed a copy of the old table into the base register with the IOMMU still enabled. The 64-bit register is updated as two 32-bit halves, so the running IOMMU could see a half-written, invalid table pointer. Keeping both tables below 4G leaves the upper half zero throughout the update, so the pointer stays valid.
Since commit 38e5f33ee359 ("iommu/amd: Reuse device table for kdump") the kdump kernel reuses the previous kernel's table without writing the base register, so its newly allocated table is discarded when reuse succeeds. If reuse fails, the previous patch programs the new table only after disabling the IOMMU. Either way, the kdump kernel's table doesn't need to be below 4G.
The previous kernel still allocates its table from DMA32, so the kdump kernel's check that the old table is below 4G still works. Drop GFP_DMA32 for kdump kernels only.
--- drivers/iommu/amd/init.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/iommu/amd/init.c +13 -2
@@ -629,8 +629,19 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table, u16 pci_/* Allocate per PCI segment device table */ static inline int __init alloc_dev_table (struct amd_iommu_pci_seg *pci_seg) { - pci_seg->dev_table =iommu_alloc_pages_sz (GFP_KERNEL |GFP_DMA32 , - pci_seg->dev_table_size); +gfp_t gfp =GFP_KERNEL ; + +/* +* Keep normal kernel device tables below 4G because a later kdump +* kernel only trusts and reuses old tables below that limit. A kdump +* kernel's new table is either discarded when reuse succeeds or +* programmed after the IOMMU is disabled, so the table does not +* need DMA32 memory (which the crashkernel may not have). +*/ +if (!is_kdump_kernel ()) + gfp |=GFP_DMA32 ; + + pci_seg->dev_table =iommu_alloc_pages_sz (gfp, pci_seg->dev_table_size);if (!pci_seg->dev_table)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 760/1257 nvme: make the DH-HMAC-CHAP secret attributes readable by root only
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Belanger <[email protected]>
[ Upstream commit bbca7c312ab25efd0024eb87545c51a76ab2ea39 ]
The dhchap_secret and dhchap_ctrl_secret sysfs attributes have mode 0644. Their show functions return the secret, so any local user can read the DH-HMAC-CHAP secrets of a connected controller.
Define them with DEVICE_ATTR_ADMIN_RW(), which sets mode 0600. The macro takes the show and store functions from the attribute name, so rename them. Writing the attributes was already limited to root and is not changed.
--- drivers/nvme/host/sysfs.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/nvme/host/sysfs.c +6 -8
@@ -809,7 +809,7 @@ static DEVICE_ATTR(io_timeout, S_IRUGO | S_IWUSR, nvme_io_timeout_show, nvme_io_timeout_store);#ifdef CONFIG_NVME_HOST_AUTH -static ssize_t nvme_ctrl_dhchap_secret_show (struct device *dev, +static ssize_t dhchap_secret_show (struct device *dev,struct device_attribute *attr,char *buf) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -820,7 +820,7 @@ static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,return sysfs_emit (buf,"%s\n" , opts->dhchap_secret); } -static ssize_t nvme_ctrl_dhchap_secret_store (struct device *dev, +static ssize_t dhchap_secret_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -864,10 +864,9 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,return count; } -static DEVICE_ATTR(dhchap_secret, S_IRUGO | S_IWUSR, - nvme_ctrl_dhchap_secret_show, nvme_ctrl_dhchap_secret_store); +static DEVICE_ATTR_ADMIN_RW (dhchap_secret); -static ssize_t nvme_ctrl_dhchap_ctrl_secret_show (struct device *dev, +static ssize_t dhchap_ctrl_secret_show (struct device *dev,struct device_attribute *attr,char *buf) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -878,7 +877,7 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_show(struct device *dev,return sysfs_emit (buf,"%s\n" , opts->dhchap_ctrl_secret); } -static ssize_t nvme_ctrl_dhchap_ctrl_secret_store (struct device *dev, +static ssize_t dhchap_ctrl_secret_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev);
@@ -922,8 +921,7 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,return count; } -static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR, - nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store); +static DEVICE_ATTR_ADMIN_RW (dhchap_ctrl_secret);#endif static struct attribute *nvme_dev_attrs[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 761/1257 mfd: ab8500: Fix child device leaks on probe failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 5bf2ae8b131d4ae9c0ed5f7aa02532645f512022 ]
ab8500_probe() registers MFD child devices before completing the remaining device initialization. If a later MFD registration or sysfs group creation fails, previously registered child devices are not removed.
Use devm_mfd_add_devices() so registered MFD child devices are removed when probe fails.
The issue was identified by a static analysis tool I developed and confirmed by manual review.
--- drivers/mfd/ab8500-core.c | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-)
drivers/mfd/ab8500-core.c +23 -21
@@ -1194,39 +1194,41 @@ static int ab8500_probe(struct platform_device *pdev)return ret;if (is_ab9540 (ab8500)) - ret =mfd_add_devices (ab8500->dev,0 , ab9540_devs, -ARRAY_SIZE (ab9540_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab9540_devs, +ARRAY_SIZE (ab9540_devs),NULL , +0 , ab8500->domain);else if (is_ab8540 (ab8500)) { - ret =mfd_add_devices (ab8500->dev,0 , ab8540_devs, -ARRAY_SIZE (ab8540_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8540_devs, +ARRAY_SIZE (ab8540_devs),NULL , +0 , ab8500->domain);if (ret)return ret;if (is_ab8540_1p2_or_earlier (ab8500)) - ret =mfd_add_devices (ab8500->dev,0 , ab8540_cut1_devs, -ARRAY_SIZE (ab8540_cut1_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , + ab8540_cut1_devs, +ARRAY_SIZE (ab8540_cut1_devs), +NULL ,0 , ab8500->domain);else /* ab8540 >= cut2 */ - ret =mfd_add_devices (ab8500->dev,0 , ab8540_cut2_devs, -ARRAY_SIZE (ab8540_cut2_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , + ab8540_cut2_devs, +ARRAY_SIZE (ab8540_cut2_devs), +NULL ,0 , ab8500->domain); }else if (is_ab8505 (ab8500)) - ret =mfd_add_devices (ab8500->dev,0 , ab8505_devs, -ARRAY_SIZE (ab8505_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8505_devs, +ARRAY_SIZE (ab8505_devs),NULL , +0 , ab8500->domain);else - ret =mfd_add_devices (ab8500->dev,0 , ab8500_devs, -ARRAY_SIZE (ab8500_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8500_devs, +ARRAY_SIZE (ab8500_devs),NULL , +0 , ab8500->domain);if (ret)return ret;/* Add battery management devices */ - ret =mfd_add_devices (ab8500->dev,0 , ab8500_bm_devs, -ARRAY_SIZE (ab8500_bm_devs),NULL , -0 , ab8500->domain); + ret =devm_mfd_add_devices (ab8500->dev,0 , ab8500_bm_devs, +ARRAY_SIZE (ab8500_bm_devs),NULL , +0 , ab8500->domain);if (ret)dev_err (ab8500->dev,"error adding bm devices\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 762/1257 spi: cadence-xspi: reject SDMA transfers larger than the requested length
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit ea9854a169e9c1437df8829bea21c2f2e80b137c ]
The XSPI controller reports the size of the slave-DMA transaction through SDMA_SIZE_REG. Both SDMA handlers take this register at face value and copy the reported number of bytes between the SDMA FIFO and the transfer buffers, without checking it against the length of the transfer that was actually requested.
While cdns_xspi_adjust_mem_op_size() clamps the size of the operations issued by the SPI core, the device can still report a bigger SDMA size than what was programmed, which makes the handlers read from or write to memory beyond the end of the transfer buffers.
Track the number of bytes requested for the current data phase in a new sdma_xfer_len field, set by cdns_xspi_send_stig_command() and by the Marvell b0 transfer path, and reject any SDMA size that exceeds it.
--- drivers/spi/spi-cadence-xspi.c | 36 +++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)
drivers/spi/spi-cadence-xspi.c +31 -5
@@ -332,6 +332,7 @@ struct cdns_xspi_dev {int irq;int cur_cs;unsigned int sdmasize; +unsigned int sdma_xfer_len;struct completion cmd_complete;struct completion auto_cmd_complete;
@@ -346,7 +347,7 @@ struct cdns_xspi_dev {u8 hw_num_banks;const struct cdns_xspi_driver_data *driver_data; -void (*sdma_handler)(struct cdns_xspi_dev *cdns_xspi); +int (*sdma_handler)(struct cdns_xspi_dev *cdns_xspi);void (*set_interrupts_handler)(struct cdns_xspi_dev *cdns_xspi,bool enabled);bool xfer_in_progress;
@@ -496,7 +497,7 @@ static inline void cdns_xspi_sdma_write(struct cdns_xspi_dev *cdns_xspi, size_tiowrite8_rep (dst, (const u8 *)buf + offset, len); } -static void cdns_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) +static int cdns_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) {u32 sdma_size, sdma_trd_info;u8 sdma_dir;
@@ -505,6 +506,13 @@ static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) sdma_trd_info =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_TRD_INFO_REG ); sdma_dir =FIELD_GET (CDNS_XSPI_SDMA_DIR , sdma_trd_info); +if (sdma_size > cdns_xspi->sdma_xfer_len) { +dev_err (cdns_xspi->dev, +"SDMA size %u exceeds the requested length %u\n" , + sdma_size, cdns_xspi->sdma_xfer_len); +return -EINVAL ; + } +switch (sdma_dir) {case CDNS_XSPI_SDMA_DIR_READ :cdns_xspi_sdma_read (cdns_xspi, sdma_size);
@@ -514,6 +522,8 @@ static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi)cdns_xspi_sdma_write (cdns_xspi, sdma_size);break ; } + +return 0 ; } static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi,
@@ -559,6 +569,7 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cdns_xspi->in_buffer = op->data.buf.in; cdns_xspi->out_buffer = op->data.buf.out; + cdns_xspi->sdma_xfer_len = op->data.nbytes;cdns_xspi_trigger_command (cdns_xspi, cmd_regs);
@@ -567,7 +578,11 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cdns_xspi->set_interrupts_handler (cdns_xspi, false);return -EIO ; } - cdns_xspi->sdma_handler (cdns_xspi); + ret = cdns_xspi->sdma_handler (cdns_xspi); +if (ret) { + cdns_xspi->set_interrupts_handler (cdns_xspi, false); +return ret; + } }wait_for_completion (&cdns_xspi->cmd_complete);
@@ -950,7 +965,7 @@ static void m_iowriteq(void __iomem *addr, const void *buf, int len) } } -static void marvell_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) +static int marvell_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) {u32 sdma_size, sdma_trd_info;u8 sdma_dir;
@@ -959,6 +974,13 @@ static void marvell_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) sdma_trd_info =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_TRD_INFO_REG ); sdma_dir =FIELD_GET (CDNS_XSPI_SDMA_DIR , sdma_trd_info); +if (sdma_size > cdns_xspi->sdma_xfer_len) { +dev_err (cdns_xspi->dev, +"SDMA size %u exceeds the requested length %u\n" , + sdma_size, cdns_xspi->sdma_xfer_len); +return -EINVAL ; + } +switch (sdma_dir) {case CDNS_XSPI_SDMA_DIR_READ : m_ioreadq(cdns_xspi->sdmabase,
@@ -970,6 +992,8 @@ static void marvell_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) cdns_xspi->out_buffer, sdma_size);break ; } + +return 0 ; }static const struct spi_controller_mem_ops marvell_xspi_mem_ops = {
@@ -1131,9 +1155,11 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,cdns_xspi_prepare_transfer (cs,1 , current_transfer_len -1 , cmd_regs);cdns_xspi_trigger_command (cdns_xspi, cmd_regs); + cdns_xspi->sdma_xfer_len = current_transfer_len -1 ;if (!cdns_xspi_is_sdma_ready (cdns_xspi, true))return -EIO ; - cdns_xspi->sdma_handler (cdns_xspi); +if (cdns_xspi->sdma_handler (cdns_xspi)) +return -EIO ;if (!cdns_xspi_is_stig_ready (cdns_xspi, true))return -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 763/1257 spi: cadence-xspi: fix stack buffer overflow in the Marvell b0 path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit ef9690269999ddf9b204731baca1bd6b7aea1aa7 ]
transfer_one_message_b0() falls back to a 10-byte stack buffer for transfers which carry no TX data and points both in_buffer and out_buffer into it.
With a transfer longer than 10 bytes the SDMA branch of the loop moves up to MRVL_XFER_QWORD_COUNT * MRVL_XFER_QWORD_BYTECOUNT (256) bytes through those pointers and then advances them by the same amount, so both directions overflow the scratch buffer: a read transaction copies SDMA data past the end of the buffer, a write transaction sends stack contents from beyond it to the SPI bus.
Size the scratch buffer for the largest chunk the loop can request, keep the buffer pointers pinned to it when the message does not carry the corresponding TX or RX data, and only advance the pointers which reference real transfer buffers. Also zero-initialize the scratch buffer so that padding bytes sent for TX-less transfers no longer leak uninitialized stack contents.
--- drivers/spi/spi-cadence-xspi.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/spi/spi-cadence-xspi.c +11 -5
@@ -268,6 +268,7 @@#define MRVL_XFER_FUNC_START BIT(0)#define MRVL_XFER_QWORD_COUNT 32#define MRVL_XFER_QWORD_BYTECOUNT 8 +#define MRVL_XFER_MAX_LEN (MRVL_XFER_QWORD_COUNT * MRVL_XFER_QWORD_BYTECOUNT)#define MRVL_XSPI_POLL_TIMEOUT_US 1000#define MRVL_XSPI_POLL_DELAY_US 10
@@ -1107,7 +1108,7 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,struct spi_device *spi = m->spi;struct spi_transfer *t =NULL ; -const unsigned int max_len =MRVL_XFER_QWORD_BYTECOUNT *MRVL_XFER_QWORD_COUNT ; +const unsigned int max_len =MRVL_XFER_MAX_LEN ;int current_transfer_len;int cs =spi_get_chipselect (spi,0 );int cs_change =0 ;
@@ -1130,13 +1131,16 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,list_for_each_entry (t, &m->transfers, transfer_list) {u8 *txd = (u8 *) t->tx_buf;u8 *rxd = (u8 *) t->rx_buf; -u8 data[10 ]; +u8 data[MRVL_XFER_MAX_LEN ] = {0 };u32 cmd_regs[6 ];if (!txd) txd = data; - cdns_xspi->in_buffer = txd +1 ; +if (rxd) + cdns_xspi->in_buffer = rxd; +else + cdns_xspi->in_buffer = data; cdns_xspi->out_buffer = txd +1 ;while (t->len) {
@@ -1163,8 +1167,10 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,if (!cdns_xspi_is_stig_ready (cdns_xspi, true))return -EIO ; - cdns_xspi->in_buffer += current_transfer_len; - cdns_xspi->out_buffer += current_transfer_len; +if (rxd) + cdns_xspi->in_buffer += current_transfer_len; +if (t->tx_buf) + cdns_xspi->out_buffer += current_transfer_len; }if (rxd) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 764/1257 ARM: 9488/1: smp: set current pointer in assembly before jumping into C
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit f6e551e7d515579b952422c93415470fb672d848 ]
With CONFIG_KCOV_INSTRUMENT_ALL=y, secondary CPUs fail to come online on ARMv6K/ARMv7 SMP:
CPU1: failed to boot: -38
The compiler inserts a call to __sanitizer_cov_trace_pc() at the entry of secondary_start_kernel(), before set_current(task). The KCOV hook dereferences current while TPIDRURO is still uninitialized, causing a data abort before cpu_init() has installed the exception stacks. The secondary CPU consequently never completes startup.
Initialize current in the secondary assembly handoff, as __mmap_switched already does for the boot CPU.
With current set in assembly, the set_current() call in secondary_start_kernel() is redundant. Drop it together with the function and the task argument. The hotplug resuscitate path in arch_cpu_idle_dead() needs no hand-off either, as smp_ops.cpu_die() can only return if the CPU kept its register state, TPIDRURO included.
--- arch/arm/include/asm/smp.h | 2 +- arch/arm/kernel/head-nommu.S | 1 + arch/arm/kernel/head.S | 1 + arch/arm/kernel/smp.c | 15 ++------------- 4 files changed, 5 insertions(+), 14 deletions(-)
arch/arm/include/asm/smp.h +1 -1
@@ -43,7 +43,7 @@ extern void set_smp_ipi_range(int ipi_base, int nr_ipi);* Called from platform specific assembly code, this is the * secondary CPU entry point. */ -asmlinkage void secondary_start_kernel(struct task_struct *task); +asmlinkage void secondary_start_kernel(void);/*
arch/arm/kernel/head-nommu.S +1 -0
@@ -116,6 +116,7 @@ ENTRY(secondary_startup) ldr r7, __secondary_data @ reload r7 ldr sp, [r7, #12] @ set up the stack pointer ldr r0, [r7, #16] @ set up task pointer + set_current r0, r1 mov fp, #0 b secondary_start_kernel ENDPROC(secondary_startup)
arch/arm/kernel/head.S +1 -0
@@ -442,6 +442,7 @@ ENTRY(__secondary_switched) adr_l r7, secondary_data + 12 @ get secondary_data.stack ldr sp, [r7] ldr r0, [r7, #4] @ get secondary_data.task + set_current r0, r1 mov fp, #0 b secondary_start_kernel ENDPROC(__secondary_switched)
arch/arm/kernel/smp.c +2 -13
@@ -371,12 +371,9 @@ void __noreturn arch_cpu_idle_dead(void)*/ __asm__("mov sp, %0\n" " mov fp, #0\n" -" mov r0, %1\n" " b secondary_start_kernel" : - :"r" (task_stack_page (current) +THREAD_SIZE -8 ), -"r" (current) - :"r0" ); + :"r" (task_stack_page (current) +THREAD_SIZE -8 ));unreachable (); }
@@ -397,23 +394,15 @@ static void smp_store_cpu_info(unsigned int cpuid)check_cpu_icache_size (cpuid); } -static void set_current (struct task_struct *cur) -{ -/* Set TPIDRURO */ - asm("mcr p15, 0, %0, c13, c0, 3" ::"r" (cur) :"memory" ); -} -/* * This is the secondary CPU boot entry. We're using this CPUs * idle thread stack, but a set of temporary page tables. */ -asmlinkage void secondary_start_kernel(struct task_struct *task) +asmlinkage void secondary_start_kernel(void) {struct mm_struct *mm = &init_mm;unsigned int cpu; -set_current (task); -secondary_biglittle_init ();/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 765/1257 ARM: 9491/1: alignment: restore uaccess state on emulation fault
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 80dafbcb705cead6d25cb821cf29c47da8860c8c ]
The alignment handlers enable access to user memory while emulating unaligned instructions. If a checked access faults, its exception table fixup jumps to the handler's fault label and bypasses uaccess_restore(). This leaves DOMAIN_USER as DOMAIN_CLIENT with SW domain PAN, or leaves TTBR0 page table walks enabled with TTBR0 PAN, while the fault is handled.
An ARM926 QEMU test using LDMIA across an unmapped page boundary reports DOMAIN_USER=1 at TYPE_FAULT before this change and DOMAIN_USER=0 after it. SW domain PAN is the default on ARMv5, ARMv6, and non-LPAE ARMv7 builds.
Keep the saved uaccess state at function scope and track whether it was saved. Restore it at the fault label only when needed. Paths that did not enable user access continue to skip the restore.
--- arch/arm/mm/alignment.c | 51 ++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-)
arch/arm/mm/alignment.c +37 -14
@@ -341,6 +341,8 @@ static int do_alignment_ldrhstrh(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd =RD_BITS (instr); +unsigned int ua_flags; +bool ua_saved = false; ai_half +=1 ;
@@ -364,10 +366,11 @@ do_alignment_ldrhstrh(unsigned long addr, u32 instr, struct pt_regs *regs) user:if (LDST_L_BIT (instr)) {unsigned long val; -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;get16t_unaligned_check (val, addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags);/* signed half-word? */ if (instr &0x40 )
@@ -375,14 +378,17 @@ do_alignment_ldrhstrh(unsigned long addr, u32 instr, struct pt_regs *regs) regs->uregs[rd] = val; }else { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;put16t_unaligned_check (regs->uregs[rd], addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }return TYPE_LDST ; fault: +if (ua_saved) +uaccess_restore (ua_flags);return TYPE_FAULT ; }
@@ -391,6 +397,8 @@ do_alignment_ldrdstrd(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd =RD_BITS (instr);unsigned int rd2; +unsigned int ua_flags; +bool ua_saved = false;int load;if ((instr &0xfe000000 ) ==0xe8000000 ) {
@@ -425,26 +433,30 @@ do_alignment_ldrdstrd(unsigned long addr, u32 instr, struct pt_regs *regs) user:if (load) {unsigned long val, val2; -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;get32t_unaligned_check (val, addr);get32t_unaligned_check (val2, addr +4 ); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); regs->uregs[rd] = val; regs->uregs[rd2] = val2; }else { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;put32t_unaligned_check (regs->uregs[rd], addr);put32t_unaligned_check (regs->uregs[rd2], addr +4 ); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }return TYPE_LDST ; bad:return TYPE_ERROR ; fault: +if (ua_saved) +uaccess_restore (ua_flags);return TYPE_FAULT ; }
@@ -452,6 +464,8 @@ static int do_alignment_ldrstr(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd =RD_BITS (instr); +unsigned int ua_flags; +bool ua_saved = false; ai_word +=1 ;
@@ -469,18 +483,22 @@ do_alignment_ldrstr(unsigned long addr, u32 instr, struct pt_regs *regs) trans:if (LDST_L_BIT (instr)) {unsigned int val; -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;get32t_unaligned_check (val, addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); regs->uregs[rd] = val; }else { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;put32t_unaligned_check (regs->uregs[rd], addr); -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }return TYPE_LDST ; fault: +if (ua_saved) +uaccess_restore (ua_flags);return TYPE_FAULT ; }
@@ -502,6 +520,8 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs) {unsigned int rd, rn, correction, nr_regs, regbits;unsigned long eaddr, newaddr; +unsigned int ua_flags; +bool ua_saved = false;if (LDM_S_BIT (instr)) goto bad;
@@ -547,7 +567,8 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs)#endif if (user_mode (regs)) { -unsigned int __ua_flags =uaccess_save_and_enable (); + ua_flags =uaccess_save_and_enable (); + ua_saved = true;for (regbits =REGMASK_BITS (instr), rd =0 ; regbits; regbits >>=1 , rd +=1 )if (regbits &1 ) {
@@ -559,7 +580,7 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs)put32t_unaligned_check (regs->uregs[rd], eaddr); eaddr +=4 ; } -uaccess_restore (__ua_flags); +uaccess_restore (ua_flags); }else {for (regbits =REGMASK_BITS (instr), rd =0 ; regbits; regbits >>=1 , rd +=1 )
@@ -581,6 +602,8 @@ do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs)return TYPE_DONE ; fault: +if (ua_saved) +uaccess_restore (ua_flags); regs->ARM_pc -= correction;return TYPE_FAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 766/1257 ARM: 9520/1: cacheinfo: avoid out-of-bounds write in populate_cache_leaves()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 41a3f4bc3e4ae4722fd24743bf3f286cea14e3dc ]
populate_cache_leaves() advances its bounds-checking index once per cache level, but split instruction/data caches consume two entries. CLIDR-based allocation supplies enough entries. Early allocation from the device tree can supply fewer and expose an out-of-bounds write.
Count each written leaf and stop before a split level that does not fit. This prepares ARM for DT-based early allocation and matches commit 875d742cf532 ("arm64: cacheinfo: Avoid out-of-bounds write to cacheinfo array").
--- arch/arm/kernel/cacheinfo.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
arch/arm/kernel/cacheinfo.c +7 -5
@@ -151,7 +151,7 @@ int populate_cache_leaves(unsigned int cpu)unsigned int level, idx;enum cache_type type;struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); -struct cacheinfo *this_leaf = this_cpu_ci->info_list; +struct cacheinfo *infos = this_cpu_ci->info_list;unsigned int arch =cpu_architecture ();/* CLIDR is not present before ARMv7/v7m */
@@ -159,13 +159,15 @@ int populate_cache_leaves(unsigned int cpu)return -EOPNOTSUPP ;for (idx =0 , level =1 ; level <= this_cpu_ci->num_levels && - idx < this_cpu_ci->num_leaves; idx++, level++) { + idx < this_cpu_ci->num_leaves; level++) { type =get_cache_type (level);if (type ==CACHE_TYPE_SEPARATE ) { -ci_leaf_init (this_leaf++,CACHE_TYPE_DATA , level); -ci_leaf_init (this_leaf++,CACHE_TYPE_INST , level); +if (idx +1 >= this_cpu_ci->num_leaves) +break ; +ci_leaf_init (&infos[idx++],CACHE_TYPE_DATA , level); +ci_leaf_init (&infos[idx++],CACHE_TYPE_INST , level); }else { -ci_leaf_init (this_leaf++, type, level); +ci_leaf_init (&infos[idx++], type, level); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 767/1257 ARM: 9521/1: cacheinfo: count external caches in early_cache_level()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 4fd69e8a9ebc42e292637ec2ebfb6bcf2d2f6c0e ]
early_cache_level() counts only caches described by CLIDR. An external PL310 is absent from CLIDR, and its arm,pl310-cache compatible is not accepted by init_of_cache_level(), so early allocation falls back to an incomplete count. init_cache_level() later adds the DT-described L2, forcing reallocation on the secondary CPU with interrupts disabled. This defeats early allocation on PREEMPT_RT.
Use init_cache_level() for early sizing too, so the initial allocation includes external caches described by the device tree.
--- arch/arm/kernel/cacheinfo.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
arch/arm/kernel/cacheinfo.c +5 -7
@@ -111,13 +111,6 @@ static int detect_cache_level(unsigned int *level_p, unsigned int *leaves_p)return 0 ; } -int early_cache_level (unsigned int cpu) -{ -struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); - -return detect_cache_level (&this_cpu_ci->num_levels, &this_cpu_ci->num_leaves); -} -int init_cache_level (unsigned int cpu) {unsigned int level, leaves;
@@ -146,6 +139,11 @@ int init_cache_level(unsigned int cpu)return 0 ; } +int early_cache_level (unsigned int cpu) +{ +return init_cache_level (cpu); +} +int populate_cache_leaves (unsigned int cpu) {unsigned int level, idx;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 768/1257 ARM: 9522/1: cacheinfo: guard the CLIDR read in populate_cache_leaves()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 2315f2c46e0813d010e7b3ea40f2769621453e27 ]
ARM1176 and ARM11 MPCore can be reported as ARMv7 by cpu_architecture() even though they lack CLIDR. populate_cache_leaves() therefore needs the CTR-format check used by detect_cache_level().
DT-based early allocation bypasses init_cache_level(), so its check no longer protects populate_cache_leaves(). A combined ARMv6/ARMv7 SMP kernel can reach this path on BCM2835, whose DT describes its caches.
Share the CLIDR capability check between detection and population. Return -ENOENT from population when CLIDR is unavailable, preserving the existing absence of cacheinfo and avoiding a new topology warning.
--- arch/arm/kernel/cacheinfo.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
arch/arm/kernel/cacheinfo.c +13 -12
@@ -80,19 +80,21 @@ static void ci_leaf_init(struct cacheinfo *this_leaf, this_leaf->type = type; } -static int detect_cache_level (unsigned int *level_p,unsigned int *leaves_p) +static bool clidr_present (void ) { -unsigned int ctype, level, leaves; -u32 ctr, format; -/* CLIDR is not present before ARMv7/v7m */ if (cpu_architecture () < CPU_ARCH_ARMv7) -return -EOPNOTSUPP ; +return false;/* Don't try reading CLIDR if CTR declares old format */ - ctr =read_cpuid_cachetype (); - format =FIELD_GET (CTR_FORMAT_MASK , ctr); -if (format !=CTR_FORMAT_ARMV7 ) +return FIELD_GET (CTR_FORMAT_MASK ,read_cpuid_cachetype ()) ==CTR_FORMAT_ARMV7 ; +} + +static int detect_cache_level (unsigned int *level_p,unsigned int *leaves_p) +{ +unsigned int ctype, level, leaves; + +if (!clidr_present ())return -EOPNOTSUPP ;for (level =1 , leaves =0 ; level <=MAX_CACHE_LEVEL ; level++) {
@@ -150,11 +152,10 @@ int populate_cache_leaves(unsigned int cpu)enum cache_type type;struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu);struct cacheinfo *infos = this_cpu_ci->info_list; -unsigned int arch =cpu_architecture (); -/* CLIDR is not present before ARMv7/v7m */ -if (arch < CPU_ARCH_ARMv7) -return -EOPNOTSUPP ; +/* The device tree can describe caches CLIDR cannot fill in. */ +if (!clidr_present ()) +return -ENOENT ;for (idx =0 , level =1 ; level <= this_cpu_ci->num_levels && idx < this_cpu_ci->num_leaves; level++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 769/1257 ARM: 9523/1: topology: allocate the cacheinfo early on the boot CPU
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 2d4234f99900403842b2c031fefb4c5816ac4df8 ]
ARM secondary CPUs allocate cacheinfo in detect_cache_attributes(), called from secondary_start_kernel() with interrupts disabled. With PREEMPT_RT, the allocation takes a sleeping lock and triggers "BUG: sleeping function called from invalid context".
Call fetch_cache_info() for each possible CPU from init_cpu_topology() on the boot CPU, following commit 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU"). This supplies the arrays before secondary CPUs populate them. Suppress -ENOENT and -EOPNOTSUPP, which leave cache detection to the existing late path.
The CLIDR fallback uses the boot CPU's cache geometry. A secondary CPU with more cache leaves can still require late reallocation and trigger the warning.
--- arch/arm/kernel/topology.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm/kernel/topology.c +13 -0
@@ -12,6 +12,7 @@*/ #include <linux/arch_topology.h> +#include <linux/cacheinfo.h> #include <linux/cpu.h> #include <linux/cpufreq.h> #include <linux/cpumask.h>
@@ -238,8 +239,20 @@ void store_cpu_topology(unsigned int cpuid)*/ void __init init_cpu_topology (void ) { +int cpu, ret; +reset_cpu_topology ();smp_wmb ();parse_dt_topology (); + +for_each_possible_cpu (cpu) { + ret =fetch_cache_info (cpu); +if (!ret) +continue ; +/* CPUs without a usable CLIDR return -EOPNOTSUPP. */ +if (ret != -ENOENT && ret != -EOPNOTSUPP ) +pr_err ("Early cacheinfo failed, ret = %d\n" , ret); +return ; + } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 770/1257 PCI: Set supported_speeds in set_pcie_port_type()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stian Halseth <[email protected]>
[ Upstream commit 926767a9be8866d26cc27ca46c46c03d921e2193 ]
sparc64 and powerpc create PCI devices from the device tree in of_create_pci_dev(), which calls set_pcie_port_type() but not pci_setup_device(). Since d2bd39c0456b, supported_speeds is only set in pci_setup_device(), so it stays 0 for these devices.
pcie_get_speed_cap() then returns PCI_SPEED_UNKNOWN, the sysfs 'max_link_speed' attribute reads "Unknown", and the failed link retraining quirk passes PCI_SPEED_UNKNOWN to pcie_set_target_speed(), which warns on a SPARC T7-1:
WARNING: drivers/pci/pcie/bwctrl.c:125 at pcie_set_target_speed+0x284/0x2e0
Set supported_speeds in set_pcie_port_type(), which all three paths call.
--- drivers/pci/probe.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/probe.c +2 -3
@@ -1651,6 +1651,8 @@ void set_pcie_port_type(struct pci_dev *pdev) pdev->aspm_l1_support =1 ;#endif + pdev->supported_speeds =pcie_get_supported_speeds (pdev); + parent =pci_upstream_bridge (pdev);if (!parent)return ;
@@ -2074,9 +2076,6 @@ int pci_setup_device(struct pci_dev *dev)set_pcie_untrusted (dev); -if (pci_is_pcie (dev)) - dev->supported_speeds =pcie_get_supported_speeds (dev); -/* "Unknown power state" */ dev->current_state =PCI_UNKNOWN ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 771/1257 Input: xpad - add GameSir Nova Lite support
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Orlando <[email protected]>
[ Upstream commit 2e6f2e5799f328ca0879dad14d7f3709c7f7496b ]
Add vendor and product ID for GameSir Nova Lite (0x3537:0x1040) in XInput mode to enable force feedback rumble support.
--- drivers/input/joystick/xpad.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/joystick/xpad.c +1 -0
@@ -408,6 +408,7 @@ static const struct xpad_device { { 0x3537, 0x1004, "GameSir T4 Kaleid", 0, XTYPE_XBOX360 }, { 0x3537, 0x100f, "GameSir Nova 2 Lite", 0, XTYPE_XBOX360 }, { 0x3537, 0x1010, "GameSir G7 SE", 0, XTYPE_XBOXONE }, + { 0x3537, 0x1040, "GameSir Nova Lite", 0, XTYPE_XBOX360 }, { 0x3651, 0x1000, "CRKD SG", 0, XTYPE_XBOX360 }, { 0x366c, 0x0005, "ByoWave Proteus Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE, FLAG_DELAY_INIT }, { 0x3767, 0x0101, "Fanatec Speedster 3 Forceshock Wheel", 0, XTYPE_XBOX },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 772/1257 Bluetooth: btusb: Add device ID for Realtek RTL8761BUE (StarTech AV53C1)
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolaj Klitlund Børty <[email protected]>
[ Upstream commit 1430308fc9d47a801a305700cd444b1a0051d14a ]
Add the USB ID 0x14b0:0x047a for the StarTech AV53C1-USB-BLUETOOTH adapter, a Realtek RTL8761BUE based Bluetooth 5.3 dongle.
Without this entry btusb treats the device as a generic Bluetooth adapter and never loads the Realtek firmware, leaving the controller on its ROM firmware. In that state it advertises and scans actively, but never reports advertisements during passive scanning. LE connections initiated by the kernel wait for a passive-scan report before issuing LE Create Connection, so connecting and pairing from BlueZ time out without any error from the controller.
The same product is also sold with the ID 0x2c0a:0x8761, which is already supported.
lsusb -v output for the device:
Bus 001 Device 010: ID 14b0:047a StarTech.com Ltd. Bluetooth Radio Device Descriptor:
bcdUSB 1.10
bDeviceClass 224 Wireless
bDeviceSubClass 1 Radio Frequency
bDeviceProtocol 1 Bluetooth
idVendor 0x14b0 StarTech.com Ltd.
idProduct 0x047a
bcdDevice 2.00
iManufacturer 1 Realtek iProduct 2 Bluetooth Radio iSerial 3 00E04C239987 bNumInterfaces 2
Interface Descriptor:
bInterfaceClass 224 Wireless
bInterfaceSubClass 1 Radio Frequency
bInterfaceProtocol 1 Bluetooth
--- drivers/bluetooth/btusb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bluetooth/btusb.c +2 -0
@@ -878,6 +878,8 @@ static const struct usb_device_id quirks_table[] = { BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x37ad, 0x0600), .driver_info = BTUSB_REALTEK | BTUSB_WIDEBAND_SPEECH }, + { USB_DEVICE(0x14b0, 0x047a), .driver_info = BTUSB_REALTEK | + BTUSB_WIDEBAND_SPEECH }, /* Additional Realtek 8761CU Bluetooth devices */ { USB_DEVICE(0x0b05, 0x1bef), .driver_info = BTUSB_REALTEK |
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 773/1257 Bluetooth: 6lowpan: Pin module for 6lowpan_control debugfs file
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bui Viet Dung <[email protected]>
[ Upstream commit 8368f0c2cde48c09ed70644059f24172b0c59f52 ]
An open debugfs file retains lowpan_control_fops in the debugfs proxy state. However, lowpan_control_fops has no .owner set to THIS_MODULE. As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth_6lowpan module.
With CONFIG_BT_6LOWPAN=m, a userspace process can keep the debugfs file descriptor for 6lowpan_control open across module unload (delete_module / rmmod bluetooth_6lowpan). When the process subsequently closes the file descriptor, full_proxy_release() accesses the already freed and unmapped lowpan_control_fops table, causing a kernel page fault or oops.
The issue was discovered via manual code audit ofnet/bluetooth/6lowpan.c.
Set .owner = THIS_MODULE on lowpan_control_fops so that debugfs pins the module until all open file descriptors have finished.
--- net/bluetooth/6lowpan.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/6lowpan.c +1 -0
@@ -1209,6 +1209,7 @@ static int lowpan_control_open(struct inode *inode, struct file *file) }static const struct file_operations lowpan_control_fops = { + .owner =THIS_MODULE , .open = lowpan_control_open, .read = seq_read, .write = lowpan_control_write,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 774/1257 Bluetooth: hci_debugfs: Pin module for debugfs file operations
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bui Viet Dung <[email protected]>
[ Upstream commit 2a3e2287877b1ee40ffb80b7d769b633866533f3 ]
An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, the file_operations defined in hci_debugfs.c (use_debug_keys_fops, sc_only_mode_fops, ssp_debug_mode_fops, force_bredr_smp_fops, force_static_address_fops, force_no_mitm_fops, dut_mode_fops, vendor_diag_fops, and the DEFINE_QUIRK_ATTRIBUTE macro) have no .owner set to THIS_MODULE.
As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth module. When a userspace process opens any of these debugfs files, a subsequent controller removal and module unload (rmmod bluetooth) can succeed while the file descriptor remains open.
When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release():
BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: <TASK> __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
The issue was discovered via manual code audit of net/bluetooth/hci_debugfs.c and verified on a Linux 7.3-rc6 test VM with CONFIG_BT=m.
Set .owner = THIS_MODULE on all debugfs file_operations tables in hci_debugfs.c so that debugfs keeps the module loaded until close has finished.
--- net/bluetooth/hci_debugfs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/bluetooth/hci_debugfs.c +9 -0
@@ -65,6 +65,7 @@ static ssize_t __name ## _write(struct file *file, \ } \ \ static const struct file_operations __name ## _fops = { \ + .owner =THIS_MODULE , \ .open = simple_open, \ .read = __name ## _read, \ .write = __name ## _write, \
@@ -283,6 +284,7 @@ static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf, }static const struct file_operations use_debug_keys_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = use_debug_keys_read, .llseek = default_llseek,
@@ -301,6 +303,7 @@ static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf, }static const struct file_operations sc_only_mode_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = sc_only_mode_read, .llseek = default_llseek,
@@ -437,6 +440,7 @@ static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf, }static const struct file_operations ssp_debug_mode_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = ssp_debug_mode_read, .llseek = default_llseek,
@@ -529,6 +533,7 @@ static ssize_t force_bredr_smp_write(struct file *file, }static const struct file_operations force_bredr_smp_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = force_bredr_smp_read, .write = force_bredr_smp_write,
@@ -778,6 +783,7 @@ static ssize_t force_static_address_write(struct file *file, }static const struct file_operations force_static_address_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = force_static_address_read, .write = force_static_address_write,
@@ -1177,6 +1183,7 @@ static ssize_t force_no_mitm_write(struct file *file, }static const struct file_operations force_no_mitm_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = force_no_mitm_read, .write = force_no_mitm_write,
@@ -1315,6 +1322,7 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf, }static const struct file_operations dut_mode_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = dut_mode_read, .write = dut_mode_write,
@@ -1371,6 +1379,7 @@ static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf, }static const struct file_operations vendor_diag_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = vendor_diag_read, .write = vendor_diag_write,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 775/1257 Bluetooth: selftest: Pin module for selftest debugfs file operations
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bui Viet Dung <[email protected]>
[ Upstream commit 64aabf94ecccb1120a63b4ee5a6761871a181a41 ]
An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, test_smp_fops in net/bluetooth/smp.c and test_ecdh_fops in net/bluetooth/selftest.c have no .owner set to THIS_MODULE.
As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the bluetooth module. When CONFIG_BT=m and selftests are enabled, a userspace process can open either /sys/kernel/debug/bluetooth/selftest_smp or /sys/kernel/debug/bluetooth/selftest_ecdh and keep the file descriptor open while the module is unloaded (rmmod bluetooth).
When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release():
BUG: unable to handle page fault for address: fffffbfff8056f03 #PF: supervisor read access in kernel mode Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: <TASK> __fput+0x39f/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
The issue was discovered via manual code audit of net/bluetooth/smp.c and net/bluetooth/selftest.c.
Set .owner = THIS_MODULE on test_smp_fops and test_ecdh_fops so that debugfs keeps the module pinned until the file descriptors are closed.
--- net/bluetooth/selftest.c | 1 + net/bluetooth/smp.c | 1 + 2 files changed, 2 insertions(+)
net/bluetooth/selftest.c +1 -0
@@ -188,6 +188,7 @@ static ssize_t test_ecdh_read(struct file *file, char __user *user_buf, }static const struct file_operations test_ecdh_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = test_ecdh_read, .llseek = default_llseek,
net/bluetooth/smp.c +1 -0
@@ -3696,6 +3696,7 @@ static ssize_t test_smp_read(struct file *file, char __user *user_buf, }static const struct file_operations test_smp_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = test_smp_read, .llseek = default_llseek,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 776/1257 Bluetooth: L2CAP: Reject mode changes on connected channels
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
[ Upstream commit c1398cf11b31a94c27ed810ba69515e0df5ce379 ]
A peer can send a configuration response with an RFC option for another mode to a connected channel, for example to switch it from Streaming to ERTM mode. l2cap_parse_conf_rsp() then changes chan->mode, but l2cap_ertm_init() is not called again, so the ERTM sequence lists are never allocated. The next out-of-sequence I-frame makes l2cap_seq_list_clear() write through the NULL srej_list.list.
Refuse the channel when a response tries to change the mode of a connected channel.
--- net/bluetooth/l2cap_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +5 -1
@@ -3802,7 +3802,11 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, } } -if (chan->mode ==L2CAP_MODE_BASIC && chan->mode != rfc.mode) +/* A connected channel cannot change its mode, as the new mode would +* not be initialized. +*/ +if (chan->mode != rfc.mode && + (chan->mode ==L2CAP_MODE_BASIC || chan->state ==BT_CONNECTED ))return -ECONNREFUSED ; chan->mode = rfc.mode;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 777/1257 Bluetooth: L2CAP: Reject invalid TxWindow in configuration requests
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
[ Upstream commit c5ebb0245fe927cf5fa33510a9cb2799c4a2dd01 ]
A peer can send an ERTM RFC option with a TxWindow of zero, which is out of spec. It is stored in remote_tx_win unchanged and later passed to l2cap_seq_list_init(), where roundup_pow_of_two(0) is undefined. On some architectures this results in a ZERO_SIZE_PTR list and a remote kernel oops.
A TxWindow above 63 is out of spec as well. With 6-bit sequence numbers we would then send more unacknowledged frames than the sequence space can tell apart.
Reply with L2CAP_CONF_UNACCEPT and propose the default TxWindow instead of accepting the value, so remote_tx_win always stays within 1 to 63. Keep the parameters of an earlier request then, and do not treat the request as done because an earlier one was.
Also refuse a zero size in l2cap_seq_list_init(), so any other path that reaches it with a zero TxWindow fails the channel instead of the kernel.
--- net/bluetooth/l2cap_core.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
net/bluetooth/l2cap_core.c +27 -8
@@ -320,6 +320,10 @@ static int l2cap_seq_list_init(struct l2cap_seq_list *seq_list, u16 size) {size_t alloc_size, i; +/* roundup_pow_of_two(0) is undefined */ +if (!size) +return -EINVAL ; +/* Allocated size is a power of 2 to map sequence numbers * (which may be up to 14 bits) in to a smaller array that is * sized for the negotiated ERTM transmit windows.
@@ -3649,18 +3653,33 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t databreak ;case L2CAP_MODE_ERTM : -if (!test_bit (CONF_EWS_RECV , &chan->conf_state)) - chan->remote_tx_win = rfc.txwin_size; -else - rfc.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; - - chan->remote_max_tx = rfc.max_transmit; - size =min_t (u16,le16_to_cpu (rfc.max_pdu_size), chan->conn->mtu -L2CAP_EXT_HDR_SIZE -L2CAP_SDULEN_SIZE -L2CAP_FCS_SIZE ); rfc.max_pdu_size =cpu_to_le16 (size); - chan->remote_mps = size; + +/* The TxWindow must be within 1 to 63, otherwise +* propose the default one and keep the parameters of +* an earlier request. This overrides a PENDING result +* from the EFS check above, so the request is no +* longer pending, nor done if an earlier one was. +*/ +if (!rfc.txwin_size || + rfc.txwin_size >L2CAP_DEFAULT_TX_WINDOW ) { + result =L2CAP_CONF_UNACCEPT ; +clear_bit (CONF_LOC_CONF_PEND , &chan->conf_state); +clear_bit (CONF_OUTPUT_DONE , &chan->conf_state); + rfc.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; + remote_efs =0 ; + }else { +if (!test_bit (CONF_EWS_RECV , &chan->conf_state)) + chan->remote_tx_win = rfc.txwin_size; +else + rfc.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; + + chan->remote_max_tx = rfc.max_transmit; + chan->remote_mps = size; + }__l2cap_set_ertm_timeouts (chan, &rfc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 778/1257 Bluetooth: L2CAP: Use default TxWindow for zero socket option
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
[ Upstream commit 226fa3b676cbf2236f803bccd347462433ffc2c8 ]
L2CAP_OPTIONS accepts a txwin_size of zero and
stores it in tx_win. The zero is then sent to the
peer in our configuration request, and if the
channel ends up in ERTM mode it is passed tol2cap_seq_list_init().
Use the default TxWindow instead, as the mode can
still be changed to ERTM during configuration.
--- net/bluetooth/l2cap_sock.c | 4 ++++ 1 file changed, 4 insertions(+)
net/bluetooth/l2cap_sock.c +4 -0
@@ -815,6 +815,10 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,break ; } +/* A zero TxWindow is invalid, use the default instead */ +if (!opts.txwin_size) + opts.txwin_size =L2CAP_DEFAULT_TX_WINDOW ; +if (!l2cap_valid_mtu (chan, opts.imtu)) { err = -EINVAL ;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 779/1257 cpufreq: schedutil: Serialize sugov_start() against rate limit updates
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
[ Upstream commit ce390caf5541c493c9061e7a2d98a463e66b736a ]
The current value of sg_policy->tunables->rate_limit_us is used in sugov_start() without locking to update sg_policy->freq_update_delay_ns, so if rate_limit_us_store() runs in parallel with it, the rate limit update may go unnoticed and the new freq_update_delay_ns value may be stale until the rate limit is updated again.
To avoid that, acquire the update_lock mutex of the rate limit sysfs attribute, that is held by rate_limit_us_store() during rate limit updates, around the freq_update_delay_ns in sugov_start().
--- kernel/sched/cpufreq_schedutil.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/sched/cpufreq_schedutil.c +13 -1
@@ -73,6 +73,18 @@ static void sugov_update_rate_limit_us(struct sugov_policy *sg_policy) (s64 )sg_policy->tunables->rate_limit_us *NSEC_PER_USEC ; } +static void sugov_update_rate_limit_us_sync (struct sugov_policy *sg_policy) +{ +/* +* Serialize with rate_limit_us_store() to prevent this path from using +* a stale rate limit tunable value to set the limit for the given +* policy. +*/ +guard (mutex)(&sg_policy->tunables->attr_set.update_lock); + +sugov_update_rate_limit_us (sg_policy); +} +static bool sugov_should_update_freq (struct sugov_policy *sg_policy,u64 time) {s64 delta_ns;
@@ -861,7 +873,7 @@ static int sugov_start(struct cpufreq_policy *policy)void (*uu)(struct update_util_data *data,u64 time,unsigned int flags);unsigned int cpu; -sugov_update_rate_limit_us (sg_policy); +sugov_update_rate_limit_us_sync (sg_policy); sg_policy->last_freq_update_time =0 ; sg_policy->next_freq =0 ; sg_policy->work_in_progress = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 780/1257 PCI: xilinx-xdma: Fix device node reference leak in xilinx_pl_dma_pcie_init_irq_domain()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 73d3d81832708137ba6332fc011663feaf97deee ]
xilinx_pl_dma_pcie_init_irq_domain() takes a reference to the PCIe interrupt-controller child node with of_get_child_by_name(), but the error paths after the two irq_domain_create_linear() calls and after xilinx_pl_dma_pcie_init_msi_irq_domain() return directly without dropping it. irq_domain_create_linear() gets its own reference on the fwnode, so the domains do not consume the caller's one.
Add an err_put_node label that drops the reference before returning.
--- drivers/pci/controller/pcie-xilinx-dma-pl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-xilinx-dma-pl.c +7 -3
@@ -581,7 +581,7 @@ static int xilinx_pl_dma_pcie_init_irq_domain(struct pl_dma_pcie *port) port->pldma_domain =irq_domain_create_linear (of_fwnode_handle (pcie_intc_node),32 , &event_domain_ops, port);if (!port->pldma_domain) -return -ENOMEM ; + goto err_put_node;irq_domain_update_bus_token (port->pldma_domain,DOMAIN_BUS_NEXUS );
@@ -589,7 +589,7 @@ static int xilinx_pl_dma_pcie_init_irq_domain(struct pl_dma_pcie *port) &intx_domain_ops, port);if (!port->intx_domain) {dev_err (dev,"Failed to get a INTx IRQ domain\n" ); -return -ENOMEM ; + goto err_put_node; }irq_domain_update_bus_token (port->intx_domain,DOMAIN_BUS_WIRED );
@@ -597,13 +597,17 @@ static int xilinx_pl_dma_pcie_init_irq_domain(struct pl_dma_pcie *port) ret =xilinx_pl_dma_pcie_init_msi_irq_domain (port);if (ret !=0 ) {irq_domain_remove (port->intx_domain); -return -ENOMEM ; + goto err_put_node; }of_node_put (pcie_intc_node);raw_spin_lock_init (&port->lock);return 0 ; + +err_put_node: +of_node_put (pcie_intc_node); +return -ENOMEM ; }static int xilinx_pl_dma_pcie_setup_irq (struct pl_dma_pcie *port)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 781/1257 kbuild: AutoFDO: Update split machine function argument for upstream rename
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
[ Upstream commit 2b358510d5cc56164f83110ca1499c95a5a352cd ]
A recent LLVM commit [1] renamed the internal LLVM plugin option '-split-machine-functions' to '-function-splitting=all', breaking the AutoFDO + ThinLTO build with:
ld.lld: error: -plugin-opt=-: ld.lld: Unknown command line argument '-split-machine-functions'. Try: 'ld.lld --help'
The plugin option is needed for in-process ThinLTO, so handle the rename accordingly using ld-option.
--- scripts/Makefile.autofdo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.autofdo +1 -1
@@ -22,7 +22,7 @@ ifdef CONFIG_LTO_CLANG_THIN KBUILD_LDFLAGS += --lto-sample-profile=$(CLANG_AUTOFDO_PROFILE) endif KBUILD_LDFLAGS += --mllvm=-enable-fs-discriminator=true --mllvm=-improved-fs-discriminator=true -plugin-opt=thinlto - KBUILD_LDFLAGS += -plugin-opt=-split-machine-functions + KBUILD_LDFLAGS += $(call ld-option,-plugin-opt=-function-splitting=all,-plugin-opt=-split-machine-functions) endif export CFLAGS_AUTOFDO_CLANG RUSTFLAGS_AUTOFDO_CLANG
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 782/1257 iommufd: Keep dmabuf PFNs MMIO when filling another domain
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit 769f2cd9226c96619d77fa16af84de74cae41b6b ]
A VFIO PCI dmabuf mapped into an IOAS is mapped with IOMMU_MMIO only in the domains present when it is mapped. A domain added later, or a copy of the area into another IOAS, maps the same BAR as cacheable CPU
memory: IOMMU_CACHE set and IOMMU_MMIO clear.
Once the area is in pages->domains_itree, pfn_reader_fill_span() reads its PFNs back from the storage domain through batch_from_domain(), which adds them with batch_add_pfn() as BATCH_CPU_MEMORY. Only a hole in the span reaches pfn_reader_fill_dmabuf() and gets BATCH_MMIO, so batch_to_domain() programs the later domain with the wrong prot.
The effect depends on the page table format. io-pgtable-arm maps the BAR as Normal cacheable instead of Device memory, the AMDv1 and x86_64 generic_pt formats set the SME C-bit on it when the tables are encrypted, and the RISC-V format with Svpbmt maps it as normal memory instead of IO.
Read dmabuf PFNs from the recorded phys for every span, before the xarray and domain paths. The phys range is always available, and the read-back from a domain only serves to avoid re-pinning user pages.
Sashiko pointed this out while reviewing an RFC that plumbs the dma-buf memory type through pfn_reader_fill_dmabuf().
--- drivers/iommu/iommufd/pages.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/iommu/iommufd/pages.c +9 -4
@@ -1178,6 +1178,15 @@ static int pfn_reader_fill_span(struct pfn_reader *pfns) WARN_ON(span->last_used < start_index))return -EINVAL ; +/* +* Always read a dmabuf from its phys, even where a domain already +* maps it: a domain can only report CPU memory PFNs, losing +* BATCH_MMIO. last_hole aliases last_used, so this covers any span. +*/ +if (iopt_is_dmabuf (pfns->pages)) +return pfn_reader_fill_dmabuf (&pfns->dmabuf, &pfns->batch, + start_index, span->last_hole); +if (span->is_used ==1 ) {batch_from_xarray (&pfns->batch, &pfns->pages->pinned_pfns, start_index, span->last_used);
@@ -1201,10 +1210,6 @@ static int pfn_reader_fill_span(struct pfn_reader *pfns)return 0 ; } -if (iopt_is_dmabuf (pfns->pages)) -return pfn_reader_fill_dmabuf (&pfns->dmabuf, &pfns->batch, - start_index, span->last_hole); - user = &pfns->user;if (start_index >= user->upages_end) { rc = pfn_reader_user_pin(user, pfns->pages, start_index,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 783/1257 iommufd: Reject a zero-length dirty bitmap request
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit f6b3fd8f573e801066c21b2aec3d2e949e61e48e ]
iommufd_check_iova_range() subtracts one from bitmap->length before it checks the length, so a zero-length request wraps to SIZE_MAX. With iova = 0 the wrapped value passes the overflow and alignment checks, and the request reaches iova_bitmap_alloc() with length 0.
iova_bitmap_alloc() then sizes the bitmap from a length - 1 of SIZE_MAX, so mapped_total_index is effectively unbounded. The scan uses last_iova = ULONG_MAX, which spans the whole IOAS when an area is mapped at IOVA 0. Reject a zero length before the subtraction.
--- drivers/iommu/iommufd/io_pagetable.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iommu/iommufd/io_pagetable.c +3 -0
@@ -605,6 +605,9 @@ int iommufd_check_iova_range(struct io_pagetable *iopt,size_t iommu_pgsize = iopt->iova_alignment;u64 last_iova; +if (!bitmap->length) +return -EINVAL ; +if (check_add_overflow (bitmap->iova, bitmap->length -1 , &last_iova))return -EOVERFLOW ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 784/1257 ALSA: hda/realtek: Fix quirk for HP Laptop 15-fc0xxx
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Heng <[email protected]>
[ Upstream commit 044d41b43ee19aa29cb0c9b7b8e77fd113336522 ]
The HP Laptop 15-fc0xxx is based on an AMD platform where the digital microphone is provided by the snd-soc-acp6x-mach driver, not by the HDA codec. The ALC236_FIXUP_HP_DMIC quirk configures pin 0x12 as an internal DMIC, which is a misconfiguration for this machine: the pin is not wired to a codec DMIC and the setting has no effect on the actual microphone path (which works via ACP6x).
Replace ALC236_FIXUP_HP_DMIC with ALC236_FIXUP_HP_MUTE_LED_MICMUTE_GPIO, the standard quirk used by the closely related HP Laptop 15-fd0xxx and other ALC236 HP machines. This removes the misleading DMIC pin config and adds proper mute LED and micmute LED support that was missing from the original quirk.
--- sound/hda/codecs/realtek/alc269.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
sound/hda/codecs/realtek/alc269.c +1 -9
@@ -4379,7 +4379,6 @@ enum {ALC245_FIXUP_BASS_HP_DAC ,ALC245_FIXUP_ACER_MICMUTE_LED ,ALC245_FIXUP_CS35L41_I2C_2_MUTE_LED , -ALC236_FIXUP_HP_DMIC ,ALC256_FIXUP_HONOR_MRB_XXX_M1020_AUDIO ,ALC245_FIXUP_HP_ENVY_X360_15_FH0XXX , ALC287_FIXUP_ACER_MICMUTE_LED,
@@ -7126,13 +7125,6 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC287_FIXUP_CS35L41_I2C_2, }, - [ALC236_FIXUP_HP_DMIC] = { - .type = HDA_FIXUP_PINS, - .v.pins = (const struct hda_pintbl []) { - {0x12 ,0x90a60160 },/* use as internal mic */ - { } - }, - }, [ALC256_FIXUP_HONOR_MRB_XXX_M1020_AUDIO] = { .type = HDA_FIXUP_PINS, .v.pins = (const struct hda_pintbl[]) {
@@ -7775,7 +7767,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x103c ,0x8da1 ,"HP 16 Clipper OmniBook X" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8da7 ,"HP 14 Enstrom OmniBook X" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8da8 ,"HP 16 Piston OmniBook X" ,ALC245_FIXUP_HP_ENVY_X360_15_FH0XXX ), -SND_PCI_QUIRK (0x103c ,0x8dc9 ,"HP Laptop 15-fc0xxx" ,ALC236_FIXUP_HP_DMIC ), +SND_PCI_QUIRK (0x103c ,0x8dc9 ,"HP Laptop 15-fc0xxx" ,ALC236_FIXUP_HP_MUTE_LED_MICMUTE_GPIO ),SND_PCI_QUIRK (0x103c ,0x8dd4 ,"HP EliteStudio 8 AIO" ,ALC274_FIXUP_HP_AIO_BIND_DACS ),SND_PCI_QUIRK (0x103c ,0x8dd7 ,"HP Laptop 15-fd0xxx" ,ALC236_FIXUP_HP_MUTE_LED_MICMUTE_GPIO ), SND_PCI_QUIRK(0x103c, 0x8de8, "HP Gemtree", ALC245_FIXUP_TAS2781_SPI_2),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 785/1257 crypto: qat - initialise state_lock on every path in adf_devmgr_add_dev()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahsan Atta <[email protected]>
[ Upstream commit 4ad7c1bd5f3dcd3fd6efbb068d6ee2a68dddfece ]
state_lock is initialised at the end of adf_devmgr_add_dev(), but the VF on host path whose id mapping already exists returns earlier via 'goto unlock'. That mapping outlives the VF, so this path is taken every time a VF is recreated on a BDF that already hosted one, e.g.:
echo 0 > sriov_numvfs
echo 32 > sriov_numvfs
accel_dev is freshly allocated on each probe, so state_lock is left zeroed and adf_dev_up() takes an uninitialised mutex. With CONFIG_DEBUG_MUTEXES this is reported on a dh895xcc with 32 host-bound VFs:
DEBUG_LOCKS_WARN_ON(lock->magic != lock)
WARNING: kernel/locking/mutex.c:159 at mutex_lock+0x171/0x1c0 Call Trace: adf_dev_up+0x27/0xe0 [intel_qat] adf_probe+0x700/0xa80 [qat_dh895xccvf] local_pci_probe+0xd5/0x190
The same happens on teardown when adf_dev_down() locks it again.
Initialise the lock next to the other per-device state, before the tables are updated, so it is done on every path.
--- drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c +1 -1
@@ -137,6 +137,7 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,mutex_lock (&table_lock);atomic_set (&accel_dev->ref_count,0 ); +mutex_init (&accel_dev->state_lock);/* PF on host or VF on guest - optimized to remove redundant is_vf */ if (!accel_dev->is_vf || !pf) {
@@ -210,7 +211,6 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev, map->attached = true;list_add_tail (&map->list, &vfs_table); } -mutex_init (&accel_dev->state_lock); unlock:mutex_unlock (&table_lock);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 786/1257 crypto: qat - fix use of destroyed vf2pf_lock on VF restart
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahsan Atta <[email protected]>
[ Upstream commit 4921634ac0a9a65aaa5e41308aabda3d3f562ee3 ]
adf_dev_stop_async() sends the RESTARTING_COMPLETE message after adf_dev_down() has returned, but adf_dev_down() already destroyed the lock that message takes.
Both run in sequence in the same worker, so every PF restart locks a destroyed mutex. With CONFIG_DEBUG_MUTEXES on a dh895xcc with 32 host-bound VFs this trips on the first PF reset:
DEBUG_LOCKS_WARN_ON(lock->magic != lock)
WARNING: kernel/locking/mutex.c:159 at mutex_lock+0x171/0x1c0 Workqueue: adf_vf_stop_wq adf_dev_stop_async [intel_qat] Call Trace: adf_gen2_pfvf_send+0x210/0x530 [intel_qat] adf_vf2pf_notify_restart_complete+0x55/0x80 [intel_qat] adf_dev_stop_async+0xdb/0x140 [intel_qat]
The notification cannot move before adf_dev_down(): the PF waits for it before its own reset and the VF must tear down its rings first.
vf2pf_lock protects the VF2PF CSR and is unrelated to the PF2VF bottom half it is initialised alongside. Tie its lifetime to the accel device, next to state_lock in adf_devmgr_add_dev()/adf_devmgr_rm_dev(), so it stays valid for messages sent outside the device up/down cycle. It is only touched for VFs, which set is_vf before adf_devmgr_add_dev() and keep it set until adf_devmgr_rm_dev().
--- drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c | 8 ++++++++ drivers/crypto/intel/qat/qat_common/adf_vf_isr.c | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_dev_mgr.c +8 -0
@@ -138,6 +138,12 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,mutex_lock (&table_lock);atomic_set (&accel_dev->ref_count,0 );mutex_init (&accel_dev->state_lock); +/* +* The VF2PF lock is used to send messages to the PF outside of the +* device up/down cycle, so it must live as long as the accel device. +*/ +if (accel_dev->is_vf) +mutex_init (&accel_dev->vf.vf2pf_lock);/* PF on host or VF on guest - optimized to remove redundant is_vf */ if (!accel_dev->is_vf || !pf) {
@@ -257,6 +263,8 @@ void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev, } } unlock: +if (accel_dev->is_vf) +mutex_destroy (&accel_dev->vf.vf2pf_lock);mutex_destroy (&accel_dev->state_lock);list_del (&accel_dev->list);mutex_unlock (&table_lock);
drivers/crypto/intel/qat/qat_common/adf_vf_isr.c +0 -2
@@ -118,7 +118,6 @@ static int adf_setup_pf2vf_bh(struct adf_accel_dev *accel_dev)tasklet_init (&accel_dev->vf.pf2vf_bh_tasklet, (void *)adf_pf2vf_bh_handler, (unsigned long )accel_dev); -mutex_init (&accel_dev->vf.vf2pf_lock);return 0 ; }
@@ -126,7 +125,6 @@ static void adf_cleanup_pf2vf_bh(struct adf_accel_dev *accel_dev) {tasklet_disable (&accel_dev->vf.pf2vf_bh_tasklet);tasklet_kill (&accel_dev->vf.pf2vf_bh_tasklet); -mutex_destroy (&accel_dev->vf.vf2pf_lock); }static irqreturn_t adf_isr (int irq,void *privdata)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 787/1257 irqchip/gic-v3-its: Dont clamp nvecs to zero when id_bits is 32
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 5a9d62555e7164ec79a5fe70153d79cf1fdfd614 ]
GITS_TYPER_IDBITS is five bits, so id_bits reaches 32 and min_t(unsigned int, ...) truncates BIT(32) to 0. nvecs becomes 0, its_lpi_alloc() rejects that, and its_msi_prepare() returns -ENOMEM. On 32-bit ARM the shift is undefined instead.
The clamp is correct for every value below the maximum, so only that one value is affected.
--- drivers/irqchip/irq-gic-v3-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -3484,7 +3484,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,* Also honor the ITS's own EID limit. */ id_bits =FIELD_GET (GITS_TYPER_IDBITS , its->typer) +1 ; - nvecs = min_t(unsigned int, nvecs, BIT(id_bits)); + nvecs =min_t (u64, nvecs,BIT_ULL (id_bits)); nr_ites =max (2 , nvecs); sz = nr_ites * (FIELD_GET (GITS_TYPER_ITT_ENTRY_SIZE , its->typer) +1 ); sz =max (sz,ITS_ITT_ALIGN );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 788/1257 irqchip/imx-intmux: Fix runtime PM teardown on remove
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit b167c1a30e9e020e4c5e102c7a555943742c024b ]
imx_intmux_probe() enables the IPG clock and then drops its runtime PM reference with pm_runtime_put(). With CONFIG_PM enabled, the runtime suspend callback disables the IPG clock. With CONFIG_PM disabled, the clock remains enabled after probe.
imx_intmux_remove() accesses the CHANIER registers without first making sure that the device is runtime active. The device may therefore be runtime suspended with the IPG clock disabled when these registers are accessed. In addition, the remove path only calls pm_runtime_disable() and does not balance the clock enable when CONFIG_PM is disabled.
Resume the device and acquire a runtime PM reference before accessing the registers. If resume fails, skip the register accesses but still tear down the chained handlers and IRQ domains. Disable runtime PM afterwards, drop the acquired reference without triggering another runtime suspend, and explicitly disable the IPG clock.
This keeps the clock enabled while the hardware registers are accessed and balances the clk_prepare_enable() performed during probe for both CONFIG_PM configurations.
This issue was found by manual code inspection.
--- drivers/irqchip/irq-imx-intmux.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/irqchip/irq-imx-intmux.c +12 -3
@@ -288,12 +288,16 @@ static int imx_intmux_probe(struct platform_device *pdev)static void imx_intmux_remove (struct platform_device *pdev) {struct intmux_data *data =platform_get_drvdata (pdev); -int i; +int i, ret; + + ret =pm_runtime_resume_and_get (&pdev->dev); +if (ret <0 ) +dev_warn (&pdev->dev,"failed to resume device: %d\n" , ret);for (i =0 ; i < data->channum; i++) {/* disable all interrupt sources of this channel */ -writel_relaxed (0 , data->regs +CHANIER (i)); - +if (ret >=0 ) +writel_relaxed (0 , data->regs +CHANIER (i));irq_set_chained_handler_and_data (data->irqchip_data[i].irq,NULL ,NULL );
@@ -301,6 +305,11 @@ static void imx_intmux_remove(struct platform_device *pdev) }pm_runtime_disable (&pdev->dev); +if (ret >=0 ) { +pm_runtime_put_noidle (&pdev->dev); +clk_disable_unprepare (data->ipg_clk); +pm_runtime_set_suspended (&pdev->dev); + } }#ifdef CONFIG_PM
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 789/1257 irqchip/mchp-eic: Fix clock reference leak in mchp_eic_probe()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit af9c707eb065a7d48eb92dc15acdb4346acf5db0 ]
of_clk_get_by_name() returns the clock with an elevated reference count that mchp_eic_probe() keeps for the lifetime of the driver, but none of the probe error paths drops it, so the reference is leaked whenever probe fails after the clock has been obtained.
Put the reference in the error cleanup. The clk_prepare_enable() failure path must jump there directly as it cannot call clk_disable_unprepare() on a clock that was never enabled.
--- drivers/irqchip/irq-mchp-eic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-mchp-eic.c +3 -1
@@ -233,7 +233,7 @@ static int mchp_eic_probe(struct platform_device *pdev, struct device_node *pare ret =clk_prepare_enable (eic->clk);if (ret) - goto unmap; + goto clk_put;for (i =0 ; i <MCHP_EIC_NIRQ ; i++) {struct of_phandle_args irq;
@@ -270,6 +270,8 @@ static int mchp_eic_probe(struct platform_device *pdev, struct device_node *pare clk_unprepare:clk_disable_unprepare (eic->clk); +clk_put: +clk_put (eic->clk); unmap:iounmap (eic->base); free:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 790/1257 irqchip/atmel-aic[5]: Disable interrupts in the irq_pm_shutdown() callbacks
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 0ca21fe111457c843624a835641bb490e704bb2f ]
irq_gc_shutdown() calls the irq_pm_shutdown() callbacks from syscore_shutdown() with interrupts enabled. aic_pm_shutdown() and aic5_pm_shutdown() take the generic chip lock with raw_spin_lock(), and irq_gc_eoi() takes the same lock from the interrupt handler. An interrupt from the chip while the lock is held spins in irq_gc_eoi() and hangs the reboot.
Lockdep reports this on every reboot of a SAM9X75 Curiosity board:
WARNING: inconsistent lock state
inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage. busybox/101 [HC0[0]:SC0[0]:HE1:SE1] takes:
c1c2b434 (&gc->lock){?.-.}-{2:2}, at: aic5_pm_shutdown+0x34/0xd8 {IN-HARDIRQ-W} state was registered at:
...
irq_gc_eoi+0x28/0x60
handle_fasteoi_irq+0x120/0x214 ...
aic5_pm_shutdown from irq_gc_shutdown+0x4c/0x58 irq_gc_shutdown from syscore_shutdown+0x5c/0x9c syscore_shutdown from kernel_restart+0x34/0x78 kernel_restart from sys_reboot+0x180/0x25c
Use the irqsave guard, as
commit 33517881ede7 ("irqchip/brcmstb-l2: Use _irqsave locking variants in non-interrupt code") did for brcmstb-l2.
--- drivers/irqchip/irq-atmel-aic.c | 2 +- drivers/irqchip/irq-atmel-aic5.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-atmel-aic.c +1 -1
@@ -123,7 +123,7 @@ static void aic_pm_shutdown(struct irq_data *d) {struct irq_chip_generic *gc =irq_data_get_irq_chip_data (d); -guard (raw_spinlock)(&gc->lock); +guard (raw_spinlock_irqsave)(&gc->lock);irq_reg_writel (gc,0xffffffff ,AT91_AIC_IDCR );irq_reg_writel (gc,0xffffffff ,AT91_AIC_ICCR ); }
drivers/irqchip/irq-atmel-aic5.c +1 -1
@@ -217,7 +217,7 @@ static void aic5_pm_shutdown(struct irq_data *d)struct irq_chip_generic *gc =irq_data_get_irq_chip_data (d);int i; -guard (raw_spinlock)(&bgc->lock); +guard (raw_spinlock_irqsave)(&bgc->lock);for (i =0 ; i < dgc->irqs_per_chip; i++) {irq_reg_writel (bgc, i + gc->irq_base,AT91_AIC5_SSR );irq_reg_writel (bgc,1 ,AT91_AIC5_IDCR );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 791/1257 irqchip/jcore-aic: Fix lost IPIs on SMP
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit f556f008f704a8777c73fb3a4177dc57c0dbe769 ]
Since commit bdf4e2ac295fe ("genirq: Allow per-cpu interrupt sharing for non-overlapping affinities"), handle_percpu_devid_irq() only runs an action whose affinity mask contains the current CPU. Only actions set up through the percpu_devid request functions have such a mask.
handle_jcore_irq() passes every per-CPU interrupt to handle_percpu_devid_irq(). The J2 IPI is not a percpu_devid interrupt. j2_prepare_cpus() requests it with request_irq() and IRQF_PERCPU, so its action has no affinity mask and cpumask_test_cpu() reads through a NULL pointer. J2 has no MMU to catch this. The read returns whatever is at address 0, the action is not found, and IPIs are dropped as spurious ("Spurious percpu IRQ20 on CPU1", printed once).
Pass only percpu_devid interrupts (the PIT) to handle_percpu_devid_irq() and the other per-CPU interrupts to handle_percpu_irq() again, as before commit d7e3fd658248f ("irqchip/jcore-aic, clocksource/drivers/jcore: Fix jcore-pit interrupt request").
Found with a two-CPU J2 model simulated from the J-Core RTL. Without this change the boot stalls with both CPUs idle shortly after "smp: Brought up 1 node, 2 CPUs". With it, the boot reaches userspace.
--- drivers/irqchip/irq-jcore-aic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-jcore-aic.c +3 -1
@@ -37,8 +37,10 @@ static struct irq_chip jcore_aic;static void handle_jcore_irq (struct irq_desc *desc) { -if (irqd_is_per_cpu (irq_desc_get_irq_data (desc))) +if (irq_is_percpu_devid (irq_desc_get_irq (desc)))handle_percpu_devid_irq (desc); +else if (irqd_is_per_cpu (irq_desc_get_irq_data (desc))) +handle_percpu_irq (desc);else handle_simple_irq (desc); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 792/1257 irqchip/renesas-rzv2h: Preserve TIEN state in rzv2h_tint_set_type()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Au Dang <[email protected]>
[ Upstream commit 42bedd4af8cd50c32a1560d8744bd22d25be79cc ]
rzv2h_tint_set_type() clears TIEN while switching the TINT source and then unconditionally sets it again, enabling the interrupt even if it was disabled before the call.
Restore the previous TIEN state instead of forcing it on.
--- drivers/irqchip/irq-renesas-rzv2h.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/irqchip/irq-renesas-rzv2h.c +4 -2
@@ -420,9 +420,9 @@ static void rzv2h_clear_tint_int(struct rzv2h_icu_priv *priv, unsigned int hwirqstatic int rzv2h_tint_set_type (struct irq_data *d,unsigned int type) {u32 titsr, titsr_k, titsel_n, tien; +u32 titsr_cur, tssr_cur, tien_cur;struct rzv2h_icu_priv *priv;u32 tssr, tssr_k, tssel_n; -u32 titsr_cur, tssr_cur;unsigned int hwirq;u32 tint, sense;int tint_nr;
@@ -477,6 +477,8 @@ static int rzv2h_tint_set_type(struct irq_data *d, unsigned int type)if (tssr_cur == tint && titsr_cur == sense) goto set_parent_type; + tien_cur = tssr & tien; + tssr &= ~(ICU_TSSR_TSSEL_MASK (tssel_n, priv->info->field_width) | tien); tssr |=ICU_TSSR_TSSEL_PREP (tint, tssel_n, priv->info->field_width);
@@ -489,7 +491,7 @@ static int rzv2h_tint_set_type(struct irq_data *d, unsigned int type)rzv2h_clear_tint_int (priv, hwirq); -writel_relaxed (tssr | tien, priv->base + priv->info->t_offs +ICU_TSSR (tssr_k)); +writel_relaxed (tssr | tien_cur, priv->base + priv->info->t_offs +ICU_TSSR (tssr_k)); } set_parent_type:return irq_chip_set_type_parent (d,IRQ_TYPE_LEVEL_HIGH );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 793/1257 ALSA: ump: Correct return size of fill_rpn()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 85e8c5f933ee3dbc9d061e121237797e9fa05315 ]
The RPN/NRPN conversion in fill_rpn() is supposed to return the number of bytes of the resultant UMP packet, but it returns boolean values. This would result in the incorrect ump_bytes in the converter, which will confuse stream processing. Correct to the right value 8 as a MIDI 2.0 UMP packet.
--- sound/core/ump_convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/ump_convert.c +1 -1
@@ -323,7 +323,7 @@ static int fill_rpn(struct ump_cvt_to_ump_bank *cc, cc->cc_data_lsb);reset_rpn (cc); -return 1 ; +return 8 ; }/* convert to a MIDI 1.0 Channel Voice message */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 794/1257 gfs2: fix the escaped block copy in gfs2_before_commit()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit 1a4aeb6d6a08af1a2e2c52c84170561625819377 ]
Commit d68d0c6c3fc7 ("gfs2: Use memcpy_{from,to}_page where appropriate") made the escaped buffer copy read from the mempool page it had just allocated instead of from the buffer, so the block written to the log is whatever the pool page last held. If the journal is replayed after a crash, the block is restored from that and the file's data is corrupted. Only escaped buffers are affected: jdata blocks whose first four bytes match GFS2_MAGIC. Copy from the buffer's folio instead.
--- fs/gfs2/lops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/lops.c +3 -1
@@ -689,7 +689,9 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit, page =mempool_alloc (gfs2_page_pool,GFP_NOIO ); p =page_address (page); -memcpy_from_page (p, page,bh_offset (bd2->bd_bh), bd2->bd_bh->b_size); +memcpy_from_folio (p, bd2->bd_bh->b_folio, +bh_offset (bd2->bd_bh), + bd2->bd_bh->b_size); *(__be32 *)p =0 ;clear_buffer_escaped (bd2->bd_bh);unlock_buffer (bd2->bd_bh);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 795/1257 spi: jcore: fix divide-by-zero when speed_hz is zero
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit 7db773075501248893c22b11bedc6745d6d0be45 ]
jcore_spi_baudrate() computes hw->clock_freq / 2 / speed without validating speed. The SPI core fills transfer.speed_hz from spi->max_speed_hz when it is zero, and jcore_spi_probe() never sets host->max_speed_hz, so the clamp in __spi_setup() is skipped. A spi_device created via the sysfs new_device interface (or a DT node without spi-max-frequency) therefore has max_speed_hz == 0, and any SPI_IOC_MESSAGE transfer reaches jcore_spi_baudrate() with speed == 0, causing a division by zero and a kernel panic.
Clamp speed to a minimum of 1 Hz before the division so the divisor is never zero. The computed divider then truncates to the register field width and the transfer simply runs at the slowest supported rate.
Verified by inspection of the __spi_setup() clamp and __spi_validate()'s speed_hz handling; the division-by-zero path requires the J-Core controller, which was not available.
--- drivers/spi/spi-jcore.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/spi/spi-jcore.c +2 -0
@@ -84,6 +84,8 @@ static void jcore_spi_baudrate(struct jcore_spi *hw, int speed) {if (speed == hw->speed_hz)return ; +if (speed <=0 ) + speed =1 ; hw->speed_hz = speed;if (speed >= hw->clock_freq /2 ) hw->speed_reg =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 796/1257 efi/libstub: arm64: Dont use the platform register x18
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit 4c86b5f3fa78347fa9cbc9e8ec06615b2f80e397 ]
The UEFI specification designates x18, the platform register, as "do not use" on AArch64, so that UEFI code is compatible both with an OS that assigns a fixed role to x18, and with one that uses it as a temporary register.
The arm64 EFI stub and the EFI zboot decompressor only avoid x18 if the kernel is built with shadow call stacks, as that is the only case where -ffixed-x18 is added to KBUILD_CFLAGS, which the stub inherits. Otherwise, the compiler is free to use x18 as a temporary register, and it does so.
So pass -ffixed-x18 unconditionally when building the stub for arm64, so that the image can be run by loaders that rely on x18 being left alone, such as a kernel that uses it for its shadow call stack.
--- drivers/firmware/efi/libstub/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/Makefile +1 -1
@@ -21,7 +21,7 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ $(CC_FLAGS_DIALECT) \ # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly # disable the stackleak plugin -cflags-$(CONFIG_ARM64) += -fpie $(DISABLE_KSTACK_ERASE) \ +cflags-$(CONFIG_ARM64) += -fpie $(DISABLE_KSTACK_ERASE) -ffixed-x18 \ -fno-unwind-tables -fno-asynchronous-unwind-tables cflags-$(CONFIG_ARM) += -DEFI_HAVE_STRLEN -DEFI_HAVE_STRNLEN \ -DEFI_HAVE_MEMCHR -DEFI_HAVE_STRRCHR \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 797/1257 efi/libstub: Dont replace an existing LINUX_EFI_MEMRESERVE table
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit aaf3ed0f46298e18ec8bc477cf0a37478e41f2ea ]
The LINUX_EFI_MEMRESERVE table is the root of a linked list of memory reservations that need to persist across kexec, such as the GICv3 LPI pending and property tables, which cannot be moved once the redistributors have been enabled. Each kernel adds its own reservations to the list that it finds via the EFI configuration table, and honours the ones made by its predecessors.
The EFI stub installs a new, empty table unconditionally, replacing any existing one. This is fine on a cold boot, but not if the stub is being executed by a loader that passes on the configuration tables of an earlier kernel, e.g., a kexec loader that runs the incoming kernel's EFI stub, as the reservations made by earlier kernels would be lost.
So leave an existing table in place, and only install a new one if none exists yet.
--- drivers/firmware/efi/libstub/efi-stub.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/firmware/efi/libstub/efi-stub.c +8 -0
@@ -83,6 +83,14 @@ static void install_memreserve_table(void)efi_guid_t memreserve_table_guid =LINUX_EFI_MEMRESERVE_TABLE_GUID ;efi_status_t status; +/* +* If an earlier boot stage installed a memreserve table already, e.g., +* a kexec loader passing on the persistent reservations made by the +* previous kernel, use it as is: installing a new one would replace it. +*/ +if (get_efi_config_table (memreserve_table_guid)) +return ; + status =efi_bs_call (allocate_pool,EFI_LOADER_DATA ,sizeof (*rsv), (void **)&rsv);if (status !=EFI_SUCCESS ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 798/1257 KVM: arm64: nv: Move L2->L1 switch on interrupt early
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 21d3b33234ebbb675c2a2a0fa7b12d2d83953d7a ]
NV request generation to switch from L2 to L1 on interrupt is buried into the vgic flush code, while we should be able to deliver requests as early as possible.
Similarly, MI generation happens *after* the need for a request has been evaluated, which means we potentially delay the maintenance interrupt by a full exit/entry cycle.
Move these two things to happen much earlier in the entry code, and make sure the MI generation and PMU interrupt serve as input to the request switching back from L2 to L1.
--- arch/arm64/kvm/arm.c | 4 ++-- arch/arm64/kvm/nested.c | 8 ++++++++ arch/arm64/kvm/vgic/vgic.c | 8 +------- 3 files changed, 11 insertions(+), 9 deletions(-)
arch/arm64/kvm/arm.c +2 -2
@@ -1314,11 +1314,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)*/ preempt_disable (); -kvm_nested_flush_hwstate (vcpu); -if (kvm_vcpu_has_pmu (vcpu))kvm_pmu_flush_hwstate (vcpu); +kvm_nested_flush_hwstate (vcpu); +local_irq_disable ();kvm_vgic_flush_hwstate (vcpu);
arch/arm64/kvm/nested.c +8 -0
@@ -2045,6 +2045,9 @@ void check_nested_vcpu_requests(struct kvm_vcpu *vcpu)* * What follows is some slop to (1) react to exception routing / masking and (2) * preserve the pending SError state across translation regimes. +* +* Also generate the maintenance interrupt state, and finally check that if +* we need to take an interrupt targetting the guest hypervisor. */ void kvm_nested_flush_hwstate (struct kvm_vcpu *vcpu) {
@@ -2053,6 +2056,11 @@ void kvm_nested_flush_hwstate(struct kvm_vcpu *vcpu)if (unlikely (vcpu_test_and_clear_flag (vcpu,NESTED_SERROR_PENDING )))kvm_inject_serror_esr (vcpu,vcpu_get_vsesr (vcpu)); + +vgic_v3_nested_update_mi (vcpu); + +if (vgic_state_is_nested (vcpu) &&kvm_vgic_vcpu_pending_irq (vcpu)) +kvm_make_request (KVM_REQ_GUEST_HYP_IRQ_PENDING , vcpu); }void kvm_nested_sync_hwstate (struct kvm_vcpu *vcpu)
arch/arm64/kvm/vgic/vgic.c +1 -7
@@ -1152,7 +1152,7 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)* * We do that by placing a request to ourselves which will * abort the entry procedure and inject the exception at the -* beginning of the run loop. +* beginning of the run loop (see kvm_nested_flush_hwstate()). * * - Otherwise, do exactly *NOTHING* apart from enabling the virtual * CPU interface. The guest state is already loaded, and we can
@@ -1162,16 +1162,10 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)* maintenance interrupt state, as it may fire. */ if (vgic_state_is_nested (vcpu)) { -if (kvm_vgic_vcpu_pending_irq (vcpu)) -kvm_make_request (KVM_REQ_GUEST_HYP_IRQ_PENDING , vcpu); -vgic_v3_flush_nested (vcpu);return ; } -if (vcpu_has_nv (vcpu)) -vgic_v3_nested_update_mi (vcpu); -DEBUG_SPINLOCK_BUG_ON (!irqs_disabled ());vgic_flush_state (vcpu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 799/1257 KVM: arm64: Move OUTSIDE_GUEST_MODE publication past context being saved
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 1d4ce2901f1e25b06d447c0b02d105d6dd3550d8 ]
OUTSIDE_GUEST_MODE indicates to the rest of KVM that the vcpu has exited. So far, this is set as soon as we return from the notional hypervisor (which with VHE is just a function call away).
However, code that uses OUTSIDE_GUEST_MODE as a synchronisation point relies on the vcpu state to have been written back to the in-memory structures. Clearly, this is not what is happening.
Move the publication of OUTSIDE_GUEST_MODE to the point where the state is actually written, and give this write release semantics to ensure the correct ordering.
--- arch/arm64/kvm/arm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/arm64/kvm/arm.c +8 -2
@@ -1334,13 +1334,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)smp_store_mb (vcpu->mode,IN_GUEST_MODE );if (ret <=0 ||kvm_vcpu_exit_request (vcpu, &ret)) { - vcpu->mode =OUTSIDE_GUEST_MODE ;isb ();/* Ensure work in x_flush_hwstate is committed */ if (kvm_vcpu_has_pmu (vcpu))kvm_pmu_sync_hwstate (vcpu);if (unlikely (!irqchip_in_kernel (vcpu->kvm)))kvm_timer_sync_user (vcpu);kvm_vgic_sync_hwstate (vcpu); +smp_store_release (&vcpu->mode,OUTSIDE_GUEST_MODE );local_irq_enable ();preempt_enable ();continue ;
@@ -1356,7 +1356,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) ret =kvm_arm_vcpu_enter_exit (vcpu); - vcpu->mode =OUTSIDE_GUEST_MODE ; vcpu->stat.exits++;/* * Back from guest
@@ -1390,6 +1389,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)kvm_arch_vcpu_ctxsync_fp (vcpu); +/* +* The state that was pushed into the CPU on entering +* the guest has been synchronised back, let's +* advertise we're outside of the guest. +*/ +smp_store_release (&vcpu->mode,OUTSIDE_GUEST_MODE ); +/* * We must ensure that any pending interrupts are taken before * we exit guest timing so that timer ticks are accounted as
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 800/1257 KVM: arm64: Move IN_GUEST_MODE ahead of state being loaded
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 22b6557ad05bf05c73246f62c19af3e04017270e ]
IN_GUEST_MODE is advertised too late, when state has already been moved onto CPU registers and cannot be observed by another CPU anymore.
Move the IN_GUEST_MODE publication ahead of the state being loaded, and immediately check for pending request. This ensures that there is no window of opportunity for another CPU to observe OUTSIDE_GUEST_MODE and yet for state to be loaded.
This also simplifies the "state rollback", which solely amounts to synchronising the timer when no irqchip is present.
--- arch/arm64/kvm/arm.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
arch/arm64/kvm/arm.c +10 -8
@@ -1321,31 +1321,33 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)local_irq_disable (); -kvm_vgic_flush_hwstate (vcpu); - -kvm_pmu_update_vcpu_events (vcpu); -/* * Ensure we set mode to IN_GUEST_MODE after we disable * interrupts and before the final VCPU requests check. * See the comment in kvm_vcpu_exiting_guest_mode() and * Documentation/virt/kvm/vcpu-requests.rst +* +* Requests to self must be posted before this point, or +* won't be taken into account until the next exit. No state +* loading other than what happens at vcpu_load() time can +* be done before we have checked for pending requests. */ smp_store_mb (vcpu->mode,IN_GUEST_MODE );if (ret <=0 ||kvm_vcpu_exit_request (vcpu, &ret)) { -isb ();/* Ensure work in x_flush_hwstate is committed */ -if (kvm_vcpu_has_pmu (vcpu)) -kvm_pmu_sync_hwstate (vcpu);if (unlikely (!irqchip_in_kernel (vcpu->kvm)))kvm_timer_sync_user (vcpu); -kvm_vgic_sync_hwstate (vcpu);smp_store_release (&vcpu->mode,OUTSIDE_GUEST_MODE );local_irq_enable ();preempt_enable ();continue ; } +/* From here onwards, we are commited to entering the guest */ +kvm_vgic_flush_hwstate (vcpu); + +kvm_pmu_update_vcpu_events (vcpu); +kvm_arch_vcpu_ctxflush_fp (vcpu);/**************************************************************
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 801/1257 KVM: arm64: Turn vcpu->arch.pause into a counter
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit e64309198eda29415a95113def92aa40196cd422 ]
We have situations where we can call kvm_arm_halt_guest() without holding config_lock, which means that halt and resume can overlap in funny ways when called from separate contexts, and result in situations where a vcpu is resumed while other parts of KVM assume it is halted. Consequences are left to the imagination of the reader.
Fix this sorry situation by turning kvm_vcpu_arch::pause into an atomic counter, which makes the races described above harmless.
--- arch/arm64/include/asm/kvm_host.h | 7 +++---- arch/arm64/kvm/arm.c | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-)
arch/arm64/include/asm/kvm_host.h +3 -4
@@ -889,11 +889,10 @@ struct kvm_vcpu_arch {/* * Don't run the guest (internal implementation need). * -* Contrary to the flags above, this is set/cleared outside of -* a vcpu context, and thus cannot be mixed with the flags -* themselves (or the flag accesses need to be made atomic). +* Contrary to the flags above, this is updated outside of +* a vcpu context, and thus cannot be mixed with the flags. */ -bool pause; +atomic_t pause;/* * We maintain more than a single set of debug registers to support
arch/arm64/kvm/arm.c +12 -9
@@ -565,6 +565,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)kvm_arm_pvtime_vcpu_init (&vcpu->arch); vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; +atomic_set (&vcpu->arch.pause,0 );/* * This vCPU may have been created after mpidr_data was initialized.
@@ -839,6 +840,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,return ret; } +static bool vcpu_can_run (struct kvm_vcpu *vcpu) +{ +return !kvm_arm_vcpu_stopped (vcpu) && !atomic_read (&vcpu->arch.pause); +} +/** * kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled * @v: The VCPU pointer
@@ -854,8 +860,7 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) (kvm_timer_should_notify_user (v) || kvm_pmu_should_notify_user(v))); -return ((irq_lines ||kvm_vgic_vcpu_pending_irq (v)) - && !kvm_arm_vcpu_stopped (v) && !v->arch.pause); +return ((irq_lines ||kvm_vgic_vcpu_pending_irq (v)) &&vcpu_can_run (v)); }bool kvm_arch_vcpu_in_kernel (struct kvm_vcpu *vcpu)
@@ -1018,7 +1023,7 @@ void kvm_arm_halt_guest(struct kvm *kvm)struct kvm_vcpu *vcpu;kvm_for_each_vcpu (i, vcpu, kvm) - vcpu->arch.pause = true; +atomic_inc (&vcpu->arch.pause);kvm_make_all_cpus_request (kvm,KVM_REQ_SLEEP ); }
@@ -1028,8 +1033,8 @@ void kvm_arm_resume_guest(struct kvm *kvm)struct kvm_vcpu *vcpu;kvm_for_each_vcpu (i, vcpu, kvm) { - vcpu->arch.pause = false; -__kvm_vcpu_wake_up (vcpu); +if (atomic_dec_and_test (&vcpu->arch.pause)) +__kvm_vcpu_wake_up (vcpu); } }
@@ -1037,11 +1042,9 @@ static void kvm_vcpu_sleep(struct kvm_vcpu *vcpu) {struct rcuwait *wait =kvm_arch_vcpu_get_wait (vcpu); -rcuwait_wait_event (wait, - (!kvm_arm_vcpu_stopped (vcpu)) && (!vcpu->arch.pause), -TASK_INTERRUPTIBLE ); +rcuwait_wait_event (wait,vcpu_can_run (vcpu),TASK_INTERRUPTIBLE ); -if (kvm_arm_vcpu_stopped (vcpu) || vcpu->arch.pause) { +if (!vcpu_can_run (vcpu)) {/* Awaken to handle a signal, request we sleep again later. */ kvm_make_request (KVM_REQ_SLEEP , vcpu); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 802/1257 spi: npcm-fiu: limit UMA data_size to the 16-byte staging buffer
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit f0be928a41384ea93c876364f360779f70359249 ]
npcm_fiu_uma_read() and npcm_fiu_uma_write() use a 16-byte on-stack staging buffer (u32 data_reg[4]) and move data_size bytes to or from it. data_size comes straight from op->data.nbytes, which is supplied by the SPI MEM operation and is not bounded by the driver:npcm_fiu_exec_op() only validates op->addr.nbytes, and no adjust_op_size callback truncates the transfer to the controller FIFO size.
A SPI MEM operation with addr.nbytes == 0 and data.nbytes > 16 therefore overflows data_reg[] on the kernel stack (write path) or reads past it (read path), corrupting the stack.
Reject data_size larger than the staging buffer in both UMA helpers by returning -EOPNOTSUPP, so spi_mem falls back to the generic SPI message path. The chunked path in npcm_fiu_manualwrite() always passes at most CHUNK_SIZE bytes, so it is unaffected.
--- drivers/spi/spi-npcm-fiu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/spi-npcm-fiu.c +8 -0
@@ -343,6 +343,10 @@ static int npcm_fiu_uma_read(struct spi_mem *mem,u32 val;u32 i; +/* data_reg holds at most 16 bytes */ +if (data_size >sizeof (data_reg)) +return -EOPNOTSUPP ; + regmap_update_bits(fiu->regmap, NPCM_FIU_UMA_CTS, NPCM_FIU_UMA_CTS_DEV_NUM, (spi_get_chipselect(mem->spi, 0) <<
@@ -398,6 +402,10 @@ static int npcm_fiu_uma_write(struct spi_mem *mem,u32 val;u32 i; +/* data_reg holds at most 16 bytes */ +if (data_size >sizeof (data_reg)) +return -EOPNOTSUPP ; + regmap_update_bits(fiu->regmap, NPCM_FIU_UMA_CTS, NPCM_FIU_UMA_CTS_DEV_NUM, (spi_get_chipselect(mem->spi, 0) <<
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 803/1257 mfd: bq257xx: Mark self-modifying BQ25792 registers volatile
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
[ Upstream commit 56d974f3ad074a60bf877d131eab8b1df5b4f069 ]
Some BQ25792 configuration registers change without being written: input source detection sets VINDPM and IINDPM at plug-in, plug-in also clears EN_HIZ, the FORCE_* bits clear once their operation starts or completes, EN_ACDRV1/2 follow input path changes, and ADC_EN clears after a one-shot conversion. Reading them from the cache returns stale values.
Mark these registers volatile, keeping the cache for the rest.
--- drivers/mfd/bq257xx.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/mfd/bq257xx.c +10 -0
@@ -52,8 +52,18 @@ static const struct regmap_access_table bq25792_writeable_regs = { };static const struct regmap_range bq25792_volatile_reg_ranges[] = { +regmap_reg_range (BQ25792_REG05_INPUT_VOLTAGE_LIMIT , +BQ25792_REG06_INPUT_CURRENT_LIMIT +1 ), +regmap_reg_range (BQ25792_REG0F_CHARGER_CONTROL_0 , +BQ25792_REG0F_CHARGER_CONTROL_0 ), +regmap_reg_range (BQ25792_REG11_CHARGER_CONTROL_2 , +BQ25792_REG11_CHARGER_CONTROL_2 ), +regmap_reg_range (BQ25792_REG13_CHARGER_CONTROL_4 , +BQ25792_REG13_CHARGER_CONTROL_4 ),regmap_reg_range (BQ25792_REG19_ICO_CURRENT_LIMIT ,BQ25792_REG27_FAULT_FLAG_1 ), +regmap_reg_range (BQ25792_REG2E_ADC_CONTROL , +BQ25792_REG2E_ADC_CONTROL ),regmap_reg_range (BQ25792_REG31_IBUS_ADC ,BQ25792_REG47_DPDM_DRIVER ), };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 804/1257 cxl/events: Test CME counter expiry with equality, not bitwise AND
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit b94ba9a1f2d5c57f2eec67d502bb8fdd1e53c87a ]
The Memory Event Type field in the General Media and DRAM event records is an enumeration, not a bitmask. The validity checks for the advanced programmable CME counter expiration event (05h) test the field with a bitwise AND, so types 01h, 03h, 04h and 06h match it as well.
A device reporting one of those types trips WARN_ON_ONCE once the general media or DRAM tracepoint is enabled, which is the case anywhere rasdaemon collects CXL events. Under panic_on_warn=1 that kills the machine.
Compare the type field for equality instead. Type 05h records that do violate the spec conditions still warn.
--- drivers/cxl/core/mbox.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/core/mbox.c +4 -4
@@ -942,11 +942,11 @@ void cxl_event_trace_record(struct cxl_memdev *cxlmd,if (evt->gen_media.media_hdr.descriptor &CXL_GMER_EVT_DESC_THRESHOLD_EVENT ) -WARN_ON_ONCE ((evt->gen_media.media_hdr.type & +WARN_ON_ONCE ((evt->gen_media.media_hdr.type ==CXL_GMER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ) && !get_unaligned_le24 (evt->gen_media.cme_count));else -WARN_ON_ONCE (evt->gen_media.media_hdr.type & +WARN_ON_ONCE (evt->gen_media.media_hdr.type ==CXL_GMER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ); trace_cxl_general_media(cxlmd, type, cxlr, hpa,
@@ -957,11 +957,11 @@ void cxl_event_trace_record(struct cxl_memdev *cxlmd,if (evt->dram.media_hdr.descriptor &CXL_GMER_EVT_DESC_THRESHOLD_EVENT ) -WARN_ON_ONCE ((evt->dram.media_hdr.type & +WARN_ON_ONCE ((evt->dram.media_hdr.type ==CXL_DER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ) && !get_unaligned_le24 (evt->dram.cvme_count));else -WARN_ON_ONCE (evt->dram.media_hdr.type & +WARN_ON_ONCE (evt->dram.media_hdr.type ==CXL_DER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE ); trace_cxl_dram(cxlmd, type, cxlr, hpa, hpa_alias,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 805/1257 mfd: tps65217: Fix NULL pointer dereference on IRQ init failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radiy Zhambakiev <[email protected]>
[ Upstream commit 0473a5b0663663b75573bf284beb77459e07c461 ]
tps65217_probe() ignores the return value of tps65217_irq_init(), so when the irq domain creation fails the probe still completes and the driver ends up bound with a NULL tps->irq_domain. Unloading the module then makes tps65217_remove() call irq_domain_remove() on the NULL pointer and oops the kernel. On top of that, irq_find_mapping() may fall back to the default irq domain and dispose of mappings that belong to other interrupt controllers.
Check the return value and abort the probe on failure so the error is reported and no inconsistent state is left for removal.
--- drivers/mfd/tps65217.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/tps65217.c +3 -1
@@ -333,7 +333,9 @@ static int tps65217_probe(struct i2c_client *client) }if (client->irq) { -tps65217_irq_init (tps, client->irq); + ret =tps65217_irq_init (tps, client->irq); +if (ret) +return ret; }else {int i;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 806/1257 mfd: tps65217: Check return value when masking interrupt sources
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radiy Zhambakiev <[email protected]>
[ Upstream commit 66ed12c1e5a986bee1dc63f9bd9c7f068138a69a ]
tps65217_irq_init() ignores the error returned by tps65217_set_bits() when masking all interrupt sources. A failed register write leaves the driver's software mask out of sync with the hardware and may result in spurious interrupts.
Check the return value and propagate the error to the caller.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/mfd/tps65217.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mfd/tps65217.c +6 -2
@@ -155,8 +155,12 @@ static int tps65217_irq_init(struct tps65217 *tps, int irq)/* Mask all interrupt sources */ tps->irq_mask =TPS65217_INT_MASK ; -tps65217_set_bits (tps,TPS65217_REG_INT ,TPS65217_INT_MASK , -TPS65217_INT_MASK ,TPS65217_PROTECT_NONE ); + ret =tps65217_set_bits (tps,TPS65217_REG_INT ,TPS65217_INT_MASK , +TPS65217_INT_MASK ,TPS65217_PROTECT_NONE ); +if (ret) { +dev_err (tps->dev,"Failed to mask interrupt sources: %d\n" , ret); +return ret; + } tps->irq_domain =irq_domain_create_linear (dev_fwnode (tps->dev),TPS65217_NUM_IRQ , &tps65217_irq_domain_ops, tps);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 807/1257 mfd: tps65217: Use devres for IRQ domain and wake teardown
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radiy Zhambakiev <[email protected]>
[ Upstream commit cffd44d2d89524e2dda6adc7b0dd59363be1c8e6 ]
Removing the parent device used to tear the IRQ domain down in tps65217_remove() before the MFD children are unbound: the i2c core only releases the parent's devres after the remove callback returns, whereas devm_mfd_add_devices() registered its own devres action which unbinds the children. Children that requested interrupts from the domain (e.g. tps65217-charger) therefore call free_irq() on virtual IRQs whose descriptors have already been disposed. With CONFIG_SPARSE_IRQ free_irq() then returns early without stopping the threaded handler, leaking the irqaction, the IRQ kthread and a module reference.
Register the domain teardown as a devres action right after the domain is created instead. Devres actions are released in reverse order of registration, so the MFD children release their IRQs first, then the parent interrupt is freed and its thread stopped, and only then is the domain torn down. The same ordering covers probe failure, which no longer needs manual cleanup, and the remove callback can be dropped entirely.
Balance the enable_irq_wake() in tps65217_irq_init() by registering disable_irq_wake() as a devres action as well. Only do so when enabling actually succeeded, since the parent chip may not support setting wake-up.
--- drivers/mfd/tps65217.c | 57 +++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-)
drivers/mfd/tps65217.c +39 -18
@@ -146,6 +146,31 @@ static const struct irq_domain_ops tps65217_irq_domain_ops = { .map = tps65217_irq_map, }; +static void tps65217_irq_cleanup (void *data) +{ +struct tps65217 *tps = data; +unsigned int virq; + +if (!tps->irq_domain) +return ; + +for (int i =0 ; i <TPS65217_NUM_IRQ ; i++) { + virq =irq_find_mapping (tps->irq_domain, i); +if (virq) +irq_dispose_mapping (virq); + } + +irq_domain_remove (tps->irq_domain); + tps->irq_domain =NULL ; +} + +static void tps65217_irq_wake_disable (void *data) +{ +unsigned long irq = (unsigned long )data; + +disable_irq_wake (irq); +} +static int tps65217_irq_init (struct tps65217 *tps,int irq) {int ret;
@@ -169,6 +194,10 @@ static int tps65217_irq_init(struct tps65217 *tps, int irq)return -ENOMEM ; } + ret =devm_add_action_or_reset (tps->dev, tps65217_irq_cleanup, tps); +if (ret) +return ret; + ret =devm_request_threaded_irq (tps->dev, irq,NULL , tps65217_irq_thread,IRQF_ONESHOT ,"tps65217-irq" , tps);
@@ -178,7 +207,16 @@ static int tps65217_irq_init(struct tps65217 *tps, int irq)return ret; } -enable_irq_wake (irq); + ret =enable_irq_wake (irq); +if (ret) { +dev_warn (tps->dev,"failed to enable IRQ wake: %d\n" , ret); +return 0 ; + } + + ret =devm_add_action_or_reset (tps->dev, tps65217_irq_wake_disable, + (void *)(unsigned long )irq); +if (ret) +return ret;return 0 ; }
@@ -379,22 +417,6 @@ static int tps65217_probe(struct i2c_client *client)return 0 ; } -static void tps65217_remove (struct i2c_client *client) -{ -struct tps65217 *tps =i2c_get_clientdata (client); -unsigned int virq; -int i; - -for (i =0 ; i <TPS65217_NUM_IRQ ; i++) { - virq =irq_find_mapping (tps->irq_domain, i); -if (virq) -irq_dispose_mapping (virq); - } - -irq_domain_remove (tps->irq_domain); - tps->irq_domain =NULL ; -} -static const struct i2c_device_id tps65217_id_table[] = { {"tps65217" ,TPS65217 }, {/* sentinel */ }
@@ -408,7 +430,6 @@ static struct i2c_driver tps65217_driver = { }, .id_table = tps65217_id_table, .probe = tps65217_probe, - .remove = tps65217_remove, };static int __init tps65217_init (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 808/1257 ASoC: qcom: q6apm-dai: wrap the position of a full ring to 0
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladyslav Tymoshchuk <[email protected]>
[ Upstream commit 0ea3e0b196f9dcc17b40ac881a6efef06459975b ]
q6apm_dai_pointer() turns the number of period buffers the DSP has returned in the current lap, 1..periods, into a position and reports one frame less than that. Commit a93dad6f4e6a ("ASoC: q6apm-dai: make use of q6apm_get_hw_pointer") added the "- 1" so that the end of the ring is not reported as a position equal to the buffer size.
One frame short has a cost once the application stops feeding the stream. The DSP returns the last queued buffer and the position stops at appl_ptr - 1, so avail stays at buffer_size - 1, below the default stop_threshold. The DSP sends nothing more as its queue is empty, so no period interrupt comes either: ALSA never detects the underrun and the stream stays RUNNING. A poll-driven application that missed its last wakeup waits forever, and drain only ends on its timeout, with -EIO. On capture, the last frame of each period is held back until the next one.
Before that commit the position wrapped to 0 at the end of the ring. Do that again. A full lap is the start of the ring, and snd_pcm_update_hw_ptr0() accounts for the wrap: the position cannot move by more than one lap between two updates, as each returned buffer calls snd_pcm_period_elapsed() and the DSP holds at most periods buffers.
Seen on a OnePlus Pad 3 (SM8750) with PipeWire in interrupt-driven
scheduling: after a stall the PCM sat at hw_ptr 78239, appl_ptr 78240 (avail 3839 of 3840) for two hours.
--- sound/soc/qcom/qdsp6/q6apm-dai.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
sound/soc/qcom/qdsp6/q6apm-dai.c +8 -4
@@ -498,11 +498,15 @@ static snd_pcm_uframes_t q6apm_dai_pointer(struct snd_soc_component *component, ptr =bytes_to_frames (runtime, index);return ptr; } - ptr =q6apm_get_hw_pointer (prtd->graph, substream->stream) * runtime->period_size; -if (ptr) -return ptr -1 ; +/* +* The hw pointer counts the period buffers the DSP has returned in +* this lap, 1..periods. A full lap is the start of the ring again: +* report 0 rather than one frame less, so that the position of a +* drained buffer reaches appl_ptr and ALSA sees the underrun. +*/ + ptr =q6apm_get_hw_pointer (prtd->graph, substream->stream) % runtime->periods; -return 0 ; +return ptr * runtime->period_size; } static int q6apm_dai_hw_params(struct snd_soc_component *component,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 809/1257 ASoC: qcom: q6apm: reset the hw pointer with the fragment queue
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladyslav Tymoshchuk <[email protected]>
[ Upstream commit 0337b8129cf676b8eb767b2a1f312955760a5460 ]
On every prepare in queue mode, q6apm_dai_prepare() frees and allocates the fragments again, and q6apm_alloc_fragments() resets dsp_buf, so the first buffer queued after it is the first one of the ring. The hw pointer that q6apm_dai_pointer() reports is left as it was.
q6apm-dai used to keep its own position and cleared it in prepare. Since commit a93dad6f4e6a ("ASoC: q6apm-dai: make use of q6apm_get_hw_pointer") the position comes from the hw pointer, so a stream that is prepared again, e.g. to recover from an xrun, reports the position of the previous run until the DSP returns its first buffer, while ALSA has reset its own pointer to 0.
Reset the hw pointer together with dsp_buf.
--- sound/soc/qcom/qdsp6/q6apm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/qcom/qdsp6/q6apm.c +1 -0
@@ -283,6 +283,7 @@ int q6apm_alloc_fragments(struct q6apm_graph *graph, unsigned int dir, phys_addrmutex_lock (&graph->lock); data->dsp_buf =0 ; +atomic_set (&data->hw_ptr,0 );if (data->buf) {mutex_unlock (&graph->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 810/1257 ASoC: qcom: q6asm-dai: wrap the position of a full ring to 0
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladyslav Tymoshchuk <[email protected]>
[ Upstream commit 222d04cf55bc5b4b63602454014619c78deda89a ]
Commit 44432315444c ("ASoC: qcom: q6asm-dai: use q6asm_get_hw_pointer") took the position from the number of period buffers the DSP has returned in the current lap, 1..periods, and reports one frame less than that, as q6apm-dai does.
One frame short, a playback stream whose application stops feeding it never reaches the stop threshold: the DSP returns the last queued buffer, the position stops at appl_ptr - 1 and no period interrupt comes any more, so ALSA never detects the underrun, the stream stays RUNNING and drain only ends on its timeout. On capture, the last frame of each period is held back until the next one.
Before that commit the position wrapped to 0 at the end of the ring. Do that again, as for q6apm-dai.
--- sound/soc/qcom/qdsp6/q6asm-dai.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
sound/soc/qcom/qdsp6/q6asm-dai.c +3 -4
@@ -485,11 +485,10 @@ static snd_pcm_uframes_t q6asm_dai_pointer(struct snd_soc_component *component,struct q6asm_dai_rtd *prtd = runtime->private_data;snd_pcm_uframes_t ptr; - ptr =q6asm_get_hw_pointer (prtd->audio_client, substream->stream) * runtime->period_size; -if (ptr) -return ptr -1 ; +/* a full lap of period buffers is the start of the ring again */ + ptr =q6asm_get_hw_pointer (prtd->audio_client, substream->stream) % runtime->periods; -return 0 ; +return ptr * runtime->period_size; } static int q6asm_dai_hw_params(struct snd_soc_component *component,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 811/1257 iommupt: Do not allow PTEs to be split when dirty logging
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Gunthorpe <[email protected]>
[ Upstream commit 04bcf84613346b973a8cc0c59238b6b5bc902688 ]
If a single PTE cannot be stored in the current bitmap that should be a failure and reported back to userspace. Allowing a PTE to be split creates a possibility that dirty memory will be reported as clean.
The gather must also cover the entire PTE that is being cleaned, not just the part that fits within the bitmap.
Fix both issues by computing the full IOVA range of every PTE and using that to update the bitmap and the gather. The bitmap code now rejects ranges that don't fit in it, and the gather always combined ranges.
The selftest quietly relied on a bug where the CONT was split, that is why the half page size for the mock domain saw alternating dirties. Increase the dirty test page size to PAGE_SIZE so it still works as intended.
--- drivers/iommu/generic_pt/iommu_pt.h | 30 +++++++------------------ tools/testing/selftests/iommu/iommufd.c | 10 ++++----- 2 files changed, 13 insertions(+), 27 deletions(-)
drivers/iommu/generic_pt/iommu_pt.h +8 -22
@@ -240,27 +240,14 @@ struct pt_iommu_dirty_args { };static void record_dirty (struct pt_state *pts, -struct pt_iommu_dirty_args *dirty, -unsigned int num_contig_lg2) +struct pt_iommu_dirty_args *dirty) { -pt_vaddr_t dirty_len; - -if (num_contig_lg2 !=ilog2 (1 )) { -unsigned int index = pts->index; -unsigned int end_index =log2_set_mod_max_t ( - unsigned int, pts->index, num_contig_lg2); - -/* Adjust for being contained inside a contiguous page */ - end_index =min (end_index, pts->end_index); - dirty_len = (end_index - index) * -log2_to_int (pt_table_item_lg2sz (pts)); - }else { - dirty_len =log2_to_int (pt_table_item_lg2sz (pts)); - } +unsigned int lg2sz =pt_entry_oa_lg2sz (pts); +pt_vaddr_t start_va =log2_set_mod (pts->range->va,0 , lg2sz); +pt_vaddr_t dirty_len =log2_to_int (lg2sz);if (dirty->dirty->bitmap) -iova_bitmap_set (dirty->dirty->bitmap, pts->range->va, - dirty_len); +iova_bitmap_set (dirty->dirty->bitmap, start_va, dirty_len);if (!(dirty->flags &IOMMU_DIRTY_NO_CLEAR )) {/*
@@ -268,8 +255,8 @@ static void record_dirty(struct pt_state *pts,* dirty tracking bits can't work together */ pt_entry_make_write_clean (pts); -iommu_iotlb_gather_add_range (dirty->dirty->gather, - pts->range->va, dirty_len); +iommu_iotlb_gather_add_range (dirty->dirty->gather, start_va, + dirty_len); } }
@@ -289,8 +276,7 @@ static inline int __read_and_clear_dirty(struct pt_range *range, void *arg,continue ; }if (pts.type ==PT_ENTRY_OA &&pt_entry_is_write_dirty (&pts)) -record_dirty (&pts, dirty, -pt_entry_num_contig_lg2 (&pts)); +record_dirty (&pts, dirty); }return 0 ; }
tools/testing/selftests/iommu/iommufd.c +5 -5
@@ -2175,9 +2175,9 @@ FIXTURE_SETUP(iommufd_dirty_tracking)test_ioctl_ioas_alloc (&self->ioas_id);/* -* For dirty testing it is important that the page size fed into -* the iommu page tables matches the size the dirty logic -* expects, or set_dirty can touch too much stuff. +* Disabling huge pages maps in PAGE_SIZE units, which can span +* multiple contiguous MOCK_PAGE_SIZE entries. The dirty tests must +* expect the entire mapping to be reported dirty. */ cmd.object_id = self->ioas_id;if (!variant->hugepages)
@@ -2335,7 +2335,7 @@ TEST_F(iommufd_dirty_tracking, device_dirty_capability) TEST_F(iommufd_dirty_tracking, get_dirty_bitmap) { -uint32_t page_size =MOCK_PAGE_SIZE ; +uint32_t page_size =PAGE_SIZE ;uint32_t ioas_id = self->ioas_id;uint32_t hwpt_id;
@@ -2377,7 +2377,7 @@ TEST_F(iommufd_dirty_tracking, get_dirty_bitmap) TEST_F(iommufd_dirty_tracking, get_dirty_bitmap_no_clear) { -uint32_t page_size =MOCK_PAGE_SIZE ; +uint32_t page_size =PAGE_SIZE ;uint32_t ioas_id = self->ioas_id;uint32_t hwpt_id;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 812/1257 spi: bcm-qspi: reject oversized dummy bytes in mspi exec_mem_op
In reply to Greg Kroah-Hartman7.3-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
@@ -1197,8 +1197,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 -EOPNOTSUPP ; buf = op->data.buf.in;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 813/1257 PCI/PM: Restore BARs after powering up during enumeration
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Keng-Yu Lin <[email protected]>
[ Upstream commit f043083843cac1105206437d8c58e725b6412fad ]
Commit 4d4c10f763d7 ("PCI: Explicitly put devices into D0 when initializing") added pci_pm_power_up_and_verify_state() to pci_pm_init(). The helper ignores pci_power_up()'s return value indicating that BARs need restoring. Its resume callers restore saved configuration afterwards; pci_pm_init() does not.
D3hot-to-D0 may reset a device and lose its BARs (PCI PM 1.2, sec 5.4.1). After enumeration powers it up, pci_enable_device() reads D0 and skips the full power-up path. Previously, a device still in D3hot at enable time took that path, including BAR restoration.
On AMD Venice SP7, two AMD xHCI controllers [1022:17d2] are in runtime D3hot with No_Soft_Reset clear before kdump. Diagnostic reads on v7.3-rc6-37 show the following for 0000:01:00.4 in the crash kernel:
PMCSR BAR0 before the platform power call 0003 f4100004 after the platform power call 0003 f4100004 after native D0 power-up 0000 00000004
The upper BAR DWORD stays zero. pci_power_up() returns 1, but the BAR address remains zero while dev->resource[0] still contains 0xf4100000. Without BAR restoration, the crash kernel hangs during boot. The last console output includes:
pci 0000:01:00.4: enabling device (0000 -> 0002)
Restoring both controllers' BARs gives matching readbacks and allows kdump to save a vmcore and reboot. An AMD Turin xHCI [1022:1557] shows the same BAR loss; restoring its BAR also allows kdump to complete.
Read the initial power state first. Otherwise, pci_power_up() may request a BAR restore based on a cached PCI_UNKNOWN state, even when the device is already in D0.
For devices already in D0, only synchronize the platform state so that ACPI calls such as _REG still run. For other states, use pci_set_full_power_state() to power up the device and restore BARs when needed.
--- drivers/pci/pci.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/pci/pci.c +9 -1
@@ -3262,7 +3262,15 @@ void pci_pm_init(struct pci_dev *dev) } poweron: -pci_pm_power_up_and_verify_state (dev); +pci_update_current_state (dev,PCI_UNKNOWN ); +if (dev->current_state ==PCI_D0 ) { +/* No need for full power-up, just sync-up platform state */ +platform_pci_set_power_state (dev,PCI_D0 ); + }else { +/* Power up the device and restore BARs if necessary */ +pci_set_full_power_state (dev, false); + } +pci_update_current_state (dev,PCI_D0 );pm_runtime_forbid (&dev->dev);/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 814/1257 spi: amd: fix len==0 underflow and FIFO overflow
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit e2f4edfc061e493fddde16c4bbe1c4f230f41e4a ]
amd_spi_fifo_xfer() unconditionally decrements xfer->len when a tx_buf is present. The SPI core does not reject zero-length transfers, so a transfer submitted through the SPI_IOC_MESSAGE ioctl with len == 0 and a tx_buf makes the u32 len wrap to 0xFFFFFFFF, and the following per-byte loop writes far past the FIFO window.
The driver also never checks the cumulative FIFO offset against AMD_SPI_FIFO_SIZE. The core splits each transfer down to the controller's max transfer size but does not bound the total message length, so a message of several transfers whose total exceeds the FIFO overflows it with out-of-bounds MMIO writes (tx) and reads (rx).
Skip zero-length transfers and reject any transfer that would run past the end of the FIFO window.
Tested with a user-space replica of the fifo_xfer length arithmetic (ASAN build): a zero-length transfer with tx_buf makes len-- wrap to 0xffffffff, and skipping zero-length transfers avoids the wrap. No AMD SPI hardware was available, so the FIFO bound check was verified by inspection against AMD_SPI_FIFO_SIZE.
--- drivers/spi/spi-amd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/spi/spi-amd.c +17 -0
@@ -322,11 +322,22 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,list_for_each_entry (xfer, &message->transfers, transfer_list) { +/* Skip zero-length transfers to avoid len underflow below */ +if (!xfer->len) +continue ; +if (xfer->speed_hz)amd_set_spi_freq (amd_spi, xfer->speed_hz);else amd_set_spi_freq (amd_spi, spi->max_speed_hz); +/* Reject transfers that would overflow the FIFO window */ +if (fifo_pos + xfer->len > +AMD_SPI_FIFO_BASE +AMD_SPI_FIFO_SIZE ) { + message->status = -EMSGSIZE ; + goto fin_msg; + } +if (xfer->tx_buf) { buf = (u8 *)xfer->tx_buf;if (!tx_len) {
@@ -369,6 +380,12 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,list_for_each_entry (xfer, &message->transfers, transfer_list)if (xfer->rx_buf) { +/* Reject transfers that would overflow the FIFO window */ +if (fifo_pos + xfer->len > +AMD_SPI_FIFO_BASE +AMD_SPI_FIFO_SIZE ) { + message->status = -EMSGSIZE ; + goto fin_msg; + } buf = (u8 *)xfer->rx_buf;/* Read data from FIFO to receive buffer */ for (i =0 ; i < xfer->len; i++)
Signature · 1 line
2.53.0
Jiri Slaby
maintainerRe: [PATCH 7.3 0814/1257] spi: amd: fix len==0 underflow and FIFO overflow
Quoted 7 lines · Greg Kroah-Hartman
7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit
e2f4edfc061e493fddde16c4bbe1c4f230f41e4a]
The above is flagged as fixed by:aed0c7475d6a ("spi: amd: validate FIFO usage before executing message")
thanks,
Signature · 2 lines
js suse labs
Re: [PATCH 7.3 0814/1257] spi: amd: fix len==0 underflow and FIFO overflow
Quoted 1 line
[PATCH 7.3 0814/1257] spi: amd: fix len==0 underflow and FIFO overflow
Queued the follow-up fix for 7.3, 6.18, 6.12, 6.6 and 6.1, so it rides with the patch it fixes. Thanks.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 815/1257 erofs: use on-disk blkszbits for lz4 max pcluster bound
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gyokhan Kochmarla <[email protected]>
[ Upstream commit 90b7e4a7a16443d9f6807b5c1dde52074d9f74c0 ]
z_erofs_load_lz4_config() rejects a valid LZ4 image when the kernel's page size differs from the image's block size. It bounds the on-disk max_pclusterblks with erofs_blknr(sb, Z_EROFS_PCLUSTER_MAX_SIZE), which expands to Z_EROFS_PCLUSTER_MAX_SIZE >> sb->s_blocksize_bits.
At the point this runs, sb->s_blocksize_bits still holds PAGE_SHIFT:erofs_fc_fill_super() seeds s_blocksize_bits to PAGE_SHIFT before reading the superblock, and only corrects it down to the on-disk blkszbits after erofs_read_superblock() returns. The LZ4 config is parsed inside erofs_read_superblock(), before that correction, so the bound is computed with the wrong shift.
On a 64K-page kernel mounting a 4K-block image (e.g. one built with mkfs.erofs -C 262144 on a 4K-page host), the bound evaluates to 1 MiB >> 16 = 16 blocks instead of the correct 1 MiB >> 12 = 256 blocks. The image's legitimate max_pclusterblks of 64 then fails the check, mount returns -EINVAL, and booting from such an image as the root filesystem panics:
erofs (device dm-0): too large lz4 pclusterblks 64
Kernel panic - not syncing: VFS: Unable to mount root fs
sbi->blkszbits already holds the on-disk block size at this point, so compute the bound from it directly. This makes the check independent of the host page size and of superblock-parse ordering.
commit 3acea5fc3354 ("erofs: avoid hardcoded blocksize for subpage block support") already handled the same ordering hazard for the superblock checksum path by using sbi->blkszbits in erofs_superblock_csum_verify(); the lz4 config path was missed.
--- fs/erofs/decompressor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/decompressor.c +1 -1
@@ -23,7 +23,7 @@ static int z_erofs_load_lz4_config(struct super_block *sb,if (!sbi->lz4.max_pclusterblks) { sbi->lz4.max_pclusterblks =1 ;/* reserved case */ }else if (sbi->lz4.max_pclusterblks > -erofs_blknr (sb,Z_EROFS_PCLUSTER_MAX_SIZE )) { +Z_EROFS_PCLUSTER_MAX_SIZE >> sbi->blkszbits) {erofs_err (sb,"too large lz4 pclusterblks %u" , sbi->lz4.max_pclusterblks);return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 816/1257 ring-buffer: Take cpus_read_lock() when changing the subbuf order
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
[ Upstream commit 453d0f47b174cac387af48d303c503b84f82212e ]
A CPU coming online for the first time gets its per CPU buffer allocated by trace_rb_cpu_prepare(), which then adds it to buffer->cpumask. If that happens while ring_buffer_subbuf_order_set() is running, the CPU shows up after the allocation loop and the install loop walks it with an empty new_pages list, corrupting the buffer.
Take cpus_read_lock() as ring_buffer_resize() does.
--- kernel/trace/ring_buffer.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/trace/ring_buffer.c +2 -0
@@ -7466,6 +7466,8 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)if (psize >RB_WRITE_MASK +1 )return -EINVAL ; +guard (cpus_read_lock)(); +/* prevent another thread from changing buffer sizes */ guard (mutex)(&buffer->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 817/1257 dax: Return errors from dax_core_init()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianyun Gao <[email protected]>
[ Upstream commit 4da700e2cadf84a6e858391d5be51d64dcba080f ]
dax_core_init() returns success when either the character device number allocation or DAX bus registration fails, even though the error paths have already released the initialized resources.
For modular DAX, this allows the module to remain loaded despite failed initialization, leaving subsequent users and module removal to access resources that have already been released.
Return the error code from the failed operation so that module loading fails rather than reporting successful initialization after the resources have been released.
--- drivers/dax/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dax/super.c +1 -1
@@ -738,7 +738,7 @@ static int __init dax_core_init(void)unregister_chrdev_region (dax_devt,MINORMASK +1 ); err_chrdev:dax_fs_exit (); -return 0 ; +return rc; } static void __exit dax_core_exit(void)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 818/1257 dax: fix dax_range_compare_iter() to use correct size and address offset
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianyun Gao <[email protected]>
[ Upstream commit a4bfbfb4e98a62b589ac7ca9e73e9612bfe8cab7 ]
dax_range_compare_iter() has two bugs in how it calls dax_iomap_direct_access() and uses the returned addresses:
1. The size argument passed to dax_iomap_direct_access() is ALIGN(pos + len, PAGE_SIZE), which is an absolute file offset rather than a length. This causes the underlying dax_direct_access() to request a massively inflated nr_pages via PHYS_PFN(size).
2. The addresses returned by dax_iomap_direct_access() are page-aligned starting addresses, but memcmp() compares from saddr/daddr directly without adding the page-in-page offset of pos1/pos2. When pos1/pos2 are not page-aligned, this compares the wrong data.
Fix the size by computing ALIGN(len + offset_in_page(pos), PAGE_SIZE), matching the pattern used in dax_iomap_copy_around(). Fix the address by adding offset_in_page(pos1)/offset_in_page(pos2) to saddr/daddr in the memcmp() call.
--- fs/dax.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/dax.c +7 -5
@@ -2200,6 +2200,7 @@ static int dax_range_compare_iter(struct iomap_iter *it_src,const struct iomap *dmap = &it_dest->iomap;loff_t pos1 = it_src->pos, pos2 = it_dest->pos;void *saddr, *daddr; +size_t size1, size2;int id, ret; len =min (len,min (smap->length, dmap->length));
@@ -2215,17 +2216,18 @@ static int dax_range_compare_iter(struct iomap_iter *it_src, } id =dax_read_lock (); - ret =dax_iomap_direct_access (smap, pos1,ALIGN (pos1 + len,PAGE_SIZE ), - &saddr,NULL ); + size1 =ALIGN (len +offset_in_page (pos1),PAGE_SIZE ); + ret =dax_iomap_direct_access (smap, pos1, size1, &saddr,NULL );if (ret <0 ) goto out_unlock; - ret =dax_iomap_direct_access (dmap, pos2,ALIGN (pos2 + len,PAGE_SIZE ), - &daddr,NULL ); + size2 =ALIGN (len +offset_in_page (pos2),PAGE_SIZE ); + ret =dax_iomap_direct_access (dmap, pos2, size2, &daddr,NULL );if (ret <0 ) goto out_unlock; - *same = !memcmp (saddr, daddr, len); + *same = !memcmp (saddr +offset_in_page (pos1), + daddr +offset_in_page (pos2), len);if (!*same) len =0 ;dax_read_unlock (id);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 819/1257 net: erspan: set lltx to avoid sch_direct_xmit deadlock
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Zhou <[email protected]>
[ Upstream commit 2d36ec73836e83175deb467fd494c61006107e5d ]
The ERSPAN xmit path re-enters the network stack, causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock, creating an ABBA deadlock. This happens for both IPv4 ERSPAN (erspan_xmit() -> ip_tunnel_xmit()) and IPv6 ERSPAN (ip6erspan_tunnel_xmit() -> ip6_tnl_xmit()):
sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit -> ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]
sch_direct_xmit [lock erspan] -> ip6erspan_tunnel_xmit -> ip6_tnl_xmit -> ip6_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]
Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as the ERSPAN xmit path has no shared mutable state: o_seqno is atomic, TX stats are per-CPU u64_stats, dst_cache is per-CPU, and o_flags is no longer modified in the xmit path since commit 9958e69b9893 ("gre: fix ERSPAN o_flags race/corruption in xmit and fill_info"). GRETAP, the sibling device with identical xmit structure, already sets lltx.
--- net/ipv4/ip_gre.c | 1 + net/ipv6/ip6_gre.c | 1 + 2 files changed, 2 insertions(+)
net/ipv4/ip_gre.c +1 -0
@@ -1367,6 +1367,7 @@ static int erspan_tunnel_init(struct net_device *dev) dev->features |=GRE_FEATURES ; dev->hw_features |=GRE_FEATURES ; dev->priv_flags |=IFF_LIVE_ADDR_CHANGE ; + dev->lltx = true;netif_keep_dst (dev);return ip_tunnel_init (dev);
net/ipv6/ip6_gre.c +1 -0
@@ -1864,6 +1864,7 @@ static int ip6erspan_tap_init(struct net_device *dev) dev->mtu -=8 ; dev->priv_flags |=IFF_LIVE_ADDR_CHANGE ; + dev->lltx = true;ip6erspan_tnl_link_config (tunnel,1 );netdev_hold (dev, &tunnel->dev_tracker,GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 820/1257 ublk: keep a canceled FETCH round canceling until the server is gone
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit 4c454b5b2634d982caf797fbe477770c3edfc983 ]
A cancel completes a fetched io command and sets io->cmd to NULL, but the io still counts as ready. Only ubq->canceling stops ublk_queue_rq() from using the NULL io->cmd. Two paths clear that flag too early:
partial FETCH round recovery, two queues
------------------- --------------------
task A: FETCH tags 0-2 q0 ready: q0->canceling = false
task A exits: q0 task exits:
start_cancel(): mark queues start_cancel(): ub->canceling
tags 0-2: io->cmd = NULL is still set -> q0 not marked
task B: FETCH tag 3 q0: io->cmd = NULL
queue ready: canceling = false q1 ready
START_DEV END_USER_RECOVERY
read -> ublk_queue_cmd(NULL) read on q0 -> ublk_queue_cmd(NULL)A FETCH round runs from the open of /dev/ublkcN until ublk_reset_ch_dev() resets the queues. A canceled command can't be fetched again in the same round. So the ready check only needs one
fact: did this round see a cancel? ub->canceling already records it:ublk_start_cancel() sets it under cancel_mutex before any command is taken. It is only cleared too early, when all queues are ready.
Fix:
- clear ub->canceling only in ublk_reset_ch_dev()
- when a queue gets ready, clear ubq->canceling only if ub->canceling is not set, and check it under cancel_mutex
The check and the marking are ordered by cancel_mutex:
check first: queue cleared -> start_cancel() marks it again
-> command taken
cancel first: check sees ub->canceling -> queue stays canceling
While ub->canceling is set, no queue clears its flag. So the "all queues marked" shortcut in ublk_start_cancel() is correct again.
UBLK_F_BATCH_IO follows the same rule. It does not dispatch through io->cmd, so it never hit the oops, but a round which lost a fetch command is treated the same way: it has to start over.
--- drivers/block/ublk_drv.c | 54 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 21 deletions(-)
drivers/block/ublk_drv.c +33 -21
@@ -334,6 +334,11 @@ struct ublk_device {u16 nr_queue_ready;bool unprivileged_daemons;struct mutex cancel_mutex; +/* +* A cancel started in this FETCH round. Set by ublk_set_canceling(), +* cleared only by ublk_reset_ch_dev() when a new round starts. While +* it is set, no queue clears its ->canceling. +*/ bool canceling;pid_t ublksrv_tgid;struct delayed_work exit_work;
@@ -2415,6 +2420,11 @@ static void ublk_reset_ch_dev(struct ublk_device *ub)spin_unlock (&ubq->cancel_lock); } +/* a new FETCH round starts, the queues stay canceling until ready */ +mutex_lock (&ub->cancel_mutex); + ub->canceling = false; +mutex_unlock (&ub->cancel_mutex); +/* set to NULL, otherwise new tasks cannot mmap io_cmd_buf */ ub->mm =NULL ; ub->nr_queue_ready =0 ;
@@ -3024,11 +3034,19 @@ static void ublk_reset_io_flags(struct ublk_queue *ubq, struct ublk_io *io) }/* reset per-queue io flags */ -static void ublk_queue_reset_io_flags (struct ublk_queue *ubq) +static void ublk_queue_reset_io_flags (struct ublk_device *ub, +struct ublk_queue *ubq) { -spin_lock (&ubq->cancel_lock); - ubq->canceling = false; -spin_unlock (&ubq->cancel_lock); +/* +* A cancel in this FETCH round took a command which still counts as +* ready, so the queue has to stay canceling. ub->canceling is set +* under cancel_mutex before any command is taken: either we see it +* here, or the cancel marks this queue again later. +*/ +mutex_lock (&ub->cancel_mutex); +if (!ub->canceling) + ubq->canceling = false; +mutex_unlock (&ub->cancel_mutex); ubq->fail_io = false; ubq->force_abort = false; }
@@ -3051,24 +3069,17 @@ static void ublk_mark_io_ready(struct ublk_device *ub, u16 q_id, ub->nr_queue_ready++;/* -* Reset queue flags as soon as this queue is ready. -* This clears the canceling flag, allowing batch FETCH commands -* to succeed during recovery without waiting for all queues. +* Reset queue flags as soon as this queue is ready. Unless +* this round saw a cancel, this clears the canceling flag, +* allowing batch FETCH commands to succeed during recovery +* without waiting for all queues. */ -ublk_queue_reset_io_flags (ubq); +ublk_queue_reset_io_flags (ub, ubq); } -/* Check if all queues are ready */ -if (ublk_dev_ready (ub)) { -/* -* All queues ready - clear device-level canceling flag -* and wake ublk_dev_ready() waiters. -*/ -mutex_lock (&ub->cancel_mutex); - ub->canceling = false; -mutex_unlock (&ub->cancel_mutex); +/* All queues ready - wake ublk_dev_ready() waiters */ +if (ublk_dev_ready (ub))wake_up_var (&ub->nr_queue_ready); - } }static inline int ublk_check_cmd_op (u32 cmd_op)
@@ -4433,9 +4444,10 @@ static bool ublk_validate_user_pid(struct ublk_device *ub, pid_t ublksrv_pid)/* * Wait until all queues have fetched their I/O commands, and return with -* ub->mutex held and readiness guaranteed: then every queue's ->canceling -* is cleared. Ready may regress between wakeup and mutex_lock() (F_BATCH -* UNPREP, daemon death), so re-check it under the mutex and wait again. +* ub->mutex held and readiness guaranteed. The queues stay canceling if +* this round saw a cancel, see ublk_queue_reset_io_flags(). Ready may +* regress between wakeup and mutex_lock() (F_BATCH UNPREP, daemon death), +* so re-check it under the mutex and wait again. */ static int ublk_wait_dev_ready_and_lock (struct ublk_device *ub) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 821/1257 ublk: mark the io command cancelable before publishing it
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit a261f0cacacc022e4fab5b8e38c59f74ce4942e8 ]
FETCH, COMMIT_AND_FETCH and NEED_GET_DATA publish the command in io->cmd before marking it cancelable. A cancel from the control path (STOP_DEV, QUIESCE_DEV) can complete it in between:
issue path control-path cancel
io->cmd = C
take C, io_uring_cmd_done(C):
C not marked, nothing to unlink
ublk_prep_cancel(C)
the completed C is linked on the cancelable list
ring exit: the cancel walk hits it → GPF (KASAN, with a delay added)
Mark the command before ublk_fill_io_cmd() publishes it. The handlers run with uring_lock held, as io_uring's cancel walk does, so marking takes no lock and the walk can't see a marked command before it is published. smp_wmb() orders the mark before the io->cmd store; the cancel loads cmd with READ_ONCE(io->cmd) before reading cmd->flags.
A marked command has to be completed by io_uring_cmd_done(), so a failed FETCH and the inline UBLK_IO_RES_OK of NEED_GET_DATA now do that. The CQE is the same.
--- drivers/block/ublk_drv.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
drivers/block/ublk_drv.c +21 -6
@@ -2800,7 +2800,8 @@ static void ublk_cancel_cmd(struct ublk_queue *ubq, u16 tag, done = !!(io->flags &UBLK_IO_FLAG_CANCELED );if (!done) { io->flags |=UBLK_IO_FLAG_CANCELED ; - cmd = io->cmd; +/* dependency ordered against smp_wmb() in ublk_prep_cancel() */ + cmd =READ_ONCE (io->cmd); io->cmd =NULL ; }spin_unlock (&ubq->cancel_lock);
@@ -3163,6 +3164,12 @@ ublk_fill_io_cmd(struct ublk_io *io, struct io_uring_cmd *cmd)return req; } +/* +* Call before ublk_fill_io_cmd() publishes @cmd in io->cmd: a control-path +* cancel may complete any command found there, and io_uring_cmd_done() only +* takes it off the cancelable list if it is marked already. The handlers +* hold uring_lock, so marking takes no lock. +*/ static inline void ublk_prep_cancel (struct io_uring_cmd *cmd,unsigned int issue_flags,struct ublk_queue *ubq,u16 tag)
@@ -3176,6 +3183,8 @@ static inline void ublk_prep_cancel(struct io_uring_cmd *cmd, pdu->ubq = ubq; pdu->tag = tag;io_uring_cmd_mark_cancelable (cmd, issue_flags); +/* pairs with the cancel loading cmd from io->cmd, then cmd->flags */ +smp_wmb (); }static void ublk_io_release (void *priv)
@@ -3423,11 +3432,11 @@ static int ublk_ch_uring_cmd_local(struct io_uring_cmd *cmd, ret =ublk_check_fetch_buf (ub, addr);if (ret) goto out; +/* before ublk_fetch() publishes io->cmd, see ublk_prep_cancel() */ +ublk_prep_cancel (cmd, issue_flags, ubq, tag); ret =ublk_fetch (cmd, ub, io, addr, q_id);if (ret) - goto out; - -ublk_prep_cancel (cmd, issue_flags, ubq, tag); + goto out_done;return -EIOCBQUEUED ; }
@@ -3471,6 +3480,7 @@ static int ublk_ch_uring_cmd_local(struct io_uring_cmd *cmd,if (ret) goto out; io->res = result; +ublk_prep_cancel (cmd, issue_flags, ubq, tag); req =ublk_fill_io_cmd (io, cmd);ublk_apply_io_buf (ub, io, cmd, addr, &auto_buf, &buf_idx);if (buf_idx !=UBLK_INVALID_BUF_IDX )
@@ -3489,19 +3499,24 @@ static int ublk_ch_uring_cmd_local(struct io_uring_cmd *cmd,* uring_cmd active first and prepare for handling new requeued * request */ +ublk_prep_cancel (cmd, issue_flags, ubq, tag); req =ublk_fill_io_cmd (io, cmd); io->buf.addr = addr;if (likely (ublk_get_data (ubq, io, req))) {__ublk_prep_compl_io_cmd (io, req); -return UBLK_IO_RES_OK ; + ret =UBLK_IO_RES_OK ; + goto out_done; }break ;default : goto out; } -ublk_prep_cancel (cmd, issue_flags, ubq, tag);return -EIOCBQUEUED ; + out_done: +/* marked cancelable: complete through io_uring_cmd_done() */ +io_uring_cmd_done (cmd, ret, issue_flags); +return -EIOCBQUEUED ; out:pr_devel ("%s: complete: cmd op %d, tag %d ret %x io_flags %x\n" , __func__, cmd_op, tag, ret, io ? io->flags :0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 822/1257 ublk: mark the batch fetch command cancelable before linking it
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit b59e96011d22e322fbf4d5d1d1124de538c278ed ]
UBLK_U_IO_FETCH_IO_CMDS has the same order problem as the per-io
commands: ublk_batch_attach() links the fetch command into fcmd_head and marks it cancelable only after dropping evts_lock. A cancel from the control path (ublk_batch_cancel_queue()) can take it in between and complete it, and the later mark puts a completed request on io_uring's cancelable list.
Mark it before linking it. evts_lock orders the mark before the link, which is where the cancel finds it.
Batch commands are not bounced to task work, so they can run from io-wq without uring_lock, and io_uring's cancel walk can now find a fetch command before it is linked. Two things make that safe:
- initialize fcmd->node: it came from kzalloc(), so list_empty() saw a linked node and ublk_batch_cancel_cmd() would list_del_init() NULL pointers
- on the -ENODEV path, complete the command with io_uring_cmd_done() before freeing fcmd: that removes it from the cancelable list under uring_lock, after which nothing can see fcmd
Also use data->cmd instead of fcmd->cmd after dropping evts_lock: once fcmd is linked and not the active one, a control-path cancel may complete and free it.
--- drivers/block/ublk_drv.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/block/ublk_drv.c +18 -6
@@ -815,6 +815,8 @@ ublk_batch_alloc_fcmd(struct io_uring_cmd *cmd)if (fcmd) { fcmd->cmd = cmd; fcmd->buf_group =READ_ONCE (cmd->sqe->buf_index); +/* a cancel may look at it before it is linked */ +INIT_LIST_HEAD (&fcmd->node); }return fcmd; }
@@ -3915,6 +3917,15 @@ static int ublk_batch_attach(struct ublk_queue *ubq,bool free = false;struct ublk_uring_cmd_pdu *pdu =ublk_get_uring_cmd_pdu (data->cmd); +/* +* Mark it cancelable before linking it into fcmd_head, where a cancel +* from the control path can take and complete it: see +* ublk_prep_cancel(). evts_lock orders the mark before the link. +*/ + pdu->ubq = ubq; + pdu->fcmd = fcmd; +io_uring_cmd_mark_cancelable (fcmd->cmd, data->issue_flags); +spin_lock (&ubq->evts_lock);if (unlikely (ubq->force_abort || ubq->canceling)) { free = true;
@@ -3925,14 +3936,12 @@ static int ublk_batch_attach(struct ublk_queue *ubq,spin_unlock (&ubq->evts_lock);if (unlikely (free)) { +/* off the cancelable list first, then nothing can see fcmd */ +io_uring_cmd_done (data->cmd, -ENODEV , data->issue_flags);ublk_batch_free_fcmd (fcmd); -return -ENODEV ; +return -EIOCBQUEUED ; } - pdu->ubq = ubq; - pdu->fcmd = fcmd; -io_uring_cmd_mark_cancelable (fcmd->cmd, data->issue_flags); -if (!new_fcmd) goto out;
@@ -3940,9 +3949,12 @@ static int ublk_batch_attach(struct ublk_queue *ubq,* If the two fetch commands are originated from same io_ring_ctx, * run batch dispatch directly. Otherwise, schedule task work for * doing it. +* +* Use data->cmd, not fcmd->cmd: once fcmd is linked and not active, +* a cancel from the control path may complete and free it. */ if (io_uring_cmd_ctx_handle (new_fcmd->cmd) == -io_uring_cmd_ctx_handle (fcmd->cmd)) { +io_uring_cmd_ctx_handle (data->cmd)) { data->cmd = new_fcmd->cmd;ublk_batch_dispatch (ubq, data, new_fcmd); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 823/1257 ublk: reset the FETCH round in release also without a disk
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit f06ca594eafcdf58a399a0f92480631192e06032 ]
The release of /dev/ublkcN resets the queues only when the device has a disk. Without one it skips ublk_reset_ch_dev():
server fetches, never starts; old server exits
or STOP_DEV removed the disk release: no disk → skip reset
ios stay ACTIVE / CANCELED, nr_io_ready stays full
new server opens /dev/ublkcN FETCH: -EBUSY (still ready), or
-EINVAL after a partial round → the device can only be deleted
All uring_cmds are done when the release work runs, with or without a disk, so the reset is safe either way. Do it in both cases. Then a new server can fetch and start the device again, as the STOP_DEV entry in Documentation/block/ublk.rst says ("ublk device is ready for the new process").
--- drivers/block/ublk_drv.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/block/ublk_drv.c +5 -5
@@ -2551,12 +2551,13 @@ static void ublk_ch_release_work_fn(struct work_struct *work) }/* -* disk isn't attached yet, either device isn't live, or it has -* been removed already, so we needn't to do anything +* No disk: the device isn't live, or it has been removed already. +* There are no requests to abort, but the round still has to be +* reset, so that a new server can fetch and start the device. */ disk =ublk_get_disk (ub);if (!disk) - goto out; + goto reset;/* * All uring_cmd are done now, so abort any request outstanding to
@@ -2617,10 +2618,9 @@ static void ublk_ch_release_work_fn(struct work_struct *work) unlock:mutex_unlock (&ub->mutex);ublk_put_disk (disk); - +reset:/* all uring_cmd has been done now, reset device & ubq */ ublk_reset_ch_dev (ub); -out:clear_bit (UB_STATE_OPEN , &ub->state);/* put the reference grabbed in ublk_ch_release() */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 824/1257 ublk: reset the FETCH round under ub->mutex
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit 84824afdb5a4dc127fbd7036142d7611c5e53651 ]
The release work resets the FETCH round without ub->mutex, while START_DEV checks it under ub->mutex:
START_DEV (ub->mutex) release work
all queues ready? yes
ublksrv_tgid matches? yes
ublk_reset_ch_dev():
io->cmd = NULL, nr_queue_ready = 0 go live: a request then reaches ublk_queue_cmd() with a NULL io->cmd
Do the reset under ub->mutex. Then START_DEV sees the round either ready or reset. The work already takes ub->mutex when there is a disk, after it has aborted the requests; nothing holding ub->mutex waits for it.
--- drivers/block/ublk_drv.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/block/ublk_drv.c +10 -6
@@ -2556,8 +2556,10 @@ static void ublk_ch_release_work_fn(struct work_struct *work)* reset, so that a new server can fetch and start the device. */ disk =ublk_get_disk (ub); -if (!disk) +if (!disk) { +mutex_lock (&ub->mutex); goto reset; + }/* * All uring_cmd are done now, so abort any request outstanding to
@@ -2589,7 +2591,7 @@ static void ublk_ch_release_work_fn(struct work_struct *work)/* double check after grabbing lock */ if (!ub->ub_disk) - goto unlock; + goto reset;/* * Transition the device to the nosrv state. What exactly this
@@ -2615,12 +2617,14 @@ static void ublk_ch_release_work_fn(struct work_struct *work)WRITE_ONCE (ublk_get_queue (ub, i)->fail_io, true); } } -unlock: -mutex_unlock (&ub->mutex); -ublk_put_disk (disk); reset: -/* all uring_cmd has been done now, reset device & ubq */ +/* +* All uring_cmd has been done now, reset device & ubq. Under +* ub->mutex, so START_DEV sees the round either ready or reset. +*/ ublk_reset_ch_dev (ub); +mutex_unlock (&ub->mutex); +ublk_put_disk (disk);clear_bit (UB_STATE_OPEN , &ub->state);/* put the reference grabbed in ublk_ch_release() */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 825/1257 ublk: let STOP_DEV cancel the servers commands before its release
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit c8b349f9daf6d88ff21033028167d00e819dafb6 ]
STOP_DEV cancels the fetched commands after dropping ub->mutex, so START_DEV and FETCH can run in between:
STOP_DEV START_DEV / FETCH
lock ub->mutex
ublk_stop_dev_unlocked() (not started: does nothing)
unlock ub->mutex
START_DEV goes live, schedules scan FETCH publishes a new command
cancel_work_sync(scan) cancels the new disk's scan
ublk_cancel_dev() takes the new command: NULL io->cmd
on a queue which isn't canceling
A START_DEV after STOP_DEV also goes live over the canceled commands.
Hold a reference on the server's /dev/ublkcN while canceling:
STOP_DEV
lock ub->mutex
ublk_stop_dev_unlocked()
cancel_work_sync(scan)
server attached: take a reference on its file, set STOPPING
unlock ub->mutex
ublk_cancel_dev()
drop the reference
- STOPPING makes FETCH and PREP get UBLK_IO_RES_ABORT and START_DEV -EBUSY; a START_DEV or END_USER_RECOVERY waiting for the device to get ready wakes up too; the reset in the server's release clears it
- the release can't run before the reference is dropped, so no new server can attach, and the cancel only meets this server's commands
- the cancel still runs after the unlock: io_uring_cmd_done() may take uring_lock, under which FETCH takes ub->mutex
ublk_ch_open() saves the file in ->ch_file and ublk_ch_release() clears it, under cancel_mutex. The release runs after the last reference is gone, so take ours with file_ref_get(). Drop it with __fput_sync(): if it is the last one, fput() would defer the release to this task, which DEL_DEV then makes wait for the device to be freed.
A server which opened the device but hasn't fetched is stopped too. Document what a server sees after STOP_DEV in ublk.rst.
--- Documentation/block/ublk.rst | 7 ++++ drivers/block/ublk_drv.c | 80 ++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 8 deletions(-)
Documentation/block/ublk.rst +7 -0
@@ -126,6 +126,13 @@ managing and controlling ublk devices with help of several control commands: ublk server will release resources (such as destroying I/O handler threads & io_uring). + If a server has ``/dev/ublkc*`` open, its fetched I/O commands complete with + ``UBLK_IO_RES_ABORT``. Until it closes ``/dev/ublkc*``, new + ``UBLK_IO_FETCH_REQ`` and ``UBLK_U_IO_PREP_IO_CMDS`` commands complete with + ``UBLK_IO_RES_ABORT`` too, and ``UBLK_CMD_START_DEV`` fails with ``-EBUSY``, + even if the server hadn't fetched anything. The device can be started again + by a server that opens ``/dev/ublkc*`` after that. + - ``UBLK_CMD_DEL_DEV`` Remove ``/dev/ublkc*``. When this command returns, the allocated ublk device
drivers/block/ublk_drv.c +72 -8
149 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 826/1257 net: skbuff: dont BUG() on a bad csum_start in skb_copy_and_csum_dev()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 56453199d28f0072a8196fba14b2d702632e2219 ]
skb_copy_and_csum_dev() copies everything up to the checksum start out of the linear area, and BUG()s if the checksum start is past the end of the linear area. It misses the other direction: a CHECKSUM_PARTIAL skb that has been pulled past its csum_start gives a negative offset, which gets past the check and becomes a ~4GB copy. It also trusts csum_offset when it stores the folded checksum. So far skb_copy_and_csum_bits() BUG()ing on a short skb has covered for that, but once it returns instead, a bad csum_offset would write past the end of the caller's buffer.
The function returns void and its callers are drivers copying a frame into a bounce buffer just before handing it to the hardware. There's nothing for them to back out of, so check both ends of csum_start and that the checksum field fits in the frame, and if not, copy the whole frame with skb_copy_bits() without filling in the checksum, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The frame
goes out with a bad checksum and is dropped by the receiver. If even that copy fails, zero the buffer so the driver doesn't send stale bytes.
--- net/core/skbuff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/core/skbuff.c +12 -1
@@ -3961,7 +3961,18 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else csstart =skb_headlen (skb); -BUG_ON (csstart >skb_headlen (skb)); +if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + (skb->ip_summed ==CHECKSUM_PARTIAL && + csstart + skb->csum_offset +sizeof (__sum16) > + skb->len))) { +DEBUG_NET_WARN_ON_ONCE (1 ); +/* Send the frame without the checksum filled in, or send +* zeroes if we can't even copy it. +*/ +if (skb_copy_bits (skb,0 , to, skb->len)) +memset (to,0 , skb->len); +return ; + }skb_copy_from_linear_data (skb, to, csstart);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 827/1257 rds: fix out-of-bounds conn_path walks via handshake exthdrs
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henry Martin <[email protected]>
[ Upstream commit 50f2103fce43922b6e562937b2d2fc62089ff7ec ]
Both the lane and the connection-generation negotiation are driven by extension headers in handshake packets, and both are processed unconditionally, even on transports that are not multipath capable. A non-MP connection (t_mp_capable unset) owns exactly one rds_conn_path slot, so a peer claiming up to RDS_MPATH_WORKERS lanes makes every subsequent fan-out walk conn->c_path[0..7] at 504-byte strides past the single allocated slot (KASAN: "Read of size 8 in rds_conn_path_connect_if_down"); the generation negotiation opens a similar out-of-bounds walk on the same array.
Only process handshake extension headers when the connection's transport is multipath capable, so a peer can never make us walk lanes that do not exist. Both call sites in rds_recv_incoming() are gated.
This is a port of the Oracle UEK fix for the same issue, picked up where Paula's series of the same change left off.
This issue was discovered by Tencent CodeBuddy Security.
--- net/rds/recv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/rds/recv.c +4 -2
@@ -379,7 +379,8 @@ void rds_recv_incoming(struct rds_connection *conn, struct in6_addr *saddr,rds_stats_inc (s_recv_ping);rds_send_pong (cp, inc->i_hdr.h_sport);/* if this is a handshake ping, start multipath if necessary */ -if (RDS_HS_PROBE (be16_to_cpu (inc->i_hdr.h_sport), +if (conn->c_trans->t_mp_capable && +RDS_HS_PROBE (be16_to_cpu (inc->i_hdr.h_sport),be16_to_cpu (inc->i_hdr.h_dport))) {rds_recv_hs_exthdrs (&inc->i_hdr, cp->cp_conn);rds_start_mprds (cp->cp_conn);
@@ -387,7 +388,8 @@ void rds_recv_incoming(struct rds_connection *conn, struct in6_addr *saddr, goto out; } -if (be16_to_cpu (inc->i_hdr.h_dport) ==RDS_FLAG_PROBE_PORT && +if (conn->c_trans->t_mp_capable && +be16_to_cpu (inc->i_hdr.h_dport) ==RDS_FLAG_PROBE_PORT && inc->i_hdr.h_sport ==0 ) {rds_recv_hs_exthdrs (&inc->i_hdr, cp->cp_conn);/* if this is a handshake pong, start multipath if necessary */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 828/1257 ipv6: defrag: orphan skb before queuing
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zixuan Chai <[email protected]>
[ Upstream commit 5dfa91a5ec53cfbf907a1fca095ac3ac7a4e94c9 ]
IPv4 and nf_conntrack fragment queues orphan skbs before returning -EINPROGRESS, but ip6_frag_queue() leaves the socket association intact.
Commit 18685451fc4e ("inet: inet_defrag: prevent sk release while still in use") moved skb_orphan() into ip_frag_queue() and nf_ct_frag6_queue(), but missed ip6_frag_queue().
Without orphaning, inet_frag_reasm_finish() clears fp->sk on frag_list skbs but leaves fp->destructor set to sock_pfree. Freeing the reassembled skb then calls sock_pfree() with a NULL socket. A socket using SOCK_RCU_FREE may also be released while its fragment is queued, leaving a stale socket pointer; this is a second consequence of the same missing orphan.
Orphan the skb before returning -EINPROGRESS so the queued fragment no longer retains the socket association or destructor.
--- net/ipv6/reassembly.c | 1 + 1 file changed, 1 insertion(+)
net/ipv6/reassembly.c +1 -0
@@ -232,6 +232,7 @@ static int ip6_frag_queue(struct net *net, }skb_dst_drop (skb); +skb_orphan (skb);return -EINPROGRESS ; insert_error:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 829/1257 sctp: hold transport reference across connect wait
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seung Min Shin <[email protected]>
[ Upstream commit 5bef8649bb9ac4b2a014bcc227202ebd2df824be ]
sctp_sendmsg_to_asoc() selects a transport before waiting for a new interleaved association to become established. sctp_wait_for_connect() drops the socket lock while sleeping.
While the lock is dropped, backlog processing can handle a COOKIE ACK and an ASCONF DEL-IP that removes the selected transport. sctp_assoc_rm_peer() then marks the transport dead and drops its association-owned reference. The transport can be freed through RCU before the send path resumes.
After the wait, the stale pointer is assigned to newly created DATA or I-DATA chunks and later dereferenced by sctp_outq_select_transport().
Hold a reference to the selected transport across sctp_wait_for_connect(). After the socket lock is reacquired, abort the send if the transport was marked dead. Callers without a selected transport pass NULL and retain their existing behavior.
--- net/sctp/socket.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
net/sctp/socket.c +19 -7
@@ -75,7 +75,8 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc,struct sctp_transport *transport, long *timeo_p, size_t msg_len);static int sctp_wait_for_packet (struct sock *sk,int *err,long *timeo_p); -static int sctp_wait_for_connect (struct sctp_association *,long *timeo_p); +static int sctp_wait_for_connect (struct sctp_association *, +struct sctp_transport *,long *timeo_p);static int sctp_wait_for_accept (struct sock *sk,long timeo);static void sctp_wait_for_close (struct sock *sk,long timeo);static void sctp_destruct_sock (struct sock *sk);
@@ -1245,7 +1246,7 @@ static int __sctp_connect(struct sock *sk, struct sockaddr *kaddrs, *assoc_id = asoc->assoc_id; timeo =sock_sndtimeo (sk, flags &O_NONBLOCK ); -return sctp_wait_for_connect (asoc, &timeo); +return sctp_wait_for_connect (asoc,NULL , &timeo); out_free: pr_debug("%s: took out_free path with asoc:%p kaddrs:%p err:%d\n",
@@ -1847,7 +1848,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,if (asoc->ep->intl_enable) { timeo =sock_sndtimeo (sk,0 ); - err =sctp_wait_for_connect (asoc, &timeo); + err =sctp_wait_for_connect (asoc, transport, &timeo);if (err || sk->sk_shutdown &RCV_SHUTDOWN ) { err = -ESRCH ; goto err;
@@ -1890,7 +1891,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,if (unlikely (wait_connect)) { timeo =sock_sndtimeo (sk, msg->msg_flags &MSG_DONTWAIT ); -sctp_wait_for_connect (asoc, &timeo); +sctp_wait_for_connect (asoc,NULL , &timeo); } err = msg_len;
@@ -9390,7 +9391,9 @@ static bool sctp_writeable(const struct sock *sk)/* Wait for an association to go into ESTABLISHED state. If timeout is 0, * returns immediately with EINPROGRESS. */ -static int sctp_wait_for_connect (struct sctp_association *asoc,long *timeo_p) +static int sctp_wait_for_connect (struct sctp_association *asoc, +struct sctp_transport *transport, +long *timeo_p) {struct sock *sk = asoc->base.sk;int err =0 ;
@@ -9399,12 +9402,16 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)pr_debug ("%s: asoc:%p, timeo:%ld\n" , __func__, asoc, *timeo_p); -/* Increment the association's refcnt. */ +/* Hold references while the socket lock is dropped. */ +if (transport) +sctp_transport_hold (transport);sctp_association_hold (asoc);for (;;) {prepare_to_wait_exclusive (&asoc->wait, &wait,TASK_INTERRUPTIBLE ); +if (transport && transport->dead) + goto do_transport_dead;if (!*timeo_p) goto do_nonblock;if (sk->sk_shutdown &RCV_SHUTDOWN )
@@ -9433,7 +9440,8 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) out:finish_wait (&asoc->wait, &wait); -/* Release the association's refcnt. */ +if (transport) +sctp_transport_put (transport);sctp_association_put (asoc);return err;
@@ -9452,6 +9460,10 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) do_nonblock: err = -EINPROGRESS ; goto out; + +do_transport_dead: + err = -EAGAIN ; + goto out; }static int sctp_wait_for_accept (struct sock *sk,long timeo)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 830/1257 RDS/IB: validate receive fragment completions
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shubham Antil <[email protected]>
[ Upstream commit 65cf6863606b0507a7c3bd1711317e4f5d6b8b7e ]
rds_ib_process_recv() accounts every receive fragment as contributing min(i_recv_data_rem, RDS_FRAG_SIZE) bytes, regardless of the completion length. When a completion is shorter than the header-declared amount, receive accounting can advance beyond the payload supplied by the completion.
Only an IB_WC_RECV completion has the buffer layout expected by this receive path. Other successful completion opcodes must not be interpreted as ordinary receive completions.
Reject successful completions with any other opcode before processing their length. For ordinary receive completions, require enough payload to cover the amount accounted to the fragment before linking its page into the incoming message.
This is compatible with the current transmit paths. MSG_ZEROCOPY is restricted to RDS/TCP, while RDS/IB copied and page-vector messages use full-sized non-final scatterlist entries.
Found during an LLM-assisted source audit and validated under KMSAN with a malformed short receive completion.
--- net/rds/ib_recv.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/rds/ib_recv.c +12 -1
@@ -949,6 +949,12 @@ static void rds_ib_process_recv(struct rds_connection *conn, } } +if (data_len <min_t (u32, ic->i_recv_data_rem,RDS_FRAG_SIZE )) { +rds_ib_conn_error (conn, +"fragment shorter than header-declared length; forcing reconnect\n" ); + goto done; + } +list_add_tail (&recv->r_frag->f_item, &ibinc->ii_frags); recv->r_frag =NULL ;
@@ -1004,7 +1010,12 @@ void rds_ib_recv_cqe_handler(struct rds_ib_connection *ic,* event is processed. */ if (wc->status ==IB_WC_SUCCESS ) { -rds_ib_process_recv (conn, recv, wc->byte_len, state); +if (wc->opcode !=IB_WC_RECV ) +rds_ib_conn_error (conn, +"recv completion had unexpected opcode %u, disconnecting and reconnecting\n" , + wc->opcode); +else +rds_ib_process_recv (conn, recv, wc->byte_len, state); }else {/* We expect errors as the qp is drained during shutdown */ if (rds_conn_up (conn) ||rds_conn_connecting (conn))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 831/1257 net: bgmac: enable interrupts only after NAPI is ready
In reply to Greg Kroah-Hartman7.3-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);
@@ -1608,10 +1608,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 832/1257 cpufreq: loongson3: Make this driver depend on MACH_LOONGSON64
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huacai Chen <[email protected]>
[ Upstream commit 48a82a3f44576a1b227f964fdb150e1cae7455bf ]
32BIT Loongson machines don't have SMC and FreqCtrl registers, so make this driver depend on MACH_LOONGSON64 (only for LoongArch based 64bit machines currently).
--- drivers/cpufreq/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/cpufreq/Kconfig +1 -0
@@ -288,6 +288,7 @@ endif if LOONGARCH config LOONGSON3_CPUFREQ tristate "Loongson3 CPUFreq Driver" + depends on MACH_LOONGSON64 help This option adds a CPUFreq driver for Loongson processors which support software configurable cpu frequency.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 833/1257 cpufreq: loongson3: Adjust the width of id and val in smc_message
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huacai Chen <[email protected]>
[ Upstream commit 290814d3c22b300eb36b74dc76ad36bd7fdc1220 ]
The id field of smc_message is usually stand for the CPU ID. In the past this driver was only tested for desktop and laptop productions so 4-bits are enough. But now we have servers that can have as many as 256 cores, so we need 8-bits CPU ID.
On the other hand, the val field is usually stand for CPU frequency so 12-bits are enough to represent 4GHz, and for higher frequencies there is an extra bit to extend (enough for 8GHz).
In theory, this is a incompatible change, but fortunately the old SMC firmwares are not widely shipped and can be updated on the air, thus we can safely adjust the widths.
--- drivers/cpufreq/loongson3_cpufreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/loongson3_cpufreq.c +2 -2
@@ -21,9 +21,9 @@union smc_message {u32 value;struct { -u32 id :4 ; +u32 id :8 ;u32 info :4 ; -u32 val :16 ; +u32 val :12 ;u32 cmd :6 ;u32 extra :1 ;u32 complete :1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 834/1257 cpufreq: loongson3: Replace per-package mutex with per-node
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huacai Chen <[email protected]>
[ Upstream commit 5d7802ada30b3101f408706b7399b0e170d2febd ]
Our server productions (e.g. Loongson-3D6000/3E6000) can have multiple nodes in one package and SMC mailboxes are also per-node. So replace the per-package mutex with per-node one.
--- drivers/cpufreq/loongson3_cpufreq.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/cpufreq/loongson3_cpufreq.c +7 -7
@@ -169,7 +169,7 @@ struct loongson3_freq_data {struct cpufreq_frequency_table table[]; }; -static struct mutex cpufreq_mutex[MAX_PACKAGES ]; +static struct mutex cpufreq_mutex[MAX_NUMNODES ];static struct cpufreq_driver loongson3_cpufreq_driver; static DEFINE_PER_CPU(struct loongson3_freq_data *, freq_data);
@@ -177,14 +177,14 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext {int retries;unsigned int cpu =raw_smp_processor_id (); -unsigned int package = cpu_data[cpu].package; +unsigned int nid =cpu_to_node (cpu);union smc_message msg, last; -mutex_lock (&cpufreq_mutex[package]); +mutex_lock (&cpufreq_mutex[nid]); last.value =iocsr_read32 (LOONGARCH_IOCSR_SMCMBX );if (!last.complete) { -mutex_unlock (&cpufreq_mutex[package]); +mutex_unlock (&cpufreq_mutex[nid]);return -EPERM ; }
@@ -208,11 +208,11 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext }if (!msg.complete || msg.cmd !=CMD_OK ) { -mutex_unlock (&cpufreq_mutex[package]); +mutex_unlock (&cpufreq_mutex[nid]);return -EPERM ; } -mutex_unlock (&cpufreq_mutex[package]); +mutex_unlock (&cpufreq_mutex[nid]);return msg.val; }
@@ -337,7 +337,7 @@ static int loongson3_cpufreq_probe(struct platform_device *pdev) {int i, ret; -for (i =0 ; i <MAX_PACKAGES ; i++) { +for (i =0 ; i <MAX_NUMNODES ; i++) { ret =devm_mutex_init (&pdev->dev, &cpufreq_mutex[i]);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 835/1257 cpufreq: loongson3: Use global physical CPU ID in get/target callbacks
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huacai Chen <[email protected]>
[ Upstream commit e38360d7c62c8fa530b58905f99a4557d4d6b352 ]
Our server productions (e.g. Loongson-3D6000/3E6000) can have discrete global physical CPU IDs while the core ID inside the packages are always continuous. In these cases we should use global physical CPU IDs to get and set frequencies.
--- drivers/cpufreq/loongson3_cpufreq.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/cpufreq/loongson3_cpufreq.c +13 -10
@@ -16,6 +16,7 @@#include <asm/idle.h> #include <asm/loongarch.h> #include <asm/loongson.h> +#include <asm/smp.h> /* Message */ union smc_message {
@@ -219,38 +220,40 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 extstatic unsigned int loongson3_cpufreq_get (unsigned int cpu) { -int ret; +int ret, core =cpu_logical_map (cpu); - ret =do_service_request (cpu,FREQ_INFO_TYPE_FREQ ,CMD_GET_FREQ_INFO ,0 ,0 ); + ret =do_service_request (core,FREQ_INFO_TYPE_FREQ ,CMD_GET_FREQ_INFO ,0 ,0 ); -return ret *KILO ; +return (ret <0 ) ?0 : ret *KILO ; }static int loongson3_cpufreq_target (struct cpufreq_policy *policy,unsigned int index) { -int ret; +int ret, core =cpu_logical_map (policy->cpu); - ret =do_service_request (cpu_data[policy->cpu].core, -FREQ_INFO_TYPE_LEVEL ,CMD_SET_FREQ_INFO , index,0 ); + ret =do_service_request (core,FREQ_INFO_TYPE_LEVEL ,CMD_SET_FREQ_INFO , + index,0 );return (ret >=0 ) ?0 : ret; }static int configure_freq_table (int cpu) { -int i, ret, boost_level, max_level, freq_level; +int i, ret, core, boost_level, max_level, freq_level;struct platform_device *pdev =cpufreq_get_driver_data ();struct loongson3_freq_data *data;if (per_cpu (freq_data, cpu))return 0 ; - ret =do_service_request (cpu,0 ,CMD_GET_FREQ_LEVEL_NUM ,0 ,0 ); + core =cpu_logical_map (cpu); + + ret =do_service_request (core,0 ,CMD_GET_FREQ_LEVEL_NUM ,0 ,0 );if (ret <0 )return ret; max_level = ret; - ret =do_service_request (cpu,0 ,CMD_GET_FREQ_BOOST_LEVEL ,0 ,0 ); + ret =do_service_request (core,0 ,CMD_GET_FREQ_BOOST_LEVEL ,0 ,0 );if (ret <0 )return ret; boost_level = ret;
@@ -263,7 +266,7 @@ static int configure_freq_table(int cpu) data->def_freq_level = boost_level -1 ;for (i =0 ; i < freq_level; i++) { - ret =do_service_request (cpu,FREQ_INFO_TYPE_FREQ ,CMD_GET_FREQ_LEVEL_INFO , i,0 ); + ret =do_service_request (core,FREQ_INFO_TYPE_FREQ ,CMD_GET_FREQ_LEVEL_INFO , i,0 );if (ret <0 ) {devm_kfree (&pdev->dev, data);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 836/1257 cpufreq: loongson3: Replace IOCSR read/write with MMIO ones
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huacai Chen <[email protected]>
[ Upstream commit 81792daacfb41ca07b04bd3956ea9e672080cc98 ]
Our server productions (e.g. Loongson-3D6000/3E6000) can have multiple nodes in one package and SMC mailboxes are also per-node. However, IOCSR read/write can only perform on the current node, while sometimes we want to perform on other nodes (e.g. when switch governor, the get and target callbacks are not run on target core). So replace IOCSR read/write with MMIO ones.
--- drivers/cpufreq/loongson3_cpufreq.c | 34 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-)
drivers/cpufreq/loongson3_cpufreq.c +27 -7
@@ -17,6 +17,7 @@#include <asm/loongarch.h> #include <asm/loongson.h> #include <asm/smp.h> +#include <asm/numa.h> /* Message */ union smc_message {
@@ -165,6 +166,12 @@ union smc_message {#define FREQ_MAX_LEVEL 16 +#define MMIO_SMCMBX (node) \ + ((void __iomem *)(nid_to_addrbase(node) | IO_BASE | LOONGSON_REG_BASE | LOONGARCH_IOCSR_SMCMBX)) + +#define MMIO_MISC_FUNC (node) \ + ((void __iomem *)(nid_to_addrbase(node) | IO_BASE | LOONGSON_REG_BASE | LOONGARCH_IOCSR_MISC_FUNC)) +struct loongson3_freq_data {unsigned int def_freq_level;struct cpufreq_frequency_table table[];
@@ -177,13 +184,27 @@ static DEFINE_PER_CPU(struct loongson3_freq_data *, freq_data);static inline int do_service_request (u32 id,u32 info,u32 cmd,u32 val,u32 extra) {int retries; -unsigned int cpu =raw_smp_processor_id (); -unsigned int nid =cpu_to_node (cpu); +unsigned int cpu =0 , nid;union smc_message msg, last; +#ifdef CONFIG_SMP +switch (cmd) { +case CMD_GET_FREQ_INFO : +case CMD_SET_FREQ_INFO : +case CMD_GET_FREQ_LEVEL_NUM : +case CMD_GET_FREQ_LEVEL_INFO : +case CMD_GET_FREQ_BOOST_LEVEL : + cpu =cpu_number_map (id); +break ; +default : + cpu =raw_smp_processor_id (); + } +#endif + nid =cpu_to_node (cpu); +mutex_lock (&cpufreq_mutex[nid]); - last.value =iocsr_read32 (LOONGARCH_IOCSR_SMCMBX ); + last.value =readl (MMIO_SMCMBX (nid));if (!last.complete) {mutex_unlock (&cpufreq_mutex[nid]);return -EPERM ;
@@ -196,12 +217,11 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext msg.extra = extra; msg.complete =0 ; -iocsr_write32 (msg.value,LOONGARCH_IOCSR_SMCMBX ); -iocsr_write32 (iocsr_read32 (LOONGARCH_IOCSR_MISC_FUNC ) |IOCSR_MISC_FUNC_SOFT_INT , -LOONGARCH_IOCSR_MISC_FUNC ); +writel (msg.value,MMIO_SMCMBX (nid)); +writel (readl (MMIO_MISC_FUNC (nid)) |IOCSR_MISC_FUNC_SOFT_INT ,MMIO_MISC_FUNC (nid));for (retries =0 ; retries <10000 ; retries++) { - msg.value =iocsr_read32 (LOONGARCH_IOCSR_SMCMBX ); + msg.value =readl (MMIO_SMCMBX (nid));if (msg.complete)break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 837/1257 fuse: dont launder folios of a bad inode
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
[ Upstream commit 01d0f3d294af126f517d92c11e100525537f8be4 ]
fuse_flush() and fuse_writepages() reject writing back dirty data for any inode that has been marked bad, but fuse_launder_folio() doesn't.
This can cause the following warning in fuse_write_file_get() to trigger, as reported by syzbot:
WARNING: fs/fuse/file.c:2043 at fuse_write_file_get fs/fuse/file.c:2043 [inline]
WARNING: fs/fuse/file.c:2043 at fuse_iomap_writeback_range+0x7c8/0x18f0 fs/fuse/file.c:2227
Call Trace:
iomap_writeback_folio+0x1526/0x2490 fs/iomap/buffered-io.c:2022
fuse_launder_folio+0x17b/0x240 fs/fuse/file.c:2331
folio_unmap_invalidate+0x4cd/0x830 mm/truncate.c:634
invalidate_inode_pages2_range+0x629/0xb30 mm/truncate.c:726
fuse_open+0x5a6/0x770 fs/fuse/file.c:297This can be hit on a writeback cache mount:
1) a writeable file is open and a buffered write dirties some pages
2) another thread opens the same file read-only. fuse_open() passes the bad inode check and sends OPEN to the server.
3) a SETATTR reply with the wrong file type marks the inode bad
4) the writeable file is closed. Flush and release skip writeback because the inode is bad. The pages stay dirty but the file gets removed from write_files.
5) server replies to the OPEN. The reply has no FOPEN_KEEP_CACHE, so fuse_open() calls invalidate_inode_pages2().
6) the invalidation finds the dirty pages and calls fuse_launder_folio(), which finds no wriable file and hits the WARN_ON in fuse_write_file_get().
Instead of trying to write back dirty data for the bad inode, fuse_launder_folio() should return -EIO.
--- fs/fuse/file.c | 3 +++ 1 file changed, 3 insertions(+)
fs/fuse/file.c +3 -0
@@ -2347,6 +2347,9 @@ static int fuse_launder_folio(struct folio *folio) .wb_ctx = &data, }; +if (fuse_is_bad (wpc.inode)) +return -EIO ; +if (folio_clear_dirty_for_io (folio)) { err =iomap_writeback_folio (&wpc, folio); err =fuse_iomap_writeback_submit (&wpc, err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 838/1257 virtio_fs: read the vring size under virtio_fs_mutex in ->get_tree
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit e7ccc777a040343b80f95f4cc5c12ce1df3187f4 ]
The vring size was read after virtio_fs_find_instance() had dropped virtio_fs_mutex, so a concurrent virtio_fs_remove() could free the virtqueue first. The reference from the lookup keeps the virtio_fs alive, but not its virtqueues.
Hold the mutex across the lookup and the read.
This issue was found by an in-house static analysis tool.
--- fs/fuse/virtio_fs.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
fs/fuse/virtio_fs.c +11 -10
@@ -455,26 +455,23 @@ static int virtio_fs_add_instance(struct virtio_device *vdev,return ret; } -/* Return the virtio_fs with a given tag, or NULL */ +/* Return the virtio_fs with a given tag, or NULL. +* Callers hold virtio_fs_mutex, which also keeps the virtqueues alive. +*/ static struct virtio_fs *virtio_fs_find_instance (const char *tag) {struct virtio_fs *fs; -mutex_lock (&virtio_fs_mutex); +lockdep_assert_held (&virtio_fs_mutex);list_for_each_entry (fs, &virtio_fs_instances, list) {if (strcmp (fs->tag, tag) ==0 ) {kobject_get (&fs->kobj); - goto found; +return fs; } } - fs =NULL ;/* not found */ - -found: -mutex_unlock (&virtio_fs_mutex); - -return fs; +return NULL ;/* not found */ }static void virtio_fs_free_devs (struct virtio_fs *fs)
@@ -1698,13 +1695,17 @@ static int virtio_fs_get_tree(struct fs_context *fsc)* in chan->iq->priv. Once fuse_conn is going away, it calls ->put() * to drop the reference to this object. */ +mutex_lock (&virtio_fs_mutex); fs =virtio_fs_find_instance (fsc->source); +if (fs) + virtqueue_size =virtqueue_get_vring_size (fs->vqs[VQ_REQUEST ].vq); +mutex_unlock (&virtio_fs_mutex); +if (!fs) {pr_info ("virtio-fs: tag <%s> not found\n" , fsc->source);return -EINVAL ; } - virtqueue_size =virtqueue_get_vring_size (fs->vqs[VQ_REQUEST ].vq);if (WARN_ON (virtqueue_size <=FUSE_HEADER_OVERHEAD )) goto out_err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 839/1257 virtiofs: validate fixed-output response length
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sung Byeongchan <[email protected]>
[ Upstream commit 5364d081125a34e90851fbb46ecc93f79339ce78 ]
A short successful virtiofs response can leave the fixed-output portion of the request argument buffer unwritten. The completion path nevertheless copies the full declared output to the request destination, allowing stale allocator contents to reach callers such as fuse_statfs().
Require successful fixed-output responses to contain their complete declared output. Continue to permit a shorter final argument only for out_argvar requests. Reject positive and internal restart error values and require valid error replies to be header-only. The error already stored in the FUSE output header is returned by fuse_request_end(), so do not copy output arguments from an error reply.
This was found by source review with AI assistance. A header-only successful FUSE_STATFS reply returned stale fields in nine of nine calls across three boots. The fixed kernel rejected the short response and preserved complete replies, valid negative-error replies, and variable-output replies.
--- fs/fuse/virtio_fs.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
fs/fuse/virtio_fs.c +30 -0
@@ -727,6 +727,10 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req)unsigned int num_out;unsigned int i; +/* fuse_request_end() returns this error; there are no args to copy. */ +if (req->out.h.error) + goto out; + remaining = req->out.h.len -sizeof (req->out.h); num_in = args->in_numargs - args->in_pages; num_out = args->out_numargs - args->out_pages;
@@ -752,6 +756,7 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req)if (args->out_argvar) args->out_args[args->out_numargs -1 ].size = remaining; +out:kfree (req->argbuf); req->argbuf =NULL ; }
@@ -759,7 +764,9 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req)/* Verify that the server properly follows the FUSE protocol */ static bool virtio_fs_verify_response (struct fuse_req *req,unsigned int len) { +struct fuse_args *args = req->args;struct fuse_out_header *oh = &req->out.h; +unsigned int expected;if (len <sizeof (*oh)) {pr_warn ("virtio-fs: response too short (%u)\n" , len);
@@ -774,6 +781,29 @@ static bool virtio_fs_verify_response(struct fuse_req *req, unsigned int len) oh->unique, req->in.h.unique);return false; } +if (oh->error <= -ERESTARTSYS || oh->error >0 ) { +pr_warn ("virtio-fs: invalid error value (%d)\n" , oh->error); +return false; + } + +if (oh->error) { +if (len !=sizeof (*oh)) { +pr_warn ("virtio-fs: error response too long (%u)\n" , len); +return false; + } +return true; + } + + expected =sizeof (*oh) + +fuse_len_args (args->out_numargs, args->out_args); +if (len > expected || + (len < expected && + (!args->out_argvar || + expected - len > args->out_args[args->out_numargs -1 ].size))) { +pr_warn ("virtio-fs: invalid response length (%u, expected %u)\n" , + len, expected); +return false; + }return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 840/1257 ASoC: amd: acp-config: force SoundWire probe on Dell 14S DS14265
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Art O Cathain <[email protected]>
[ Upstream commit 38cb2ef26b6411277826da54c6bcf94523541058 ]
The BIOS on the Dell 14S DS14265 (ACP PCI revision 0x72) reports acp-audio-config-flag = FLAG_AMD_LEGACY_ONLY_DMIC. As a result snd_pci_ps returns early and the SoundWire links are never scanned, while the legacy snd_acp_pci driver probes the device, finds no matching machine driver ("No matching ASoC machine driver found") and no internal sound card is created. The CS42L45 headset codec on link 0 and the two CS35L63 speaker amplifiers on link 1 never enumerate.
Add a DMI entry for the model to the ACP70 ACPI flag override table so the firmware-provided flag is overridden and snd_pci_ps probes instead. Match on the product name rather than the board name, as the same symptom has been reported on several boards of this model (09PVND, 0M0J65, 0C7F12).
Tested on a DS14265 (board 09PVND, BIOS 1.5.3) with Debian's 7.2.6 kernel, with and without this entry. With it, snd_pci_ps binds, both SoundWire links come up, the CS42L45 and both CS35L63 enumerate, the existing CS42L45 + 2x CS35L63 machine entry matches, the amplifiers load their firmware and calibration, and the amd-soundwire card plays through both the internal speakers and the headphone jack. Also build-tested on asoc-next with W=1.
Developed with AI assistance. Claude read the ACP driver source, identified the BIOS flag as the cause and the override table as the fix, wrote the DMI entry and the out-of-tree test module, and drafted this changelog. All hardware testing was done by the submitter, who has reviewed the change, understands it and takes responsibility for it.
--- sound/soc/amd/acp-config.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/soc/amd/acp-config.c +7 -0
@@ -98,6 +98,13 @@ static const struct dmi_system_id acp70_acpi_flag_override_table[] = { DMI_MATCH(DMI_BOARD_NAME, "8EA2"), }, }, + { + /* Dell 14S DS14265 */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Dell 14S DS14265"), + }, + }, {} };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 841/1257 fuse: fix copy_file_range reply handling race
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit bf4ccbaad8bdff8c90fd290ed6135b63f89ee8a7 ]
__fuse_copy_file_range() selects its request opcode and output buffer using fc->no_copy_file_range_64, then reads the flag again to handle the reply. Copies to different destination inodes can run concurrently on the same connection, so the flag may change while a request is pending.
For example, task A submits FUSE_COPY_FILE_RANGE_64 and waits for its reply. Task B submits the same opcode, receives -ENOSYS and sets no_copy_file_range_64. When A receives a successful reply, it reads the uninitialized outarg.size instead of outarg_64.bytes_copied. This can produce an incorrect return value, page cache invalidation range and inode size update, and disclose stack contents if automatic stack initialization is disabled.
If A also receives -ENOSYS, it instead mistakes that reply for rejection of the legacy opcode and sets no_copy_file_range, skipping the legacy fallback and unnecessarily disabling copy offload for the connection.
KCSAN reported the conflicting accesses:
BUG: KCSAN: data-race in __fuse_copy_file_range / __fuse_copy_file_range
read to 0xffff8881014a4d4d of 1 bytes by task 123 on cpu 4:
__fuse_copy_file_range+0x1a7/0x6e0 fuse_copy_file_range+0x54/0xd0 vfs_copy_file_range+0x290/0x9d0 __do_sys_copy_file_range+0x10f/0x2f0
write to 0xffff8881014a4d4d of 8 bytes by task 119 on cpu 0:
__fuse_copy_file_range+0x633/0x6e0 fuse_copy_file_range+0x54/0xd0 vfs_copy_file_range+0x290/0x9d0 __do_sys_copy_file_range+0x10f/0x2f0
The bug can lead to leak kernel base address for KASLR bypass, the corresponding reproducer can be provided per request.
Use args.opcode for both -ENOSYS handling and output buffer selection. It records the opcode actually sent and is updated on fallback, keeping each reply tied to its request regardless of concurrent flag updates.
--- fs/fuse/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/fuse/file.c +2 -2
@@ -3042,7 +3042,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, } err =fuse_simple_request (fm, &args);if (err == -ENOSYS ) { -if (fc->no_copy_file_range_64) { +if (args.opcode ==FUSE_COPY_FILE_RANGE ) { fc->no_copy_file_range =1 ; err = -EOPNOTSUPP ; }else {
@@ -3053,7 +3053,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,if (err) goto out; - bytes_copied = fc->no_copy_file_range_64 ? + bytes_copied = args.opcode ==FUSE_COPY_FILE_RANGE ? outarg.size : outarg_64.bytes_copied;if (bytes_copied > len) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 842/1257 ublk: pin module while release work is pending
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: sonotri <[email protected]>
[ Upstream commit afc9cde716b29ce814798d649a95f9128ba42b43 ]
ublk_ch_release() takes a device reference and queues exit_work. The VFS module reference held through the file operations is dropped after ->release() returns. A queued work item does not acquire its own module reference for the callback.
Consequently, normal module removal can start while exit_work is pending or executing. In addition to the worker callback itself, the final device put can invoke ublk_cdev_rel(), which is also module code.
Take a module reference while ->release() is still covered by the file operations reference and drop it only after the worker has completed its final device put. A rearming worker retains the same reference.
Merely canceling exit_work during module exit is insufficient. The worker is the terminal path for the device reference taken by ublk_ch_release(), so its cancellation would strand that reference and skip the associated cleanup.
--- drivers/block/ublk_drv.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/block/ublk_drv.c +3 -0
@@ -2637,6 +2637,7 @@ static void ublk_ch_release_work_fn(struct work_struct *work)/* put the reference grabbed in ublk_ch_release() */ ublk_put_device (ub); +module_put (THIS_MODULE ); }static int ublk_ch_release (struct inode *inode,struct file *filp)
@@ -2652,6 +2653,8 @@ static int ublk_ch_release(struct inode *inode, struct file *filp)*/ ublk_get_device (ub); +/* Keep the worker's callback and final device release code resident. */ +__module_get (THIS_MODULE );INIT_DELAYED_WORK (&ub->exit_work, ublk_ch_release_work_fn);schedule_delayed_work (&ub->exit_work,0 );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 843/1257 ipc, msg: Account msg_msg allocations with GFP_KERNEL_ACCOUNT again
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kees Cook <[email protected]>
[ Upstream commit c57fbbe42e907fa26c5ffada52d913d4ca5fa66e ]
Since commit 734bbc1c97ea7 ("ipc, msg: Use dedicated slab buckets for alloc_msg()"), alloc_msg() allocates with GFP_KERNEL, and a msg_msg is accounted only through SLAB_ACCOUNT on its bucket caches. With CONFIG_SLAB_BUCKETS=n, kmem_buckets_create() creates no caches and kmem_buckets_alloc() is a GFP_KERNEL kmalloc() from the general caches, which do not account it; the same happens when kmem_buckets_create() fails. Either way, the allocation is not charged to the sender's memory cgroup.
Allocate with GFP_KERNEL_ACCOUNT again, as before that commit, so the allocation is charged whichever cache serves it.
Build tested ARCH=x86_64 defconfig with GCC 16.2.0, with CONFIG_SLAB_BUCKETS as y and n.
--- ipc/msgutil.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ipc/msgutil.c +2 -1
@@ -58,7 +58,8 @@ static struct msg_msg *alloc_msg(size_t len)size_t alen; alen =min (len,DATALEN_MSG ); - msg =kmem_buckets_alloc (msg_buckets,sizeof (*msg) + alen,GFP_KERNEL ); + msg =kmem_buckets_alloc (msg_buckets,sizeof (*msg) + alen, +GFP_KERNEL_ACCOUNT );if (msg ==NULL )return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 844/1257 mptcp: reset msk state on early connect failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quanye Yang <[email protected]>
[ Upstream commit 29afe67082b2d33ab2e90c56c337235d725f023f ]
mptcp_connect() can fall back before the subflow SYN is sent, for example when the netns is in an MPTCP blackhole, token allocation fails, or MD5SIG is in use. If the subsequent subflow connect() fails immediately (EAFNOSUPPORT, ENETUNREACH, ...), __inet_stream_connect() returns while the socket is still SS_UNCONNECTED and never calls ->disconnect(). This was reported by Clashiko [1].
The error path only dropped the token and moved the msk back to TCP_CLOSE. MPTCP_FALLBACK_DONE, allow_subflows and request_mptcp were left as after early fallback, so a later connect() on the same fd stayed TCP-only.
--- net/mptcp/protocol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +8 -1
@@ -4233,9 +4233,16 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,* subflow_finish_connect() */ if (unlikely (err)) { -/* avoid leaving a dangling token in an unconnected socket */ mptcp_token_destroy (msk);mptcp_set_state (sk,TCP_CLOSE ); + +spin_lock_bh (&msk->fallback_lock); + msk->allow_subflows = true; + msk->allow_infinite_fallback = true; +clear_bit (MPTCP_FALLBACK_DONE , &msk->flags); +spin_unlock_bh (&msk->fallback_lock); + +mptcp_subflow_ctx_reset (mptcp_subflow_ctx (ssk));return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 845/1257 mptcp: fix subflow bitfield misuse
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit 7538fa33bb2f66b8b809ff39d58308be48e197a0 ]
The subflow status bitfield is protected by the subflow socket lock, with one notable exception: the close_event_done bit is actually under the msk socket lock protection.
As reported by Clashiko [1], flipping the latter bit may corrupt other entries in the same bitfield.
Move the close_event_done outside the bitfield, in a 32bit hole.
--- net/mptcp/protocol.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/mptcp/protocol.h +4 -2
@@ -583,14 +583,16 @@ struct mptcp_subflow_context { closing : 1, /* must not pass rx data to msk anymore */ valid_csum_seen : 1, /* at least one csum validated */ is_mptfo : 1, /* subflow is doing TFO */ - close_event_done : 1, /* has done the post-closed part */ mpc_drop : 1, /* the MPC option has been dropped in a rtx */ resetting : 1, /* subflow is resetting */ - __unused : 8; + __unused : 9;bool data_avail;bool scheduled;bool pm_listener;/* a listener managed by the kernel PM? */ bool fully_established;/* path validated */ +bool close_event_done;/* has done the post-closed part, +* protected by msk socket lock +*/ u32 lent_mem_frag;u32 remote_nonce;u64 thmac;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 846/1257 ALSA: seq: oss: Skip events until fully initialized
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 68d4a6ea6cc6091a05836f783bc17d525d266d0b ]
When an OSS sequencer device is opened, it creates a sequencer port, then further initializes the internal states like a timer instance, etc. Since the sequencer port is published, an event can be already delivered, and this may hit unexpected event handling, which can eventually cause a NULL dereference (like the timer start/stop event triggered before the timer initialization).
For avoiding such a race, introduce a simple guard and skips the event processing until the port is fully initialized.
At releasing the device, in turn, clear this guard, so that any input events will be discarded during the teardown.
--- sound/core/seq/oss/seq_oss_device.h | 1 + sound/core/seq/oss/seq_oss_event.c | 3 +++ sound/core/seq/oss/seq_oss_init.c | 2 ++ 3 files changed, 6 insertions(+)
sound/core/seq/oss/seq_oss_device.h +1 -0
@@ -72,6 +72,7 @@ struct seq_oss_devinfo {int cseq;/* sequencer client number */ int port;/* sequencer port number */ int queue;/* sequencer queue number */ +bool initialized;struct snd_seq_addr addr;/* address of this device */
sound/core/seq/oss/seq_oss_event.c +3 -0
@@ -425,6 +425,9 @@ snd_seq_oss_event_input(struct snd_seq_event *ev, int direct, void *private_datastruct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private_data;union evrec *rec; +if (!dp || !smp_load_acquire (&dp->initialized)) +return 0 ;/* ignored */ +if (ev->type !=SNDRV_SEQ_EVENT_ECHO )return snd_seq_oss_midi_input (ev, direct, private_data);
sound/core/seq/oss/seq_oss_init.c +2 -0
@@ -258,6 +258,7 @@ snd_seq_oss_open(struct file *file, int level) client_table[dp->index] = dp; num_clients++; +smp_store_release (&dp->initialized, true);return 0 ;
@@ -403,6 +404,7 @@ snd_seq_oss_release(struct seq_oss_devinfo *dp) client_table[dp->index] =NULL ; num_clients--; +smp_store_release (&dp->initialized, false);snd_seq_oss_reset (dp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 847/1257 ALSA: hda/realtek: Enable mute LEDs on HP OmniBook X Flip 14-fm0xxx
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: José Miguel Castellanos Valladolid <[email protected]>
[ Upstream commit c80286aaa4acd52f9bd0b0d4914d2069fe6ba3a8 ]
The HP OmniBook X Flip Laptop 14-fm0xxx (subsystem ID 0x103c8d9f, ALC245 with two CS35L41 amplifiers over I2C) is currently handled by ALC287_FIXUP_CS35L41_I2C_2. That binds the amplifiers but does not set up the mute LEDs, so neither the speaker mute key LED nor the microphone mute key LED lights up under Linux. With that fixup the codec GPIOs stay disabled (IO[0..2] enable=0).
Switch the entry to ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS, which chains cs35l41_fixup_i2c_two with ALC245_FIXUP_HP_X360_MUTE_LEDS. This keeps the amplifier setup and adds the speaker mute LED through the ALC245 COEF register and the mic mute LED through codec GPIO2. It is the same fixup already used for the 17 Turbine OmniBook 7 DIS (0x103c8d9c).
Tested on the affected laptop with v7.2.11 using the equivalent ALC245_FIXUP_HP_ENVY_X360_15_FH0XXX fixup, which has the identical cs35l41_fixup_i2c_two + ALC245_FIXUP_HP_X360_MUTE_LEDS chain: hda::mute and hda::micmute LED class devices appear and both key LEDs light up when muting.
--- sound/hda/codecs/realtek/alc269.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/codecs/realtek/alc269.c +1 -1
@@ -7762,7 +7762,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x103c ,0x8d9c ,"HP 17 Turbine OmniBook 7 DIS" ,ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS ),SND_PCI_QUIRK (0x103c ,0x8d9d ,"HP 17 Turbine OmniBook X UMA" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8d9e ,"HP 17 Turbine OmniBook X DIS" ,ALC287_FIXUP_CS35L41_I2C_2 ), -SND_PCI_QUIRK (0x103c ,0x8d9f ,"HP 14 Cadet (x360)" ,ALC287_FIXUP_CS35L41_I2C_2 ), +SND_PCI_QUIRK (0x103c ,0x8d9f ,"HP 14 Cadet (x360)" ,ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS ),SND_PCI_QUIRK (0x103c ,0x8da0 ,"HP 16 Clipper OmniBook 7(X360)" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8da1 ,"HP 16 Clipper OmniBook X" ,ALC287_FIXUP_CS35L41_I2C_2 ), SND_PCI_QUIRK(0x103c, 0x8da7, "HP 14 Enstrom OmniBook X", ALC287_FIXUP_CS35L41_I2C_2),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 848/1257 ALSA: hda/realtek: Fix internal speakers on Acer Aspire AL16-31P
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luis Gerardo Lopez Hernandez <[email protected]>
[ Upstream commit d933955c456e0573b40eae4f72a3af37ab1c15c3 ]
The Acer Aspire AL16-31P (Intel Alder Lake-N, Realtek ALC269VC, PCI/codec SSID 2782:1718) has its internal speakers wired to pin 0x1b, but the BIOS marks that pin as not connected (0x411111f0) and only exposes pin 0x14 as the speaker. As a result the internal speakers are silent while headphones, HDMI and Bluetooth work.
This is the same layout as the Infinix Y4 Max and MEDION E15433, which share the 0x2782 subsystem vendor. Reuse their fixup, which configures pin 0x1b as an internal speaker and limits the internal mic boost.
Tested by booting with snd-hda-intel model=2782:1705: the fixup is picked, pin 0x1b is used as a speaker output, the internal speakers work, and they are muted when headphones are plugged in.
--- sound/hda/codecs/realtek/alc269.c | 1 + 1 file changed, 1 insertion(+)
sound/hda/codecs/realtek/alc269.c +1 -0
@@ -8460,6 +8460,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x2782 ,0x1701 ,"Infinix Y4 Max" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1705 ,"MEDION E15433" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1707 ,"Vaio VJFE-ADL" ,ALC298_FIXUP_SPK_VOLUME ), +SND_PCI_QUIRK (0x2782 ,0x1718 ,"Acer Aspire AL16-31P" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x4900 ,"MEDION E15443" ,ALC233_FIXUP_MEDION_MTL_SPK ),SND_PCI_QUIRK (0x2782 ,0xa128 ,"Positivo N15RPE-S" ,ALC269_FIXUP_LIMIT_INT_MIC_BOOST ), SND_PCI_QUIRK(0x2782, 0xa212, "Lunnen Ground 14", ALC269VC_FIXUP_LUNNEN_GROUND_14),
Signature · 1 line
2.53.0