6.12.97-rc1 review
Subsystems (12)
Greg Kroah-Hartman
maintainerPATCH 802/1276 net/mlx5: Fix L3 tunnel entropy refcount leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit c914307e1d41c2cb7bcdcbfde4cd2f214f6aa027 ]
mlx5_tun_entropy_refcount_inc() counts both VXLAN and L2-to-L3 tunnel reformat entries as entropy-enabling users. The matching decrement path only handled VXLAN, leaving L2-to-L3 tunnel entries counted after release.
Handle MLX5_REFORMAT_TYPE_L2_TO_L3_TUNNEL in mlx5_tun_entropy_refcount_dec() as well so the enabling entry refcount remains balanced.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/port_tun.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/port_tun.c +2 -1
@@ -176,7 +176,8 @@ void mlx5_tun_entropy_refcount_dec(struct mlx5_tun_entropy *tun_entropy, int reformat_type) {mutex_lock (&tun_entropy->lock); -if (reformat_type ==MLX5_REFORMAT_TYPE_L2_TO_VXLAN ) +if (reformat_type ==MLX5_REFORMAT_TYPE_L2_TO_VXLAN || + reformat_type ==MLX5_REFORMAT_TYPE_L2_TO_L3_TUNNEL ) tun_entropy->num_enabling_entries--;else if (reformat_type ==MLX5_REFORMAT_TYPE_L2_TO_NVGRE && --tun_entropy->num_disabling_entries ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 803/1276 octeontx2-af: fix VF bringup affecting PF promiscuous state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harman Kalra <[email protected]>
[ Upstream commit fabb881df322da25442f98d23f5fa371e3c78ec4 ]
Mbox handling of nix_set_rx_mode for a VF with promiscuous and all_multi flags set to false causes deletion of the PF's promiscuous and allmulti MCAM rules. This occurs because the APIs that enable/disable these rules operate only on the PF, even when the mbox request is made via a VF interface.
Guard both rvu_npc_enable_allmulti_entry() and rvu_npc_enable_promisc_entry() disable paths with an is_vf() check so that a VF bringing up or tearing down its interface cannot inadvertently clear the PF's MCAM rules.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +2 -2
@@ -4473,7 +4473,7 @@ int rvu_mbox_handler_nix_set_rx_mode(struct rvu *rvu, struct nix_rx_mode *req,rvu_npc_install_allmulti_entry (rvu, pcifunc, nixlf, pfvf->rx_chan_base); }else { -if (!nix_rx_multicast) +if (!nix_rx_multicast && !is_vf (pcifunc))rvu_npc_enable_allmulti_entry (rvu, pcifunc, nixlf, false); }
@@ -4483,7 +4483,7 @@ int rvu_mbox_handler_nix_set_rx_mode(struct rvu *rvu, struct nix_rx_mode *req, pfvf->rx_chan_base, pfvf->rx_chan_cnt); else - if (!nix_rx_multicast) + if (!nix_rx_multicast && !is_vf(pcifunc))rvu_npc_enable_promisc_entry (rvu, pcifunc, nixlf, false);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 804/1276 drm/xe: remove duplicate <kunit/test-bug.h> include
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anas Khan <[email protected]>
[ Upstream commit 91426ce50d14a49bde53b3ad1e48393556ba92cd ]
xe_pci.c includes <kunit/test-bug.h> twice, separated only by the <kunit/test.h> include. Drop the redundant second include; this is a non-functional cleanup flagged by scripts/checkincludes.pl.
--- drivers/gpu/drm/xe/tests/xe_pci.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/xe/tests/xe_pci.c +0 -1
@@ -9,7 +9,6 @@#include <kunit/test-bug.h> #include <kunit/test.h> -#include <kunit/test-bug.h> #include <kunit/visibility.h> /**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 805/1276 smb: client: fix overflow in passthrough ioctl bounds check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit a4f27ad055392fa164f5649e89a3637b033c5fcc ]
smb2_ioctl_query_info() validates the PASSTHRU_FSCTL response payload before copying it to userspace.
The payload offset and length both come from 32-bit fields. The bounds check currently adds OutputOffset and qi.input_buffer_length directly, so the addition can wrap in 32-bit arithmetic before the result is compared against the response buffer length.
A malicious server can use a large OutputOffset and a small OutputCount to make the wrapped sum pass the bounds check. The later copy_to_user() then reads from io_rsp + OutputOffset, outside the response buffer.
Use size_add() for the offset plus length check so overflow is treated as out of bounds.
--- fs/smb/client/smb2ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/smb2ops.c +2 -2
@@ -1771,8 +1771,8 @@ smb2_ioctl_query_info(const unsigned int xid,if (le32_to_cpu (io_rsp->OutputCount) < qi.input_buffer_length) qi.input_buffer_length =le32_to_cpu (io_rsp->OutputCount);if (qi.input_buffer_length >0 && -le32_to_cpu (io_rsp->OutputOffset) + qi.input_buffer_length - > rsp_iov[1 ].iov_len) { +size_add (le32_to_cpu (io_rsp->OutputOffset), + qi.input_buffer_length) > rsp_iov[1 ].iov_len) { rc = -EFAULT ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 806/1276 mlxsw: fix refcount leak in mlxsw_sp_port_lag_join()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 41c8c1d65b32beacd8d916a22457b4f6e47f45af upstream.
When mlxsw_sp_port_lag_index_get() fails, mlxsw_sp_port_lag_join() returns an error without releasing the lag reference obtained by the earlier mlxsw_sp_lag_get(). All other error paths in the function jump to the cleanup label that ends with mlxsw_sp_lag_put(), so this is a single missed release.
Fix the leak by replacing the bare 'return err' with a goto to the existing error cleanup label, which will drop the reference safely.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +1 -1
@@ -4507,7 +4507,7 @@ static int mlxsw_sp_port_lag_join(struct lag_id = lag->lag_id; err =mlxsw_sp_port_lag_index_get (mlxsw_sp, lag_id, &port_index);if (err) -return err; + goto err_lag_uppers_bridge_join; err =mlxsw_sp_lag_uppers_bridge_join (mlxsw_sp_port, lag_dev, extack);
Greg Kroah-Hartman
maintainerPATCH 807/1276 mlxsw: fix refcount leak in mlxsw_sp_vrs_lpm_tree_replace()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 21cf8dc478a49e8de039c2739b1646a774cb1944 upstream.
When mlxsw_sp_vrs_lpm_tree_replace() fails after replacing some VRs, the error rollback loop does not correctly revert the preceding replacements. The loop decrements the index but fails to update the vr pointer, which still points to the VR that caused the failure. As a result, the condition and the rollback call always operate on the same VR, potentially calling mlxsw_sp_vr_lpm_tree_replace() multiple times on it while never rolling back the earlier VRs. Those VRs continue to hold a reference to new_tree acquired via mlxsw_sp_lpm_tree_hold(), leaking the reference count of new_tree.
Fix by reinitializing vr inside the error loop with the updated index:
vr = &mlxsw_sp->router->vrs[i];
so that the loop correctly iterates over all VRs that were actually replaced.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +1 -0
@@ -1019,6 +1019,7 @@ static int mlxsw_sp_vrs_lpm_tree_replace err_tree_replace:for (i--; i >=0 ; i--) { + vr = &mlxsw_sp->router->vrs[i];if (!mlxsw_sp_vr_lpm_tree_should_replace (vr, proto, new_id))continue ; mlxsw_sp_vr_lpm_tree_replace(mlxsw_sp,
Greg Kroah-Hartman
maintainerPATCH 808/1276 vduse: Fix race in vduse_dev_msg_sync and vduse_dev_read_iter
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Tianci <[email protected]>
commit ae9c13b6fd79087cc5a216ee1649b6f012c2a238 upstream.
There is one race case in vduse_dev_msg_sync and vduse_dev_read_iter:
vduse_dev_read_iter():
lock(msg_lock);
dequeue_msg(send_list);
unlock(msg_lock);
vduse_dev_msg_sync():
wait_timeout() finish
lock(msg_lock);
check msg->complete is false
list_del(msg); <- double list_del() crash!To fix this case, we shall ensure vduse_msg is on send_list or recv_list outside the msg_lock critical section.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_user/vduse_dev.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
drivers/vdpa/vdpa_user/vduse_dev.c +27 -10
@@ -330,6 +330,7 @@ static ssize_t vduse_dev_read_iter(strucstruct file *file = iocb->ki_filp;struct vduse_dev *dev = file->private_data;struct vduse_dev_msg *msg; +struct vduse_dev_request req;int size =sizeof (struct vduse_dev_request );ssize_t ret;
@@ -341,12 +342,11 @@ static ssize_t vduse_dev_read_iter(struc msg =vduse_dequeue_msg (&dev->send_list);if (msg)break ; +spin_unlock (&dev->msg_lock); - ret = -EAGAIN ;if (file->f_flags &O_NONBLOCK ) - goto unlock; +return -EAGAIN ; -spin_unlock (&dev->msg_lock); ret =wait_event_interruptible_exclusive (dev->waitq, !list_empty (&dev->send_list));if (ret)
@@ -354,17 +354,34 @@ static ssize_t vduse_dev_read_iter(strucspin_lock (&dev->msg_lock); } + +memcpy (&req, &msg->req,sizeof (req)); +/* +* We must ensure vduse_msg is on send_list or recv_list before unlock +* dev->msg_lock. Because vduse_dev_msg_sync() may be timeout when we +* copy data to userspace, and will call list_del() for this msg. +*/ +vduse_enqueue_msg (&dev->recv_list, msg);spin_unlock (&dev->msg_lock); - ret =copy_to_iter (&msg->req, size, to); -spin_lock (&dev->msg_lock); + + ret =copy_to_iter (&req, size, to);if (ret != size) { +/* +* Roll back: move msg back to send_list if still pending. +* +* NOTE: +* vduse_find_msg() must use req.request_id instead of `msg`. +* A malicious userspace may reply to this request, and wake up +* the caller, after which `msg` will have already been freed. +* And here vduse_find_msg() will return NULL then do nothing. +*/ +spin_lock (&dev->msg_lock); + msg =vduse_find_msg (&dev->recv_list, req.request_id); +if (msg) +vduse_enqueue_msg_head (&dev->send_list, msg); +spin_unlock (&dev->msg_lock); ret = -EFAULT ; -vduse_enqueue_msg_head (&dev->send_list, msg); - goto unlock; } -vduse_enqueue_msg (&dev->recv_list, msg); -unlock: -spin_unlock (&dev->msg_lock);return ret; }
Greg Kroah-Hartman
maintainerPATCH 809/1276 ASoC: SOF: ipc4-control: Fix TOCTOU in sof_ipc4_bytes_put
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 3ad673e7139cf214afd24321a829aad6575f4163 upstream.
In sof_ipc4_bytes_put(), the copy size is derived from the old data->size in the buffer rather than the incoming new data's size field from ucontrol. If the new data has a different size, the copy uses the wrong length: it may truncate valid data or copy stale bytes.
Fix by validating and using the incoming data's sof_abi_hdr.size from ucontrol before copying.
--- sound/soc/sof/ipc4-control.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
sound/soc/sof/ipc4-control.c +7 -4
@@ -455,6 +455,8 @@ static int sof_ipc4_bytes_put(struct sndstruct snd_soc_component *scomp = scontrol->scomp;struct snd_sof_dev *sdev =snd_soc_component_get_drvdata (scomp);struct sof_abi_hdr *data = cdata->data; +const struct sof_abi_hdr *new_hdr = + (const struct sof_abi_hdr *)ucontrol->value.bytes.data;size_t size;int ret;
@@ -465,15 +467,16 @@ static int sof_ipc4_bytes_put(struct sndreturn -EINVAL ; } -/* scontrol->max_size has been verified to be >= sizeof(struct sof_abi_hdr) */ -if (data->size > scontrol->max_size -sizeof (*data)) { +/* Validate the new data's size, not the old one */ +if (new_hdr->size > scontrol->max_size -sizeof (*new_hdr)) {dev_err_ratelimited (scomp->dev,"data size too big %u bytes max is %zu\n" , - data->size, scontrol->max_size -sizeof (*data)); + new_hdr->size, + scontrol->max_size -sizeof (*new_hdr));return -EINVAL ; } - size = data->size +sizeof (*data); + size = new_hdr->size +sizeof (*new_hdr);/* copy from kcontrol */ memcpy (data, ucontrol->value.bytes.data, size);
Greg Kroah-Hartman
maintainerPATCH 810/1276 ASoC: SOF: ipc3-control: Use overflow checks in control_update size calc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 8791977d7289f6e9d2b014f60a5455f053a7bc04 upstream.
In sof_ipc3_control_update(), the expected_size calculation uses firmware-provided cdata->num_elems in arithmetic that could overflow on 32-bit platforms, wrapping to a small value. This would allow the cdata->rhdr.hdr.size comparison to pass with mismatched sizes, potentially leading to out-of-bounds access in snd_sof_update_control.
Use check_mul_overflow() and check_add_overflow() to detect and reject overflowed size calculations.
--- sound/soc/sof/ipc3-control.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
sound/soc/sof/ipc3-control.c +16 -4
@@ -626,16 +626,28 @@ static void sof_ipc3_control_update(strureturn ; } - expected_size =sizeof (struct sof_ipc_ctrl_data );switch (cdata->type) {case SOF_CTRL_TYPE_VALUE_CHAN_GET :case SOF_CTRL_TYPE_VALUE_CHAN_SET : - expected_size += cdata->num_elems * -sizeof (struct sof_ipc_ctrl_value_chan ); +if (check_mul_overflow ((size_t )cdata->num_elems, +sizeof (struct sof_ipc_ctrl_value_chan ), + &expected_size)) +return ; +if (check_add_overflow (expected_size, +sizeof (struct sof_ipc_ctrl_data ), + &expected_size)) +return ;break ;case SOF_CTRL_TYPE_DATA_GET :case SOF_CTRL_TYPE_DATA_SET : - expected_size += cdata->num_elems +sizeof (struct sof_abi_hdr ); +if (check_add_overflow ((size_t )cdata->num_elems, +sizeof (struct sof_abi_hdr ), + &expected_size)) +return ; +if (check_add_overflow (expected_size, +sizeof (struct sof_ipc_ctrl_data ), + &expected_size)) +return ;break ;default :return ;
Greg Kroah-Hartman
maintainerPATCH 811/1276 ASoC: SOF: ipc3-control: Fix TOCTOU in bytes_put and bytes_get
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 1f97760417b5faa60e9642fd0ed61eb17d0b1b39 upstream.
In sof_ipc3_bytes_put(), the size used for the memcpy is derived from the old data->size already in the buffer, not the incoming new data's size field. If the new data has a different size, the copy length is
wrong: it may truncate valid data or copy stale bytes.
Similarly, sof_ipc3_bytes_get() checks data->size against max_size without accounting for the sizeof(struct sof_ipc_ctrl_data) offset of the flex array within the allocation.
Fix bytes_put to validate and use the incoming data's sof_abi_hdr.size from ucontrol before copying. Fix bytes_get to subtract sizeof(*cdata) from the bounds check to match the actual available space.
--- sound/soc/sof/ipc3-control.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
sound/soc/sof/ipc3-control.c +16 -7
@@ -315,10 +315,13 @@ static int sof_ipc3_bytes_get(struct snd }/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ -if (data->size > scontrol->max_size -sizeof (*data)) { +if (data->size > scontrol->max_size -sizeof (*cdata) - +sizeof (*data)) {dev_err_ratelimited (scomp->dev,"%u bytes of control data is invalid, max is %zu\n" , - data->size, scontrol->max_size -sizeof (*data)); + data->size, + scontrol->max_size -sizeof (*cdata) - +sizeof (*data));return -EINVAL ; }
@@ -336,6 +339,8 @@ static int sof_ipc3_bytes_put(struct sndstruct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;struct snd_soc_component *scomp = scontrol->scomp;struct sof_abi_hdr *data = cdata->data; +const struct sof_abi_hdr *new_hdr = + (const struct sof_abi_hdr *)ucontrol->value.bytes.data;size_t size;if (scontrol->max_size >sizeof (ucontrol->value.bytes.data)) {
@@ -344,14 +349,18 @@ static int sof_ipc3_bytes_put(struct sndreturn -EINVAL ; } -/* scontrol->max_size has been verified to be >= sizeof(struct sof_abi_hdr) */ -if (data->size > scontrol->max_size -sizeof (*data)) { -dev_err_ratelimited (scomp->dev,"data size too big %u bytes max is %zu\n" , - data->size, scontrol->max_size -sizeof (*data)); +/* Validate the new data's size, not the old one */ +if (new_hdr->size > scontrol->max_size -sizeof (*cdata) - +sizeof (*new_hdr)) { +dev_err_ratelimited (scomp->dev, +"data size too big %u bytes max is %zu\n" , + new_hdr->size, + scontrol->max_size -sizeof (*cdata) - +sizeof (*new_hdr));return -EINVAL ; } - size = data->size +sizeof (*data); + size = new_hdr->size +sizeof (*new_hdr);/* copy from kcontrol */ memcpy (data, ucontrol->value.bytes.data, size);
Greg Kroah-Hartman
maintainerPATCH 812/1276 ASoC: SOF: topology: validate vendor array size before parsing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
commit 8468dd79cfb2ffbdeaf7c353f63d64941cb8ba05 upstream.
sof_parse_token_sets() reads array->size while iterating over topology private data. The loop condition only checks that some data remains, so a malformed topology with a truncated trailing vendor array can make the parser read the size field before a full vendor-array header is available.
Validate that the remaining private data contains a complete snd_soc_tplg_vendor_array header before reading array->size.
The declared array size check also needs to remain signed. asize is an int, but sizeof(*array) has type size_t, so comparing them directly promotes negative asize values to unsigned and lets them pass the check, as reported in the stable review thread reference below.
Cast sizeof(*array) to int when validating the declared array size. This rejects negative, zero and otherwise too-small sizes before the parser dispatches to the tuple-specific code.
--- sound/soc/sof/topology.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
sound/soc/sof/topology.c +4 -1
@@ -721,10 +721,13 @@ static int sof_parse_token_sets(struct sint ret;while (array_size >0 && total < count * token_instance_num) { +if (array_size < (int )sizeof (*array)) +return -EINVAL ; + asize =le32_to_cpu (array->size);/* validate asize */ -if (asize <sizeof (*array)) { +if (asize < (int )sizeof (*array)) {dev_err (scomp->dev,"error: invalid array size 0x%x\n" , asize);return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 813/1276 net: qrtr: fix 32-bit integer overflow in qrtr_endpoint_post()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 20054869770c7df060c5ecee3e8bbf9029c47191 upstream.
qrtr_endpoint_post() validates an incoming packet with
if (!size || len != ALIGN(size, 4) + hdrlen) goto err;
where size comes from the wire. On 32-bit, size_t is 32 bits and ALIGN(size, 4) wraps to 0 for size >= 0xfffffffd, so the check passes and skb_put_data(skb, data + hdrlen, size) writes past the hdrlen-sized skb and oopses the kernel. 64-bit is unaffected.
This is the 32-bit residual of ad9d24c9429e2 ("net: qrtr: fix OOB Read in qrtr_endpoint_post"), which fixed only the 64-bit case.
Reject any size that cannot fit the buffer before the ALIGN.
--- net/qrtr/af_qrtr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/qrtr/af_qrtr.c +1 -1
@@ -496,7 +496,7 @@ int qrtr_endpoint_post(struct qrtr_endpoif (cb->dst_port ==QRTR_PORT_CTRL_LEGACY ) cb->dst_port =QRTR_PORT_CTRL ; -if (!size || len !=ALIGN (size,4 ) + hdrlen) +if (!size || size > len || len !=ALIGN (size,4 ) + hdrlen) goto err; if ((cb->type == QRTR_TYPE_NEW_SERVER ||
Greg Kroah-Hartman
maintainerPATCH 814/1276 net: atm: reject out-of-range traffic classes in QoS validation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhengchuan Liang <[email protected]>
commit cdf19f380e46192e7084be559638aab1f6ed86a2 upstream.
Reject ATM traffic classes above ATM_ANYCLASS in check_tp(). SO_ATMQOS stores the supplied QoS after check_qos() succeeds, so accepting larger values leaves invalid traffic_class values in vcc->qos.
That bad state later reaches pvc_info(), which indexes class_name[] with vcc->qos.{rx,tp}.traffic_class. Values above ATM_ANYCLASS cause an out-of-bounds read when /proc/net/atm/pvc is read.
Tighten the existing QoS validation so invalid traffic_class values are rejected at the point where user supplied QoS is accepted.
--- net/atm/common.c | 2 ++ 1 file changed, 2 insertions(+)
net/atm/common.c +2 -0
@@ -720,6 +720,8 @@ static int atm_change_qos(struct atm_vccstatic int check_tp (const struct atm_trafprm *tp) {/* @@@ Should be merged with adjust_tp */ +if (tp->traffic_class >ATM_ANYCLASS ) +return -EINVAL ;if (!tp->traffic_class || tp->traffic_class ==ATM_ANYCLASS )return 0 ; if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
Greg Kroah-Hartman
maintainerPATCH 815/1276 net: ife: require ETH_HLEN to be pullable in ife_decode()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yong Wang <[email protected]>
commit 9406f6012b7343661efb516a11c62d4db2b62f75 upstream.
ife decode may return after making only the outer IFE header and metadata pullable. The caller then passes the decapsulated packet to eth_type_trans(), which expects the inner Ethernet header to be accessible from the linear data area.
With a malformed IFE frame, the inner Ethernet header may still be shorter than ETH_HLEN in the linear area, which can lead to a crash in the original code.
Fix this by extending the pull check in ife_decode() so that the inner Ethernet header is also guaranteed to be pullable before returning.
--- net/ife/ife.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ife/ife.c +1 -1
@@ -79,7 +79,7 @@ void *ife_decode(struct sk_buff *skb, u1if (unlikely (ifehdrln <2 ))return NULL ; -if (unlikely (!pskb_may_pull (skb, total_pull))) +if (unlikely (!pskb_may_pull (skb, total_pull +ETH_HLEN )))return NULL ; ifehdr = (struct ifeheadr *)(skb->data + skb->dev->hard_header_len);
Greg Kroah-Hartman
maintainerPATCH 816/1276 arm64: fpsimd: Fix type mismatch in sve_{save,load}_state()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
commit ae24f6b06e90681ec36b9c21c3f5c09618350f5a upstream.
The sve_save_state() and sve_load_state() functions take a 32-bit int argument that describes whether to save/restore the FFR. Their assembly implementations consume the entire 64-bit register containing this 32-bit value, and will attempt to save/restore the FFR if any bit of that 64-bit register is non-zero.
Per the AAPCS64 parameter passing rules, the callee is responsible for any necessary widening, and the upper 32-bits are permitted to contain arbitrary values. If the upper 32 bits are non-zero, this could result in an unexpected attempt to save/restore the FFR, and consequently could lead to unexpected traps/undefs/faults.
In practice compilers are very unlikely to generate code where the upper 32-bits would be non-zero, but they are permitted to do so.
Fix this by only consuming the low 32 bits of the register, and update comments accordingly.
The hyp code __sve_save_state() and __sve_restore_state() functions don't have the same latent bug as they override the full 64-bit register containing the argument.
--- arch/arm64/kernel/entry-fpsimd.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/entry-fpsimd.S +4 -4
@@ -38,10 +38,10 @@ SYM_FUNC_END(fpsimd_load_state) * * x0 - pointer to buffer for state * x1 - pointer to storage for FPSR - * x2 - Save FFR if non-zero + * w2 - Save FFR if non-zero */ SYM_FUNC_START(sve_save_state) - sve_save 0, x1, x2, 3 + sve_save 0, x1, w2, 3 ret SYM_FUNC_END(sve_save_state)
@@ -50,10 +50,10 @@ SYM_FUNC_END(sve_save_state) * * x0 - pointer to buffer for state * x1 - pointer to storage for FPSR - * x2 - Restore FFR if non-zero + * w2 - Restore FFR if non-zero */ SYM_FUNC_START(sve_load_state) - sve_load 0, x1, x2, 4 + sve_load 0, x1, w2, 4 ret SYM_FUNC_END(sve_load_state)
Greg Kroah-Hartman
maintainerPATCH 817/1276 arm64: dts: qcom: sdm630: describe adsp_mem region properly
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nickolay Goppen <[email protected]>
commit ce414263e9ebe5080381a50cbdf9065c29816202 upstream.
Downstream [1] this region is marked as shared, reusable and dynamic so describe it that way.
--- arch/arm64/boot/dts/qcom/sdm630.dtsi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/qcom/sdm630.dtsi +6 -3
@@ -493,9 +493,12 @@ no-map; }; - adsp_mem: adsp-region@f6000000 { - reg = <0x0 0xf6000000 0x0 0x800000>; - no-map; + adsp_mem: adsp-region { + compatible = "shared-dma-pool"; + alloc-ranges = <0x0 0x80000000 0x0 0x80000000>; + alignment = <0x0 0x400000>; + size = <0x0 0x800000>; + reusable; }; qseecom_mem: qseecom-region@f6800000 {
Greg Kroah-Hartman
maintainerPATCH 818/1276 ARM: dts: stm32: stm32mp15x-mecio1-io: Fix ADC sampling times
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Jander <[email protected]>
commit 8407e611faf80ce790a393addf7b44cc595742af upstream.
Increase the minimum ADC sample times for all configured channels on ADC1 and ADC2 to ensure measurement accuracy meets specifications.
The default 5us sample time is insufficient for the internal sampling capacitor to fully charge. Increase the default time to 20us to relax the input impedance requirements.
Additionally, the phint0_ain and phint1_ain channels require a much longer sampling period due to their specific circuit design. Increase their sample times to 200us. Remove stale comments regarding clock cycles that no longer match the updated timings.
--- .../arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-)
arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi +15 -17
@@ -104,80 +104,79 @@ &adc1 { channel@0 { reg = <0>; - /* 16.5 ck_cycles sampling time */ - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "p24v_stp"; }; channel@1 { reg = <1>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "p24v_hpdcm"; }; channel@2 { reg = <2>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "ain0"; }; channel@3 { reg = <3>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "hpdcm1_i2"; }; channel@5 { reg = <5>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "hpout1_i"; }; channel@6 { reg = <6>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "ain1"; }; channel@9 { reg = <9>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "hpout0_i"; }; channel@10 { reg = <10>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <200000>; label = "phint0_ain"; }; channel@13 { reg = <13>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <200000>; label = "phint1_ain"; }; channel@15 { reg = <15>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "hpdcm0_i1"; }; channel@16 { reg = <16>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "lsin"; }; channel@18 { reg = <18>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "hpdcm0_i2"; }; channel@19 { reg = <19>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "hpdcm1_i1"; }; };
@@ -187,14 +186,13 @@ &adc2 { channel@2 { reg = <2>; - /* 16.5 ck_cycles sampling time */ - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "ain2"; }; channel@6 { reg = <6>; - st,min-sample-time-ns = <5000>; + st,min-sample-time-ns = <20000>; label = "ain3"; }; };
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 819/1276 ARM: dts: stm32: stm32mp15x-mecio1-io: Move divergent mecio1 ADC channels to board files
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Jander <[email protected]>
commit 70f1d8fcbd121a40f51b6c846d41e8cbb38ba210 upstream.
Move the divergent adc1 channel definitions out of the common mecio1-io.dtsi file and into the specific Revision 0 and Revision 1 board files.
The original common file contained incorrect schematic labels for the Revision 0 hardware (e.g., labeling ana0 as p24v_hpdcm instead of ain_aux0) and failed to account for physical signal routing changes between the board revisions.
Retain only the strictly shared channels in the common include file. Map the correct channels and schematic labels directly within stm32mp151c-mecio1r0.dts and stm32mp153c-mecio1r1.dts.
Crucially, ensure that the required 200us sample time follows the phint1_ain signal to its new physical location on channel 3 for the Revision 1 hardware.
--- arch/arm/boot/dts/st/stm32mp151c-mecio1r0.dts | 50 +++++++++++++++++++++++++ arch/arm/boot/dts/st/stm32mp153c-mecio1r1.dts | 50 +++++++++++++++++++++++++ arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi | 50 ------------------------- 3 files changed, 101 insertions(+), 49 deletions(-)
arch/arm/boot/dts/st/stm32mp151c-mecio1r0.dts +50 -0
@@ -36,6 +36,56 @@ }; }; +&adc1 { + channel@0 { + reg = <0>; + st,min-sample-time-ns = <20000>; + label = "ain_aux0"; + }; + + channel@1 { + reg = <1>; + st,min-sample-time-ns = <20000>; + label = "ain_aux1"; + }; + + channel@3 { + reg = <3>; + st,min-sample-time-ns = <20000>; + label = "hpdcm1_i2"; + }; + + channel@5 { + reg = <5>; + st,min-sample-time-ns = <20000>; + label = "pout1_i"; + }; + + channel@9 { + reg = <9>; + st,min-sample-time-ns = <20000>; + label = "pout0_i"; + }; + + channel@13 { + reg = <13>; + st,min-sample-time-ns = <200000>; + label = "phint1_ain"; + }; + + channel@15 { + reg = <15>; + st,min-sample-time-ns = <20000>; + label = "hpdcm0_i1"; + }; + + channel@18 { + reg = <18>; + st,min-sample-time-ns = <20000>; + label = "hpdcm0_i2"; + }; +}; + &clk_hse { clock-frequency = <25000000>; };
arch/arm/boot/dts/st/stm32mp153c-mecio1r1.dts +50 -0
56 lines not on this page · raw message
arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi +1 -49
86 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 820/1276 arm64: dts: ti: k3-am62a7-sk: Add bootph-all tag to vqmmc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Judith Mendez <[email protected]>
commit d8fe8442366ffd8306575028bda92389d0dfb674 upstream.
Add bootph-all property to vqmmc voltage regulator node and its corresponding pinmux node to make it available during all boot phases. This allows to run tuning early in SPL stages of boot.
--- arch/arm64/boot/dts/ti/k3-am62a7-sk.dts | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/ti/k3-am62a7-sk.dts +2 -0
@@ -134,6 +134,7 @@ gpios = <&main_gpio0 31 GPIO_ACTIVE_HIGH>; states = <1800000 0x0>, <3300000 0x1>; + bootph-all; }; leds {
@@ -381,6 +382,7 @@ pinctrl-single,pins = < AM62AX_MCU_IOPAD(0x000, PIN_INPUT, 7) /* (E11) MCU_GPIO0_0 */ >; + bootph-all; }; };
Re: [PATCH 6.12 0820/1276] arm64: dts: ti: k3-am62a7-sk: Add bootph-all tag to vqmmc
Hi Greg,
Quoted 12 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Judith Mendez <[email protected]>
commit
d8fe8442366ffd8306575028bda92389d0dfb674upstream.Add bootph-all property to vqmmc voltage regulator node and its corresponding pinmux node to make it available during all boot phases. This allows to run tuning early in SPL stages of boot.
Quoted 6 lines
Fixes 8f023012eb4a ("arm64: dts: ti: k3-am62a: Enable UHS mode support for SD cards")Signed-off-by Judith Mendez <[email protected]>Signed-off-by Nishanth Menon <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
I have run an AI assisted backport review and it spotted an issue. I have taken a look and the issue goes like:
Upstream commit d8fe8442366f ("arm64: dts: ti: k3-am62a7-sk: Add bootph-all tag to vqmmc") has:
vddshv_sdio_pins_default: vddshv-sdio-default-pins {
...
bootph-all;
};The 6.12.y backport leaves that node untagged and instead adds the property to the unrelated PMIC interrupt pinmux:
pmic_irq_pins_default: pmic-irq-default-pins {
...
bootph-all;
};The vddshv_sdio regulator's pinctrl-0 points to vddshv_sdio_pins_default, so tagging pmic_irq_pins_default does not do the intended fix I suppose.,
This is probably cherry-pick fault ?
I think 6.12.y should move bootph-all from pmic_irq_pins_default to vddshv_sdio_pins_default, thoughts?
Lets drop this for now and redo this later , vddshv_sdio_pins_default is present in 6.12.y
thanks,
Harshit
Quoted 25 lines
--- arch/arm64/boot/dts/ti/k3-am62a7-sk.dts | 2 ++ 1 file changed, 2 insertions(+)arch/arm64/boot/dts/ti/k3-am62a7-sk.dts +2
-0@@ -134,6 +134,7 @@ gpios = <&main_gpio0 31 GPIO_ACTIVE_HIGH>; states = <1800000 0x0>, <3300000 0x1>; + bootph-all; }; leds {@@ -381,6 +382,7 @@ pinctrl-single,pins = < AM62AX_MCU_IOPAD(0x000, PIN_INPUT, 7) /* (E11) MCU_GPIO0_0 */ >; + bootph-all; }; };
Re: [PATCH 6.12 0820/1276] arm64: dts: ti: k3-am62a7-sk: Add bootph-all tag to vqmmc
Hi all,
Quoted 40 lines · Harshit Mogalapalli
Hi Greg,
Quoted 12 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Judith Mendez <[email protected]>
commit
d8fe8442366ffd8306575028bda92389d0dfb674upstream.Add bootph-all property to vqmmc voltage regulator node and its corresponding pinmux node to make it available during all boot phases. This allows to run tuning early in SPL stages of boot.
Quoted 6 lines
Fixes 8f023012eb4a ("arm64: dts: ti: k3-am62a: Enable UHS mode support for SD cards")Signed-off-by Judith Mendez <[email protected]>Signed-off-by Nishanth Menon <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>I have run an AI assisted backport review and it spotted an issue. I have taken a look and the issue goes like:
Upstream commit
d8fe8442366f("arm64: dts: ti: k3-am62a7-sk: Add bootph-all tag to vqmmc") has:
vddshv_sdio_pins_default: vddshv-sdio-default-pins {
...
bootph-all;
};The 6.12.y backport leaves that node untagged and instead adds the property to the unrelated PMIC interrupt pinmux:
pmic_irq_pins_default: pmic-irq-default-pins {
...
bootph-all;
};
Quoted 6 lines
The
vddshv_sdioregulator's pinctrl-0 points tovddshv_sdio_pins_default, so taggingpmic_irq_pins_defaultdoes not do the intended fix I suppose.,This is probably cherry-pick fault ?
I think 6.12.y should move bootph-all from
pmic_irq_pins_defaulttovddshv_sdio_pins_default, thoughts?
This is correct, boot phase flag is supposed to be added to regulator-5 and corresponding pinmux node as Harshit mentioned. Thanks for catching this Harshit (:
~ Judith
Greg Kroah-Hartman
maintainerPATCH 821/1276 ARM: dts: stm32: stm32mp15x-mecio1-io: Enable internal ADC reference
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Jander <[email protected]>
commit c84f22405085d91cd5f0c5b967318371c07904ba upstream.
Switch the ADC reference supply from the general 3.3V rail to the internal 2.5V VREFBUF regulator. The ADC circuits on this board are designed for the internal 2.5V reference. Without this change, all ADC measurement values are incorrect.
--- arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi +8 -1
@@ -95,7 +95,7 @@ pinctrl-names = "default"; vdd-supply = <&v3v3>; vdda-supply = <&v3v3>; - vref-supply = <&v3v3>; + vref-supply = <&vrefbuf>; status = "okay"; };
@@ -362,6 +362,13 @@ phy-supply = <&v3v3>; }; +&vrefbuf { + regulator-min-microvolt = <2500000>; + regulator-max-microvolt = <2500000>; + vdda-supply = <&v3v3>; + status = "okay"; +}; + &pinctrl { adc12_pins_mecsbc: adc12-ain-mecsbc-0 { pins {
Greg Kroah-Hartman
maintainerPATCH 822/1276 arm64: dts: imx8ulp-evk: Correct Type-C int GPIO flags
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Kozlowski <[email protected]>
commit b4f5c46163b3fe3ec7ed8a76dff8b7e80a776a1f upstream.
IRQ_TYPE_xxx flags are not correct in the context of GPIO flags. These are simple defines so they could be used in DTS but they will not have the same meaning: IRQ_TYPE_EDGE_FALLING = 2 = GPIO_SINGLE_ENDED.
Correct the Type-C int-gpios to use proper flags, assuming the author of the code wanted similar logical behavior:
IRQ_TYPE_EDGE_FALLING => GPIO_ACTIVE_LOW
--- arch/arm64/boot/dts/freescale/imx8ulp-evk.dts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/imx8ulp-evk.dts +2 -2
@@ -130,7 +130,7 @@ ptn5150_1: typec@1d { compatible = "nxp,ptn5150"; reg = <0x1d>; - int-gpios = <&gpiof 3 IRQ_TYPE_EDGE_FALLING>; + int-gpios = <&gpiof 3 GPIO_ACTIVE_LOW>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_typec1>; status = "disabled";
@@ -146,7 +146,7 @@ ptn5150_2: typec@3d { compatible = "nxp,ptn5150"; reg = <0x3d>; - int-gpios = <&gpiof 5 IRQ_TYPE_EDGE_FALLING>; + int-gpios = <&gpiof 5 GPIO_ACTIVE_LOW>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_typec2>; status = "disabled";
Greg Kroah-Hartman
maintainerPATCH 823/1276 ARM: dts: stm32: stm32mp15x-mecio1-io: Fix GPIO names typo
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Jander <[email protected]>
commit b04ccecb714de913e360f0866c66f38e1606e89b upstream.
The reset pins for the LPOUT lines were incorrectly prefixed with "GPOUT" instead of "LPOUT" in the gpio-line-names array. Fix these typos so the pin names consistently match the LPOUT0-4 signals they belong to.
--- arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi +5 -5
@@ -185,14 +185,14 @@ &gpiod { &gpioe { gpio-line-names = "HPOUT0_RESETN", "HPOUT1", "HPOUT1_ALERTN", "", "", "", "HPOUT1_RESETN", - "LPOUT0", "LPOUT0_ALERTN", "GPOUT0_RESETN", - "LPOUT1", "LPOUT1_ALERTN", "GPOUT1_RESETN", - "LPOUT2", "LPOUT2_ALERTN", "GPOUT2_RESETN"; + "LPOUT0", "LPOUT0_ALERTN", "LPOUT0_RESETN", + "LPOUT1", "LPOUT1_ALERTN", "LPOUT1_RESETN", + "LPOUT2", "LPOUT2_ALERTN", "LPOUT2_RESETN"; }; &gpiof { - gpio-line-names = "LPOUT3", "LPOUT3_ALERTN", "GPOUT3_RESETN", - "LPOUT4", "LPOUT4_ALERTN", "GPOUT4_RESETN", + gpio-line-names = "LPOUT3", "LPOUT3_ALERTN", "LPOUT3_RESETN", + "LPOUT4", "LPOUT4_ALERTN", "LPOUT4_RESETN", "", "", "", "", "", "", "", "", "", "";
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 824/1276 ARM: dts: stm32: stm32mp15x-mecio1-io: Move gpio-line-names to board files
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Jander <[email protected]>
commit 4f5069609ac99894c0632d8b8c4c016f85199de9 upstream.
Move the gpio-line-names properties out of the common mecio1-io.dtsi file and into the specific board dts files.
The pinout originally defined in the common include file belonged to the mecio1r0 (Revision 0) hardware. This is moved 1:1 into the stm32mp151c-mecio1r0.dts file without any modifications.
A large number of GPIO pins are swapped on the mecio1r1 (Revision 1) hardware, so a new, board-specific gpio-line-names mapping is added to stm32mp153c-mecio1r1.dts to reflect those hardware changes.
--- arch/arm/boot/dts/st/stm32mp151c-mecio1r0.dts | 64 ++++++++++++++++++++ arch/arm/boot/dts/st/stm32mp153c-mecio1r1.dts | 80 +++++++++++++++++++++++++ arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi | 63 ------------------- 3 files changed, 144 insertions(+), 63 deletions(-)
arch/arm/boot/dts/st/stm32mp151c-mecio1r0.dts +64 -0
@@ -96,3 +96,67 @@ assigned-clock-rates = <125000000>; /* Clock PLL3 to 625Mhz in tf-a. */ st,eth-clk-sel; }; + +&gpiod { + gpio-line-names = "", "", "", "", + "", "", "", "", + "", "", "", "", + "STP_RESETN", "STP_ENABLEN", "HPOUT0", "HPOUT0_ALERTN"; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_hog_d_mecsbc>; +}; + +&gpioe { + gpio-line-names = "HPOUT0_RESETN", "HPOUT1", "HPOUT1_ALERTN", "", + "", "", "HPOUT1_RESETN", + "LPOUT0", "LPOUT0_ALERTN", "LPOUT0_RESETN", + "LPOUT1", "LPOUT1_ALERTN", "LPOUT1_RESETN", + "LPOUT2", "LPOUT2_ALERTN", "LPOUT2_RESETN"; +}; + +&gpiof { + gpio-line-names = "LPOUT3", "LPOUT3_ALERTN", "LPOUT3_RESETN", + "LPOUT4", "LPOUT4_ALERTN", "LPOUT4_RESETN", + "", "", + "", "", "", "", + "", "", "", ""; +}; + +&gpiog { + gpio-line-names = "LPOUT5", "LPOUT5_ALERTN", "", "LPOUT5_RESETN", + "", "", "", "", + "", "", "", "", + "", "", "", ""; +}; + +&gpioh { + gpio-line-names = "", "", "", "", + "", "", "", "", + "GPIO0_RESETN", "", "", "", + "", "", "", ""; +}; + +&gpioi { + gpio-line-names = "", "", "", "", + "", "", "", "", + "HPDCM0_SLEEPN", "HPDCM1_SLEEPN", "GPIO1_RESETN", "", + "", "", "", ""; +}; + +&gpioj { + gpio-line-names = "HSIN10", "HSIN11", "HSIN12", "HSIN13", + "HSIN14", "HSIN15", "", "", + "", "", "", "", + "", "RTD_RESETN", "", ""; +}; + +&gpiok { + gpio-line-names = "", "", "HSIN0", "HSIN1", + "HSIN2", "HSIN3", "HSIN4", "HSIN5"; +}; + +&gpioz { + gpio-line-names = "", "", "", "HSIN6", + "HSIN7", "HSIN8", "HSIN9", ""; +}; +
arch/arm/boot/dts/st/stm32mp153c-mecio1r1.dts +80 -0
86 lines not on this page · raw message
arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi +0 -63
69 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 825/1276 ARM: dts: stm32: stm32mp15x-mecio1-io: Fix expander gpio line typo
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Jander <[email protected]>
commit dfb93c4acce8ad9c4f573128b2cf7ddb936e0de7 upstream.
Fix a copy-paste error in the GPIO line names for the TCA6416 expander (gpio@20).
The common mecio1-io include file was originally defined using the mecio1r1 (Revision 1) hardware layout, but incorrectly labeled pin 13 as "HSIN9_BIAS" instead of the actual "HSIN7_BIAS" present in the schematics.
--- arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi +1 -1
@@ -186,7 +186,7 @@ gpio0: gpio@20 { #gpio-cells = <2>; gpio-line-names = "HSIN0_BIAS", "HSIN1_BIAS", "HSIN2_BIAS", "HSIN3_BIAS", "", "", "HSIN_VREF0_LVL", "HSIN_VREF1_LVL", - "HSIN4_BIAS", "HSIN5_BIAS", "HSIN6_BIAS", "HSIN9_BIAS", + "HSIN4_BIAS", "HSIN5_BIAS", "HSIN6_BIAS", "HSIN7_BIAS", "", "", "", ""; };
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 826/1276 ARM: dts: stm32: stm32mp15x-mecio1-io: Move expander gpio-line-names to board files
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Jander <[email protected]>
commit a0d6c2a06fffff47bcca4d5bfdab4cc428a315fc upstream.
Move the gpio-line-names properties for the I2C GPIO expanders (gpio0 and gpio1) out of the common mecio1-io.dtsi file and into the specific board dts files.
The layout originally defined in the common include file belonged to the mecio1r1 (Revision 1) hardware. This layout is moved 1:1 into the stm32mp153c-mecio1r1.dts file.
The mecio1r0 (Revision 0) hardware utilizes a completely different pinout for these expanders. A new, accurate mapping reflecting the Revision 0 schematics is added to stm32mp151c-mecio1r0.dts.
--- arch/arm/boot/dts/st/stm32mp151c-mecio1r0.dts | 14 ++++++++++++++ arch/arm/boot/dts/st/stm32mp153c-mecio1r1.dts | 14 ++++++++++++++ arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi | 8 -------- 3 files changed, 28 insertions(+), 8 deletions(-)
arch/arm/boot/dts/st/stm32mp151c-mecio1r0.dts +14 -0
@@ -97,6 +97,20 @@ st,eth-clk-sel; }; +&gpio0 { + gpio-line-names = "HSIN0_BIAS", "HSIN1_BIAS", "HSIN2_BIAS", "HSIN3_BIAS", + "HSIN4_BIAS", "", "STP_VREF0_LVL", "HSIN_VREF0_LVL", + "STP0_FB_BIAS", "STP1_FB_BIAS", "STP2_FB_BIAS", "STP3_FB_BIAS", + "", "", "", ""; +}; + +&gpio1 { + gpio-line-names = "HSIN5_BIAS", "HSIN6_BIAS", "HSIN7_BIAS", "HSIN8_BIAS", + "HSIN9_BIAS", "", "STP_VREF1_LVL", "HSIN_VREF1_LVL", + "STP4_FB_BIAS", "STP5_FB_BIAS", "STP6_FB_BIAS", "", + "", "", "LSIN8_BIAS", "LSIN9_BIAS"; +}; + &gpiod { gpio-line-names = "", "", "", "", "", "", "", "",
arch/arm/boot/dts/st/stm32mp153c-mecio1r1.dts +14 -0
@@ -90,6 +90,20 @@ clock-frequency = <24000000>; }; +&gpio0 { + gpio-line-names = "HSIN0_BIAS", "HSIN1_BIAS", "HSIN2_BIAS", "HSIN3_BIAS", + "", "", "HSIN_VREF0_LVL", "HSIN_VREF1_LVL", + "HSIN4_BIAS", "HSIN5_BIAS", "HSIN6_BIAS", "HSIN7_BIAS", + "", "", "", ""; +}; + +&gpio1 { + gpio-line-names = "HSIN8_BIAS", "HSIN9_BIAS", "HSIN10_BIAS", "HSIN11_BIAS", + "", "", "HSIN_VREF2_LVL", "HSIN_VREF3_LVL", + "HSIN12_BIAS", "HSIN13_BIAS", "HSIN14_BIAS", "HSIN15_BIAS", + "", "", "LSIN8_BIAS", "LSIN9_BIAS"; +}; + &gpioa { gpio-line-names = "", "", "", "", "", "", "", "",
arch/arm/boot/dts/st/stm32mp15x-mecio1-io.dtsi +0 -8
@@ -184,10 +184,6 @@ reg = <0x20>; gpio-controller; #gpio-cells = <2>; - gpio-line-names = "HSIN0_BIAS", "HSIN1_BIAS", "HSIN2_BIAS", "HSIN3_BIAS", - "", "", "HSIN_VREF0_LVL", "HSIN_VREF1_LVL", - "HSIN4_BIAS", "HSIN5_BIAS", "HSIN6_BIAS", "HSIN7_BIAS", - "", "", "", ""; }; gpio1: gpio@21 {
@@ -195,10 +191,6 @@ reg = <0x21>; gpio-controller; #gpio-cells = <2>; - gpio-line-names = "HSIN8_BIAS", "HSIN9_BIAS", "HSIN10_BIAS", "HSIN11_BIAS", - "", "", "HSIN_VREF2_LVL", "HSIN_VREF3_LVL", - "HSIN12_BIAS", "HSIN13_BIAS", "HSIN14_BIAS", "HSIN15_BIAS", - "", "", "LSIN8_BIAS", "LSIN9_BIAS"; }; };
Greg Kroah-Hartman
maintainerPATCH 827/1276 LoongArch: KVM: Check irq validity in kvm_vcpu_ioctl_interrupt()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bibo Mao <[email protected]>
commit 09b318ab77b7a4fc9987fd98d1525fc55ddc2617 upstream.
Function kvm_vcpu_ioctl_interrupt() can be called from userspace, here add irq validility cheking in kvm_vcpu_ioctl_interrupt().
--- arch/loongarch/kvm/vcpu.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/loongarch/kvm/vcpu.c +4 -0
@@ -1429,6 +1429,10 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu)int kvm_vcpu_ioctl_interrupt (struct kvm_vcpu *vcpu,struct kvm_interrupt *irq) {int intr = (int )irq->irq; +unsigned int vector =abs (intr); + +if (vector >=EXCCODE_INT_NUM ) +return -EINVAL ;if (intr >0 )kvm_queue_irq (vcpu, intr);
Greg Kroah-Hartman
maintainerPATCH 828/1276 LoongArch: KVM: Check the return values for put_user()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiang Ma <[email protected]>
commit fb89e0fe2dc4246c86ad0eb0fa2b7cb2f8ba9728 upstream.
put_user() may return -EFAULT, so, when the user space address is invalid, the caller should return -EFAULT.
--- arch/loongarch/kvm/vcpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/loongarch/kvm/vcpu.c +2 -1
@@ -1029,7 +1029,8 @@ static int kvm_loongarch_cpucfg_get_attrreturn -ENXIO ; } -put_user (val, uaddr); +if (put_user (val, uaddr)) +return -EFAULT ;return ret; }
Greg Kroah-Hartman
maintainerPATCH 829/1276 LoongArch: KVM: Fix FPU register width with user access API
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bibo Mao <[email protected]>
commit f4caaac76379daf4a617d9134b6087fb2636fb31 upstream.
At the beginning, only 64 bit FPU is supported. With FPU register get interface, 64 bit FPU data is copied to user space, the same with FPU register set API. However with LSX and LASX supported in later, there should be FPU data copied with bigger width. So here fixes this issue, copy the whole 256 bit FPU data from/to user space.
--- arch/loongarch/kvm/vcpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/loongarch/kvm/vcpu.c +2 -2
@@ -1234,7 +1234,7 @@ int kvm_arch_vcpu_ioctl_get_fpu(struct k fpu->fcc = vcpu->arch.fpu.fcc; fpu->fcsr = vcpu->arch.fpu.fcsr;for (i =0 ; i <NUM_FPU_REGS ; i++) -memcpy (&fpu->fpr[i], &vcpu->arch.fpu.fpr[i],FPU_REG_WIDTH /64 ); +memcpy (&fpu->fpr[i], &vcpu->arch.fpu.fpr[i],sizeof (union fpureg ));return 0 ; }
@@ -1246,7 +1246,7 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct k vcpu->arch.fpu.fcc = fpu->fcc; vcpu->arch.fpu.fcsr = fpu->fcsr;for (i =0 ; i <NUM_FPU_REGS ; i++) -memcpy (&vcpu->arch.fpu.fpr[i], &fpu->fpr[i],FPU_REG_WIDTH /64 ); +memcpy (&vcpu->arch.fpu.fpr[i], &fpu->fpr[i],sizeof (union fpureg ));return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 830/1276 LoongArch: KVM: Return full old CSR value from kvm_emu_xchg_csr()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiang Ma <[email protected]>
commit ebd50de14f1a06b7e0206083904bcc62b9ba65be upstream.
The LoongArch CSRXCHG instruction returns the full old CSR value in rd after applying the masked update. kvm_emu_xchg_csr() currently masks the saved value before returning it to the guest, so rd receives only the bits selected by the write mask.
That breaks the architectural behavior and makes a zero mask return 0 instead of the previous CSR value. So, keep the masked CSR update, but return the unmodified old CSR value.
--- arch/loongarch/kvm/exit.c | 1 - 1 file changed, 1 deletion(-)
arch/loongarch/kvm/exit.c +0 -1
@@ -103,7 +103,6 @@ static unsigned long kvm_emu_xchg_csr(st old =kvm_read_sw_gcsr (csr, csrid); val = (old & ~csr_mask) | (val & csr_mask);kvm_write_sw_gcsr (csr, csrid, val); - old = old & csr_mask; }else pr_warn_once ("Unsupported csrxchg 0x%x with pc %lx\n" , csrid, vcpu->arch.pc);
Greg Kroah-Hartman
maintainerPATCH 831/1276 KVM: s390: pci: Fix GISC refcount leak on AIF enable failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 7b69729046a4c58f4cb457184e5ac4aaa179bff4 upstream.
kvm_s390_gisc_register() registers the guest ISC before pinning the guest interrupt forwarding pages and allocating the AISB bit. If any of the later setup steps fails, the function unwinds the pinned pages and other local state, but does not unregister the GISC reference. Add the missing kvm_s390_gisc_unregister() to the error unwind path.
Message-ID: <[email protected]>
--- arch/s390/kvm/pci.c | 1 + 1 file changed, 1 insertion(+)
arch/s390/kvm/pci.c +1 -0
@@ -330,6 +330,7 @@ unpin2: unpin1:unpin_user_page (aibv_page); out: +kvm_s390_gisc_unregister (kvm, fib->fmt0.isc);return rc; }
Greg Kroah-Hartman
maintainerPATCH 832/1276 KVM: arm64: vgic: Check the interrupt is still ours before migrating it
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunwoo Kim <[email protected]>
commit 0074b82cdfcb5fd13710a0ac308ade68ac6f6fbe upstream.
vgic_prune_ap_list() drops both ap_list_lock and irq_lock while migrating an interrupt to another vCPU. After reacquiring the locks it only checks that the affinity is unchanged (target_vcpu == vgic_target_oracle(irq)) before moving the interrupt, which assumes that an interrupt whose affinity is preserved is still queued on this vCPU's ap_list.
That assumption no longer holds if the interrupt is taken off the ap_list while the locks are dropped. vgic_flush_pending_lpis() removes the interrupt from the list and sets irq->vcpu to NULL, but leaves enabled/pending/target_vcpu untouched. As the interrupt is still enabled and pending, vgic_target_oracle() returns the same target_vcpu, so the affinity check passes and list_del() is run a second time on an entry that has already been removed.
Also check that the interrupt is still assigned to this vCPU (irq->vcpu == vcpu) before moving it.
--- arch/arm64/kvm/vgic/vgic.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
arch/arm64/kvm/vgic/vgic.c +6 -5
@@ -684,15 +684,16 @@ retry:raw_spin_lock (&irq->irq_lock);/* -* If the affinity has been preserved, move the -* interrupt around. Otherwise, it means things have -* changed while the interrupt was unlocked, and we -* need to replay this. +* If the interrupt is still ours and its affinity has +* been preserved, move it around. Otherwise, it means +* things have changed while the interrupt was unlocked +* (it may even have been taken off the list with its +* affinity left untouched), and we need to replay this. * * In all cases, we cannot trust the list not to have * changed, so we restart from the beginning. */ -if (target_vcpu ==vgic_target_oracle (irq)) { +if (irq->vcpu == vcpu && target_vcpu ==vgic_target_oracle (irq)) {struct vgic_cpu *new_cpu = &target_vcpu->arch.vgic_cpu;list_del (&irq->ap_list);
Greg Kroah-Hartman
maintainerPATCH 833/1276 KVM: s390: pci: Fix handling of AIF enable without AISB
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Rosato <[email protected]>
commit 3e3aa6da87d30a0064a17b836685cd43c90a3572 upstream.
When a guest seeks to register IRQs without a summary bit specified, ensure that the associated GAITE then stores 0 for the guest AISB location instead of virt_to_phys(page_address(NULL)).
--- arch/s390/kvm/pci.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
arch/s390/kvm/pci.c +8 -3
@@ -302,9 +302,14 @@ static int kvm_s390_pci_aif_enable(struc gaite->gisc = fib->fmt0.isc; gaite->count++; - gaite->aisbo = fib->fmt0.aisbo; - gaite->aisb =virt_to_phys (page_address (aisb_page) + (fib->fmt0.aisb & - ~PAGE_MASK )); +if (fib->fmt0.sum ==1 ) { + gaite->aisbo = fib->fmt0.aisbo; + gaite->aisb =virt_to_phys (page_address (aisb_page) + + (fib->fmt0.aisb & ~PAGE_MASK )); + }else { + gaite->aisbo =0 ; + gaite->aisb =0 ; + } aift->kzdev[zdev->aisb] = zdev->kzdev;spin_unlock_irq (&aift->gait_lock);
Greg Kroah-Hartman
maintainerPATCH 834/1276 KVM: SEV: Do not allow intra-host migration/mirroring of SNP VMs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Atish Patra <[email protected]>
commit 6ee4140788234a6fabf59e6a50e38cdb936008cd upstream.
The intra-host migration/mirroring feature is not fully implemented for SEV-SNP VMs. The proper migration requires additional SNP-specific state such as guest_req_mutex, guest_req_buf, and guest_resp_buf to be transferred or initialized on the destination.
The SNP VM mirroring requires vmsa features to be copied as well otherwise ASID would be bound to SNP range while VM is detected as a SEV VM.
Reject SNP source VMs in migration/mirroring until proper SNP state transfer is implemented.
--- arch/x86/kvm/svm/sev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/sev.c +4 -2
@@ -2101,8 +2101,9 @@ int sev_vm_move_enc_context_from(structif (ret)return ret; +/* Do not allow SNP VM migration until additional state transfer is implemented */ if (kvm->arch.vm_type != source_kvm->arch.vm_type || -sev_guest (kvm) || !sev_guest (source_kvm)) { +sev_guest (kvm) || !sev_guest (source_kvm) ||sev_snp_guest (source_kvm)) { ret = -EINVAL ; goto out_unlock; }
@@ -2830,8 +2831,9 @@ int sev_vm_copy_enc_context_from(struct* disallow out-of-band SEV/SEV-ES init if the target is already an * SEV guest, or if vCPUs have been created. KVM relies on vCPUs being * created after SEV/SEV-ES initialization, e.g. to init intercepts. +* Also do not allow SNP VM mirroring until additional state transfer is implemented. */ -if (sev_guest (kvm) || !sev_guest (source_kvm) || +if (sev_guest (kvm) || !sev_guest (source_kvm) ||sev_snp_guest (source_kvm) ||is_mirroring_enc_context (source_kvm) || kvm->created_vcpus) { ret = -EINVAL ; goto e_unlock;
Greg Kroah-Hartman
maintainerPATCH 835/1276 KVM: x86: Ignore pending PV EOI if the vCPU has since disabled PV EOIs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit 9285e4070df2c40585c3d7ec9571faa7a2b97e17 upstream.
Ignore KVM's internal "service pending PV EOI" request if the vCPU has disabled PV EOIs since the request was made. Asserting that PV EOIs are enabled can fail if reading guest memory in pv_eoi_get_user() fails, i.e. if pv_eoi_test_and_clr_pending() bails early, *and* the vCPU also disables PV EOIs.
kernel BUG at arch/x86/kvm/lapic.c:3338!
Oops: invalid opcode: 0000 [#1] SMP CPU: 4 UID: 1000 PID: 890 Comm: pv_eoi_test Not tainted 7.0.0-d585aa5894d8-vm #337 PREEMPT Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 RIP: 0010:kvm_lapic_sync_from_vapic+0x12b/0x140 [kvm] Call Trace: <TASK> kvm_arch_vcpu_ioctl_run+0x1075/0x1c30 [kvm] kvm_vcpu_ioctl+0x2d5/0x980 [kvm] __x64_sys_ioctl+0x8a/0xd0 do_syscall_64+0xb5/0xb40 entry_SYSCALL_64_after_hwframe+0x4b/0x53 </TASK> Modules linked in: kvm_intel kvm irqbypass ---[ end trace 0000000000000000 ]---
--- arch/x86/kvm/lapic.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kvm/lapic.c +6 -2
@@ -3169,6 +3169,12 @@ static void apic_sync_pv_eoi_from_guest( struct kvm_lapic *apic) {int vector; + +if (unlikely (!pv_eoi_enabled (vcpu))) { +__clear_bit (KVM_APIC_PV_EOI_PENDING , &vcpu->arch.apic_attention); +return ; + } +/* * PV EOI state is derived from KVM_APIC_PV_EOI_PENDING in host * and KVM_PV_EOI_ENABLED in guest memory as follows:
@@ -3180,8 +3186,6 @@ static void apic_sync_pv_eoi_from_guest(* KVM_APIC_PV_EOI_PENDING is set, KVM_PV_EOI_ENABLED is unset: * -> host enabled PV EOI, guest executed EOI. */ -BUG_ON (!pv_eoi_enabled (vcpu)); -if (pv_eoi_test_and_clr_pending (vcpu))return ; vector =apic_set_eoi (apic);
Greg Kroah-Hartman
maintainerPATCH 836/1276 KVM: arm64: nv: Drop bogus WARN for write to ZCR_EL2
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Upton <[email protected]>
commit 9f1667098c6ae7ec81a9a56859cfdacb822aa0d0 upstream.
It is entirely possible for a guest to write to the ZCR_EL2 sysreg alias while in a nested context, as it is expected if FEAT_NV2 is advertised to the L1 hypervisor.
Get rid of the bogus WARN which, since the hyp vectors were installed at this point, has the effect of a hyp_panic...
--- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 -- 1 file changed, 2 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +0 -2
@@ -451,8 +451,6 @@ static inline bool kvm_hyp_handle_fpsimdreturn false;break ;case ESR_ELx_EC_SYS64: -if (WARN_ON_ONCE (!is_hyp_ctxt (vcpu))) -return false; fallthrough;case ESR_ELx_EC_SVE:if (!sve_guest)
Greg Kroah-Hartman
maintainerPATCH 837/1276 KVM: arm64: nv: Fix SPSR_EL2 restore in kvm_hyp_handle_mops()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit ff1022c3de46753eb7eba2f6efd990569e66ff95 upstream.
kvm_hyp_handle_mops() resets the single-step state machine as part of rewinding state for a MOPS exception by modifying vcpu_cpsr() and writing the result directly into hardware.
In the case of nested virtualization, vcpu_cpsr() is a synthetic value such that the rest of KVM can deal with vEL2 cleanly. That means the value requires translation before being written into hardware, which is unfortunately missing from the MOPS handler.
Fix it by directly modifying SPSR_EL2 and avoiding the synthetic state altogether, which will be resynchronized on the next 'full' exit back to KVM.
--- arch/arm64/kvm/hyp/include/hyp/switch.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +6 -3
@@ -297,16 +297,19 @@ static inline bool __populate_fault_infostatic inline bool kvm_hyp_handle_mops (struct kvm_vcpu *vcpu,u64 *exit_code) { +u64 spsr; + *vcpu_pc (vcpu) =read_sysreg_el2 (SYS_ELR );arm64_mops_reset_regs (vcpu_gp_regs (vcpu), vcpu->arch.fault.esr_el2);write_sysreg_el2 (*vcpu_pc (vcpu),SYS_ELR );/* * Finish potential single step before executing the prologue -* instruction. +* instruction. Modify the hardware SPSR_EL2 directly, as vcpu_cpsr() +* may hold a synthetic (vEL2) value for a guest hypervisor. */ - *vcpu_cpsr (vcpu) &= ~DBG_SPSR_SS ; -write_sysreg_el2 (*vcpu_cpsr (vcpu),SYS_SPSR ); + spsr =read_sysreg_el2 (SYS_SPSR ); +write_sysreg_el2 (spsr & ~DBG_SPSR_SS ,SYS_SPSR );return true; }
Greg Kroah-Hartman
maintainerPATCH 838/1276 fbdev: metronomefb: fix potential memory leak in metronomefb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 894632b862a39b3fe1cb5de06fbae86225ea64de upstream.
The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().
--- drivers/video/fbdev/metronomefb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/metronomefb.c +6 -2
@@ -645,12 +645,14 @@ static int metronomefb_probe(struct plat info->flags =FBINFO_VIRTFB ; info->fbdefio = &metronomefb_defio; -fb_deferred_io_init (info); + retval =fb_deferred_io_init (info); +if (retval) + goto err_free_irq; retval =fb_alloc_cmap (&info->cmap,8 ,0 );if (retval <0 ) {dev_err (&dev->dev,"Failed to allocate colormap\n" ); - goto err_free_irq; + goto err_fbdefio; }/* set cmap */
@@ -673,6 +675,8 @@ static int metronomefb_probe(struct plat err_cmap:fb_dealloc_cmap (&info->cmap); +err_fbdefio: +fb_deferred_io_cleanup (info); err_free_irq: board->cleanup (par); err_csum_table:
Greg Kroah-Hartman
maintainerPATCH 839/1276 fbdev: broadsheetfb: fix potential memory leak in broadsheetfb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 9d18a4e4234fd3ee0d0eed8ccbbb50cb76b2232c upstream.
The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().
--- drivers/video/fbdev/broadsheetfb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/broadsheetfb.c +6 -2
@@ -1072,12 +1072,14 @@ static int broadsheetfb_probe(struct pla info->flags =FBINFO_VIRTFB ; info->fbdefio = &broadsheetfb_defio; -fb_deferred_io_init (info); + retval =fb_deferred_io_init (info); +if (retval) + goto err_vfree; retval =fb_alloc_cmap (&info->cmap,16 ,0 );if (retval <0 ) {dev_err (&dev->dev,"Failed to allocate colormap\n" ); - goto err_vfree; + goto err_fbdefio; }/* set cmap */
@@ -1121,6 +1123,8 @@ err_free_irq: board->cleanup (par); err_cmap:fb_dealloc_cmap (&info->cmap); +err_fbdefio: +fb_deferred_io_cleanup (info); err_vfree:vfree (videomemory); err_fb_rel:
Greg Kroah-Hartman
maintainerPATCH 840/1276 fbdev: hecubafb: fix potential memory leak in hecubafb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit cbef2a305a8a72969b86f96b7c07b86edde61aff upstream.
The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().
--- drivers/video/fbdev/hecubafb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/video/fbdev/hecubafb.c +5 -1
@@ -192,7 +192,9 @@ static int hecubafb_probe(struct platfor info->flags =FBINFO_VIRTFB ; info->fbdefio = &hecubafb_defio; -fb_deferred_io_init (info); + retval =fb_deferred_io_init (info); +if (retval) + goto err_fbdefio; retval =register_framebuffer (info);if (retval <0 )
@@ -209,6 +211,8 @@ static int hecubafb_probe(struct platforreturn 0 ; err_fbreg: +fb_deferred_io_cleanup (info); +err_fbdefio:framebuffer_release (info); err_fballoc:vfree (videomemory);
Greg Kroah-Hartman
maintainerPATCH 841/1276 fbdev: sm712: Fix operator precedence in big_swap macro
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
commit 5dbe5b65df0b0c0ec77492427c274b7b5011890e upstream.
The big_swap(p) macro was intended to swap bytes within 16-bit halves of a 32-bit value. However, because the bitwise shift operators (<<, >>) have higher precedence than the bitwise AND operator (&), the original code failed to perform any shifting on the masked bits.
For example, 'p & 0xff00ff00 >> 8' was evaluated as 'p & (0xff00ff00 >> 8)', effectively neutralizing the intended swap.
Fix this by adding parentheses to ensure the bitwise AND is performed before the shift, correctly implementing the byte swap logic.
--- drivers/video/fbdev/sm712.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/sm712.h +1 -1
@@ -101,7 +101,7 @@ struct modeinit {#define mmio_addr 0x00800000#define seqw17 () smtc_seqw(0x17, 0x30)#define big_pixel_depth (p, d) {if (p == 24) {p = 32; d = 32; } } -#define big_swap (p) ((p & 0xff00ff00 >> 8) | (p & 0x00ff00ff << 8)) +#define big_swap (p) (((p & 0xff00ff00) >> 8) | ((p & 0x00ff00ff) << 8))#else #define pal_rgb (r, g, b, val) val#define big_addr 0
Greg Kroah-Hartman
maintainerPATCH 842/1276 fbdev: efifb: fix memory leak in efifb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 9b6eaf101656958397a6012bf43f6e2e42c9e5cb upstream.
Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the string returned from fb_get_options() is expected to be freed by the caller, but the string is not freed in efifb_probe(). Fix that by freeing the option string after setup.
--- drivers/video/fbdev/efifb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/efifb.c +1 -0
@@ -377,6 +377,7 @@ static int efifb_probe(struct platform_dif (fb_get_options ("efifb" , &option))return -ENODEV ;efifb_setup (si, option); +kfree (option);/* We don't get linelength from UGA Draw Protocol, only from * EFI Graphics Protocol. So if it's not in DMI, and it's not
Greg Kroah-Hartman
maintainerPATCH 843/1276 fbdev: radeon: fix potential memory leak in radeonfb_pci_register()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit df8c1101c9a08859da612b5d0a08d55d475522c6 upstream.
The function radeonfb_pci_register() allocates memory for modelist (by calling radeon_check_modes() which calls fb_add_videomode()). The memory is appended to info->modelist, but is not freed in subsequent error paths. Fix this by calling fb_destroy_modelist().
--- drivers/video/fbdev/aty/radeon_base.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/aty/radeon_base.c +1 -0
@@ -2476,6 +2476,7 @@ static int radeonfb_pci_register(structreturn 0 ; err_unmap_fb:iounmap (rinfo->fb_base); +fb_destroy_modelist (&info->modelist); err_unmap_rom:kfree (rinfo->mon1_EDID);kfree (rinfo->mon2_EDID);
Greg Kroah-Hartman
maintainerPATCH 844/1276 fbdev: i740fb: fix potential memory leak in i740fb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 5936063409af230a2c88b8700c47b89a19fd70b5 upstream.
In i740fb_probe(), the memory allocated in fb_videomode_to_modelist() for modelist is not freed in the error paths. Fix that by calling fb_destroy_modelist().
--- drivers/video/fbdev/i740fb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/i740fb.c +1 -0
@@ -1152,6 +1152,7 @@ err_reg_framebuffer:fb_dealloc_cmap (&info->cmap); err_alloc_cmap: err_find_mode: +fb_destroy_modelist (&info->modelist);if (par->ddc_registered)i2c_del_adapter (&par->ddc_adapter);pci_iounmap (dev, par->regs);
Greg Kroah-Hartman
maintainerPATCH 845/1276 fbdev: s3fb: fix potential memory leak in s3_pci_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 3b0ed04bc852887a9164e1bbf521652e8ef3eb92 upstream.
In s3_pci_probe(), the memory allocated for modelist using fb_videomode_to_modelist() is not freed in subsequent error paths. Fix that by calling fb_destroy_modelist()
--- drivers/video/fbdev/s3fb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/s3fb.c +1 -0
@@ -1382,6 +1382,7 @@ err_reg_fb: err_alloc_cmap: err_find_mode:#ifdef CONFIG_FB_S3_DDC +fb_destroy_modelist (&info->modelist);if (par->ddc_registered)i2c_del_adapter (&par->ddc_adapter);if (par->mmio)
Greg Kroah-Hartman
maintainerPATCH 846/1276 fbdev: uvesafb: fix potential memory leak in uvesafb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 033e56fed09047ee63072e9f58789f40c1c7079d upstream.
Due to an incorrect goto label, memory allocated for modedb and modelist in uvesafb_vbe_init() is not freed in some error paths. Fix this by updating the goto label.
--- drivers/video/fbdev/uvesafb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/video/fbdev/uvesafb.c +2 -2
@@ -1697,14 +1697,14 @@ static int uvesafb_probe(struct platform i =uvesafb_vbe_init_mode (info);if (i <0 ) { err = -EINVAL ; - goto out; + goto out_mode; }else { mode = &par->vbe_modes[i]; }if (fb_alloc_cmap (&info->cmap,256 ,0 ) <0 ) { err = -ENXIO ; - goto out; + goto out_mode; }uvesafb_init_info (info, mode);
Greg Kroah-Hartman
maintainerPATCH 847/1276 fbdev: tdfxfb: fix potential memory leak in tdfxfb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit bb019d755366cc3e777a12d4bf457ff289837370 upstream.
In tdfxfb_probe(), the memory allocated for modelist using fb_videomode_to_modelist() when CONFIG_FB_3DFX_I2C is defined, is not freed in the subsequent error paths.
Fix that by calling fb_destroy_modelist().
--- drivers/video/fbdev/tdfxfb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/tdfxfb.c +1 -0
@@ -1550,6 +1550,7 @@ static int tdfxfb_probe(struct pci_dev * out_err_iobase:#ifdef CONFIG_FB_3DFX_I2C +fb_destroy_modelist (&info->modelist);tdfxfb_delete_i2c_busses (default_par);#endif arch_phys_wc_del (default_par->wc_cookie);
Greg Kroah-Hartman
maintainerPATCH 848/1276 fbdev: carminefb: fix potential memory leak in alloc_carmine_fb()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 6fcca16a2b19c37f60693c56cbc0c923364ff3ef upstream.
The memory allocated for modelist in fb_videomode_to_modelist() is not freed in the subsequent error path.
Fix that by calling fb_destroy_modelist()
--- drivers/video/fbdev/carminefb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/carminefb.c +1 -0
@@ -589,6 +589,7 @@ static int alloc_carmine_fb(void __iomemreturn 0 ; err_dealloc_cmap: +fb_destroy_modelist (&info->modelist);fb_dealloc_cmap (&info->cmap); err_free_fb:framebuffer_release (info);
Greg Kroah-Hartman
maintainerPATCH 849/1276 fbdev: vesafb: fix memory leak in vesafb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit b15d708995c01bbffe7dcd634a31959f6805bed3 upstream.
Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the string returned from fb_get_options() is expected to be freed by the caller. But the string is not freed in vesafb_probe(). Fix that by freeing the option string after setup.
--- drivers/video/fbdev/vesafb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/vesafb.c +1 -0
@@ -267,6 +267,7 @@ static int vesafb_probe(struct platform_/* ignore error return of fb_get_options */ fb_get_options ("vesafb" , &option);vesafb_setup (option); +kfree (option);if (si->orig_video_isVGA !=VIDEO_TYPE_VLFB )return -ENODEV ;
Greg Kroah-Hartman
maintainerPATCH 850/1276 fbdev: nvidia: fix potential memory leak in nvidiafb_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 85f5e38c162bdf9dbbe197275d416402712f3707 upstream.
In nvidiafb_probe(), the memory allocated for modelist in nvidia_set_fbinfo() is not freed in the subsequent error paths. Fix that by calling fb_destroy_modelist().
--- drivers/video/fbdev/nvidia/nvidia.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/nvidia/nvidia.c +1 -0
@@ -1420,6 +1420,7 @@ static int nvidiafb_probe(struct pci_dev err_out_iounmap_fb:iounmap (info->screen_base); +fb_destroy_modelist (&info->modelist); err_out_free_base1:fb_destroy_modedb (info->monspecs.modedb);nvidia_delete_i2c_busses (par);
Greg Kroah-Hartman
maintainerPATCH 851/1276 fbdev: tridentfb: fix potential memory leak in trident_pci_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 7a35ec619d9af8ee128320975c1252b8ad65f1e8 upstream.
In trident_pci_probe(), the memory allocated for modelist using fb_videomode_to_modelist() is not freed in subsequent error paths. Fix that by calling fb_destroy_modelist().
--- drivers/video/fbdev/tridentfb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/tridentfb.c +1 -0
@@ -1706,6 +1706,7 @@ static int trident_pci_probe(struct pci_return 0 ; out_unmap2: +fb_destroy_modelist (&info->modelist);if (default_par->ddc_registered)i2c_del_adapter (&default_par->ddc_adapter);kfree (info->pixmap.addr);
Greg Kroah-Hartman
maintainerPATCH 852/1276 ASoC: SOF: ipc3-control: Fix heap overflow in bytes_ext put/get
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit fd46668d538993218eea19c6925c868ac0f2630c upstream.
The ipc_control_data buffer is allocated as kzalloc(max_size), where max_size covers the entire struct sof_ipc_ctrl_data including its flexible array payload. However, the bounds checks in bytes_ext_put and _bytes_ext_get compared user data lengths against max_size directly, ignoring that cdata->data sits at an offset of sizeof(struct sof_ipc_ctrl_data) bytes into the allocation.
This allowed writing up to sizeof(struct sof_ipc_ctrl_data) bytes past the end of the heap buffer from unprivileged userspace via the ALSA TLV kcontrol interface, and similarly allowed over-reading adjacent heap data on the get path.
Fix all bounds checks to subtract sizeof(*cdata) from max_size so they reflect the actual space available at the cdata->data offset. Also fix the error-path restore in bytes_ext_put which wrote to cdata->data instead of cdata, causing the same overflow.
--- sound/soc/sof/ipc3-control.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
sound/soc/sof/ipc3-control.c +19 -8
@@ -398,9 +398,17 @@ static int sof_ipc3_bytes_ext_put(struct }/* be->max is coming from topology */ -if (header.length > scontrol->max_size) { -dev_err_ratelimited (scomp->dev,"Bytes data size %d exceeds max %zu\n" , - header.length, scontrol->max_size); +if (header.length > scontrol->max_size -sizeof (*cdata)) { +dev_err_ratelimited (scomp->dev,"Bytes data size %u exceeds max %zu\n" , + header.length, scontrol->max_size -sizeof (*cdata)); +return -EINVAL ; + } + +/* Ensure the data is large enough to contain the ABI header */ +if (header.length <sizeof (struct sof_abi_hdr )) { +dev_err_ratelimited (scomp->dev, +"Bytes data size %u less than ABI header %zu\n" , + header.length,sizeof (struct sof_abi_hdr ));return -EINVAL ; }
@@ -436,7 +444,7 @@ static int sof_ipc3_bytes_ext_put(struct }/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ -if (cdata->data->size > scontrol->max_size -sizeof (struct sof_abi_hdr )) { +if (cdata->data->size > scontrol->max_size -sizeof (*cdata) -sizeof (struct sof_abi_hdr )) {dev_err_ratelimited (scomp->dev,"Mismatch in ABI data size (truncated?)\n" ); goto err_restore; }
@@ -452,7 +460,7 @@ static int sof_ipc3_bytes_ext_put(struct err_restore:/* If we have an issue, we restore the old, valid bytes control data */ if (scontrol->old_ipc_control_data) { -memcpy (cdata->data, scontrol->old_ipc_control_data, scontrol->max_size); +memcpy (cdata, scontrol->old_ipc_control_data, scontrol->max_size);kfree (scontrol->old_ipc_control_data); scontrol->old_ipc_control_data =NULL ; }
@@ -491,10 +499,13 @@ static int _sof_ipc3_bytes_ext_get(struc }/* check data size doesn't exceed max coming from topology */ -if (cdata->data->size > scontrol->max_size -sizeof (struct sof_abi_hdr )) { -dev_err_ratelimited (scomp->dev,"User data size %d exceeds max size %zu\n" , +if (cdata->data->size > scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr )) { +dev_err_ratelimited (scomp->dev, +"User data size %u exceeds max size %zu\n" , cdata->data->size, - scontrol->max_size -sizeof (struct sof_abi_hdr )); + scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr ));return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 853/1276 ASoC: SOF: ipc3-control: Validate size in snd_sof_update_control
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 390aa4c9339bb0ec0bc8d554e830faf93ca9d49e upstream.
In snd_sof_update_control(), firmware-provided cdata->num_elems is checked against local_cdata->data->size but never against the actual allocation size. If local_cdata->data->size was previously set to an inconsistent value, the memcpy could write past the allocated buffer.
Add a bounds check to ensure num_elems fits within the available space in the ipc_control_data allocation before copying.
--- sound/soc/sof/ipc3-control.c | 9 +++++++++ 1 file changed, 9 insertions(+)
sound/soc/sof/ipc3-control.c +9 -0
@@ -555,6 +555,15 @@ static void snd_sof_update_control(strucreturn ; } +/* Verify the size fits within the allocation */ +if (cdata->num_elems > scontrol->max_size -sizeof (*local_cdata) - +sizeof (*local_cdata->data)) { +dev_err (scomp->dev, +"cdata binary size %u exceeds buffer\n" , + cdata->num_elems); +return ; + } +/* copy the new binary data */ memcpy (local_cdata->data, cdata->data, cdata->num_elems); }else if (cdata->num_elems != scontrol->num_channels) {
Greg Kroah-Hartman
maintainerPATCH 854/1276 ASoC: mediatek: mt8192: Release reserved memory on cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
commit 965e17ae6751c5d3302430c8ebd650e72d45a85f upstream.
The MT8192 AFE probe calls of_reserved_mem_device_init() and falls back to preallocated buffers when no reserved memory region is available. When the reserved memory assignment succeeds, however, the driver never releases it.
Register a devm cleanup action after a successful reserved-memory assignment so the assignment is released on probe failure and driver unbind.
--- sound/soc/mediatek/mt8192/mt8192-afe-pcm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
sound/soc/mediatek/mt8192/mt8192-afe-pcm.c +9 -0
@@ -2155,6 +2155,11 @@ static const dai_register_cb dai_registe mt8192_dai_memif_register, }; +static void mt8192_afe_release_reserved_mem (void *data) +{ +of_reserved_mem_device_release (data); +} +static int mt8192_afe_pcm_dev_probe (struct platform_device *pdev) {struct mtk_base_afe *afe;
@@ -2185,6 +2190,10 @@ static int mt8192_afe_pcm_dev_probe(struif (ret) {dev_info (dev,"no reserved memory found, pre-allocating buffers instead\n" ); afe->preallocate_buffers = true; + }else { + ret =devm_add_action_or_reset (dev, mt8192_afe_release_reserved_mem, dev); +if (ret) +return ret; }/* init audio related clock */
Greg Kroah-Hartman
maintainerPATCH 855/1276 ASoC: mediatek: mt8183: Release reserved memory on cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
commit bee65e00c0924ebecf97718d95dcf4a05ee36471 upstream.
The MT8183 AFE probe can assign reserved memory with of_reserved_mem_device_init(), but the assignment is never released on driver removal or later probe failures.
Register a devm cleanup action so the reserved memory assignment is released consistently, matching newer Mediatek AFE drivers.
--- sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c +11 -0
@@ -1073,6 +1073,11 @@ static const dai_register_cb dai_registe mt8183_dai_memif_register, }; +static void mt8183_afe_release_reserved_mem (void *data) +{ +of_reserved_mem_device_release (data); +} +static int mt8183_afe_pcm_dev_probe (struct platform_device *pdev) {struct mtk_base_afe *afe;
@@ -1099,6 +1104,12 @@ static int mt8183_afe_pcm_dev_probe(struif (ret) {dev_info (dev,"no reserved memory found, pre-allocating buffers instead\n" ); afe->preallocate_buffers = true; + }else { + ret =devm_add_action_or_reset (dev, + mt8183_afe_release_reserved_mem, + dev); +if (ret) +return ret; }/* initial audio related clock */
Greg Kroah-Hartman
maintainerPATCH 856/1276 ASoC: qcom: q6apm: fix NULL pointer dereference in graph_callback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
commit 2e9261761b35f0b67b7487688cd1365f535be0b3 upstream.
When q6apm_free_fragments() is called it frees rx_data.buf/tx_data.buf and sets them to NULL under graph->lock. A late DSP buffer-done response can race with this: graph_callback() passes the !graph->ar_graph guard (not yet NULL), acquires the lock, but then dereferences a now-NULL buf pointer to read buf[token].phys, crashing at virtual address 0x10.
Add a NULL check for buf inside the mutex-protected section in both the write-done (DATA_CMD_RSP_WR_SH_MEM_EP_DATA_BUFFER_DONE_V2) and read-done (DATA_CMD_RSP_RD_SH_MEM_EP_DATA_BUFFER_V2) handlers and bail out cleanly if buffers have already been freed.
This problem is only shown up recently while apr bus was updated to process the commands per service rather from single global queue.
--- sound/soc/qcom/qdsp6/q6apm.c | 8 ++++++++ 1 file changed, 8 insertions(+)
sound/soc/qcom/qdsp6/q6apm.c +8 -0
@@ -533,6 +533,10 @@ static int graph_callback(struct gpr_res token = hdr->token &APM_WRITE_TOKEN_MASK ; done = data->payload; +if (!graph->rx_data.buf) { +mutex_unlock (&graph->lock); +break ; + } phys = graph->rx_data.buf[token].phys;mutex_unlock (&graph->lock);/* token numbering starts at 0 */
@@ -567,6 +571,10 @@ static int graph_callback(struct gpr_res client_event =APM_CLIENT_EVENT_DATA_READ_DONE ;mutex_lock (&graph->lock); rd_done = data->payload; +if (!graph->tx_data.buf) { +mutex_unlock (&graph->lock); +break ; + } phys = graph->tx_data.buf[hdr->token].phys;mutex_unlock (&graph->lock);/* token numbering starts at 0 */
Greg Kroah-Hartman
maintainerPATCH 857/1276 netfilter: nf_conntrack_irc: fix parse_dcc() off-by-one OOB read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit ef6400ca25a13fd6dedbe8ef4a1d0979bbbfe88a upstream.
parse_dcc() treats data_end as an inclusive end pointer, but its only caller passes data_limit = ib_ptr + datalen, which points one past the last valid byte.
The newline search loop iterates while tmp <= data_end, so when no newline is present, *tmp is read at tmp == data_end, one byte beyond the region filled by skb_header_pointer().
irc_buffer is kmalloc'd as MAX_SEARCH_SIZE + 1 bytes and datalen is capped at MAX_SEARCH_SIZE, so the stray read does not fault. The byte is uninitialized or stale; if it contains an ASCII digit, simple_strtoul will consume it and produce a wrong DCC IP or port in the conntrack expectation. The extra allocation byte is also a fragile guard: if the cap or allocation size changes, this becomes a real out-of-bounds read.
Change the loop and its post-loop check to use strict less-than, consistent with the caller's exclusive-end convention. Update the function comment accordingly.
--- net/netfilter/nf_conntrack_irc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_conntrack_irc.c +3 -3
@@ -64,7 +64,7 @@ static const char *const dccprotos[] = {/* tries to get the ip_addr and port out of a dcc command * return value: -1 on failure, 0 on success * data pointer to first byte of DCC command data -* data_end pointer to last byte of dcc command data +* data_end one past end of data * ip returns parsed ip of dcc command * port returns parsed port of dcc command * ad_beg_p returns pointer to first byte of addr data
@@ -82,10 +82,10 @@ static int parse_dcc(char *data, const c/* Make sure we have a newline character within the packet boundaries * because simple_strtoul parses until the first invalid character. */ -for (tmp = data; tmp <= data_end; tmp++) +for (tmp = data; tmp < data_end; tmp++)if (*tmp =='\n' )break ; -if (tmp > data_end || *tmp !='\n' ) +if (tmp >= data_end || *tmp !='\n' )return -1 ; *ad_beg_p = data;
Greg Kroah-Hartman
maintainerPATCH 858/1276 netfilter: nfnl_cthelper: apply per-class values when updating policies
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit d738feccb98cb224ebabecb703e98f5008276bff upstream.
When a userspace conntrack helper with multiple expectation classes is updated via nfnetlink, every class ends up with the first class's max_expected and timeout values.
nfnl_cthelper_update_policy_all() validates each new policy into the corresponding slot of the temporary new_policy array, but the second loop that commits the values into the live helper dereferences new_policy as a pointer instead of indexing it, so every iteration reads new_policy[0] regardless of i. An update that changes per-class values is silently collapsed onto class 0's values with no error returned to userspace.
Index the temporary array by i in the commit loop so each class gets its own validated values.
--- net/netfilter/nfnetlink_cthelper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nfnetlink_cthelper.c +2 -2
@@ -351,8 +351,8 @@ static int nfnl_cthelper_update_policy_afor (i =0 ; i < helper->expect_class_max +1 ; i++) { policy = (struct nf_conntrack_expect_policy *) &helper->expect_policy[i]; - policy->max_expected = new_policy->max_expected; - policy->timeout = new_policy->timeout; + policy->max_expected = new_policy[i].max_expected; + policy->timeout = new_policy[i].timeout; } err:
Greg Kroah-Hartman
maintainerPATCH 859/1276 netfilter: xt_cluster: reject template conntracks in hash match
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wyatt Feng <[email protected]>
commit 5feba91006ec92da57acc1cc2e34df623b98541e upstream.
xt_cluster_mt() treats any non-NULL nf_ct_get() result as a fully initialized conntrack and passes it to xt_cluster_hash().
This causes a state confusion bug when the raw table CT target attaches a template conntrack to skb->_nfct before normal conntrack processing. Templates carry IPS_TEMPLATE status but do not have a valid tuple for hashing yet, so xt_cluster_hash() can hit its WARN_ON() path on the zeroed l3num field.
Reject template conntracks before hashing them. This matches existing netfilter handling for template objects and avoids hashing incomplete conntrack state.
--- net/netfilter/xt_cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_cluster.c +1 -1
@@ -107,7 +107,7 @@ xt_cluster_mt(const struct sk_buff *skb, } ct =nf_ct_get (skb, &ctinfo); -if (ct ==NULL ) +if (!ct ||nf_ct_is_template (ct))return false;if (ct->master)
Greg Kroah-Hartman
maintainerPATCH 860/1276 netfilter: nf_queue: pin bridge device while NFQUEUE holds fake dst
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoze Xie <[email protected]>
commit c9c9b37f8c5505224e8d206184df3bb668ee00cf upstream.
The br_netfilter fake rtable is embedded in struct net_bridge and is attached to bridged packets with skb_dst_set_noref(). If such a packet is queued to NFQUEUE, __nf_queue() upgrades that fake dst with skb_dst_force().
At that point the queued skb can hold a real dst reference after bridge teardown has started. The problem is not that every bridged packet needs its own dst reference. The problem is that NFQUEUE can keep the bridge private fake dst alive after unregister begins.
Fix this by keeping the bridge fake dst model unchanged and pinning the bridge master device only while the packet sits in NFQUEUE. Record the bridge device in nf_queue_entry when the queued skb carries a bridge fake dst, take a device reference for the queue lifetime, and drop it when the queue entry is freed.
Also make sure queued entries are reaped when that bridge device goes down, and drop the redundant nf_bridge_info_exists() test from the fake dst detection.
This keeps netdev_priv(br->dev) alive until verdict completion, so the embedded fake rtable and its metrics backing storage cannot be freed out from under dst_release(). It also avoids the constant refcount bump and avoids using ipv4-specific dst helpers for IPv6 bridge traffic.
--- include/net/netfilter/nf_queue.h | 1 + net/netfilter/nf_queue.c | 14 ++++++++++++++ net/netfilter/nfnetlink_queue.c | 3 +++ 3 files changed, 18 insertions(+)
include/net/netfilter/nf_queue.h +1 -0
@@ -18,6 +18,7 @@ struct nf_queue_entry {unsigned int id;unsigned int hook_index;/* index in hook_entries->hook[] */ #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +struct net_device *bridge_dev;struct net_device *physin;struct net_device *physout;#endif
net/netfilter/nf_queue.c +14 -0
@@ -67,6 +67,7 @@ static void nf_queue_entry_release_refs(nf_queue_sock_put (state->sk);#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +dev_put (entry->bridge_dev);dev_put (entry->physin);dev_put (entry->physout);#endif
@@ -83,6 +84,8 @@ static void __nf_queue_entry_init_physde {#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )const struct sk_buff *skb = entry->skb; +struct dst_entry *dst =skb_dst (skb); +struct net_device *dev =NULL ;if (nf_bridge_info_exists (skb)) { entry->physin =nf_bridge_get_physindev (skb, entry->state.net);
@@ -91,6 +94,16 @@ static void __nf_queue_entry_init_physde entry->physin =NULL ; entry->physout = NULL; } + +if (entry->state.pf ==NFPROTO_BRIDGE && + dst && (dst->flags &DST_FAKE_RTABLE )) + dev =dst_dev_rcu (dst); + +/* Must hold a reference on the bridge device: dst_hold() protects +* the dst itself, but the fake rtable is embedded in bridge-private +* storage that netdevice teardown can free independently. +*/ + entry->bridge_dev = dev;#endif }
@@ -107,6 +120,7 @@ bool nf_queue_entry_get_refs(struct nf_qdev_hold (state->out);#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +dev_hold (entry->bridge_dev);dev_hold (entry->physin);dev_hold (entry->physout);#endif
net/netfilter/nfnetlink_queue.c +3 -0
@@ -1251,6 +1251,9 @@ dev_cmp(struct nf_queue_entry *entry, unif (physinif == ifindex || physoutif == ifindex)return 1 ; + +if (entry->bridge_dev && entry->bridge_dev->ifindex == ifindex) +return 1 ;#endif if (entry->skb_dev && entry->skb_dev->ifindex == ifindex)return 1 ;
Greg Kroah-Hartman
maintainerPATCH 861/1276 netfilter: nft_set_pipapo: dont leak bad clone into future transaction
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 47e65eff50691f0a5b79d325e28d83ec1da43bcf upstream.
On memory allocation failure the cloned nft_pipapo_match can enter a bad state:
- some fields can have their lookup tables resized while others did not
- bits might have been toggled
- scratch map can be undersized which also means m->bsize_max can be lower than what is required
This means that the next insertion in the same batch can trigger out-of-bounds writes.
Furthermore, a failure in the first can result in the bad clone to leak into the next transaction because the abort callback is never executed in this case (the upper layer saw an error and no attempt to allocate a transactional request was made).
Record a state for the nft_pipapo_match structure:
- NEW (pristine clone)
- MOD (modified clone with good state)
- ERR (potentially bogus content)
Then make it so that deletes and insertions fail when the clone entered ERR state.
In case the very first insert attempt results in an error, free the clone right away.
--- net/netfilter/nft_set_pipapo.c | 34 +++++++++++++++++++++++++++++----- net/netfilter/nft_set_pipapo.h | 8 ++++++++ 2 files changed, 37 insertions(+), 5 deletions(-)
net/netfilter/nft_set_pipapo.c +29 -5
@@ -342,6 +342,8 @@#include "nft_set_pipapo_avx2.h" #include "nft_set_pipapo.h" +static void nft_pipapo_abort (const struct nft_set *set); +/** * pipapo_refill() - For each set bit, set bits from selected mapping table item * @map: Bitmap to be scanned for set bits
@@ -1284,7 +1286,7 @@ static int nft_pipapo_insert(const strucconst u8 *start_p, *end_p;int i, bsize_max, err =0 ; -if (!m) +if (!m || m->state ==NFT_PIPAPO_CLONE_ERR )return -ENOMEM ;if (nft_set_ext_exists (ext,NFT_SET_EXT_KEY_END ))
@@ -1355,8 +1357,10 @@ static int nft_pipapo_insert(const strucelse ret =pipapo_expand (f, start, end, f->groups * f->bb); -if (ret <0 ) -return ret; +if (ret <0 ) { + err = ret; + goto abort; + }if (f->bsize > bsize_max) bsize_max = f->bsize;
@@ -1372,7 +1376,7 @@ static int nft_pipapo_insert(const struc err =pipapo_realloc_scratch (m, bsize_max);if (err) -return err; + goto abort; m->bsize_max = bsize_max; }else {
@@ -1384,7 +1388,26 @@ static int nft_pipapo_insert(const strucpipapo_map (m, rulemap, e); + m->state =NFT_PIPAPO_CLONE_MOD ;return 0 ; +abort: +DEBUG_NET_WARN_ON_ONCE (m->state ==NFT_PIPAPO_CLONE_ERR ); + +/* Two rollback cases: +* 1) no previous changes. nft_pipapo_abort is not +* guaranteed to be invoked (there might be no further +* add/delete requests coming after this). +* +* 2) we had previous changes: there are transaction +* records pointing to this set. Leave the rollback to +* the transaction handling. +*/ +if (m->state ==NFT_PIPAPO_CLONE_NEW ) +nft_pipapo_abort (set);/* releases m */ +else + m->state =NFT_PIPAPO_CLONE_ERR ; + +return err; }/**
@@ -1462,6 +1485,7 @@ static struct nft_pipapo_match *pipapo_c dst++; } + new->state =NFT_PIPAPO_CLONE_NEW ;return new; out_mt:
@@ -1885,7 +1909,7 @@ nft_pipapo_deactivate(const struct net */* removal must occur on priv->clone, if we are low on memory * we have no choice and must fail the removal request. */ -if (!m) +if (!m || m->state ==NFT_PIPAPO_CLONE_ERR )return NULL ; e = pipapo_get(m, (const u8 *)elem->key.val.data,
net/netfilter/nft_set_pipapo.h +8 -0
@@ -134,9 +134,16 @@ struct nft_pipapo_scratch {unsigned long map[]; }; +enum nft_pipapo_clone_state { +NFT_PIPAPO_CLONE_NEW , +NFT_PIPAPO_CLONE_MOD , +NFT_PIPAPO_CLONE_ERR , +}; +/** * struct nft_pipapo_match - Data used for lookup and matching * @field_count: Amount of fields in set +* @state: add/delete state; used from control plane * @bsize_max: Maximum lookup table bucket size of all fields, in longs * @scratch: Preallocated per-CPU maps for partial matching results * @rcu: Matching data is swapped on commits
@@ -144,6 +151,7 @@ struct nft_pipapo_scratch {*/ struct nft_pipapo_match {u8 field_count; +enum nft_pipapo_clone_state state:8 ;unsigned int bsize_max;struct nft_pipapo_scratch *__percpu *scratch;struct rcu_head rcu;
Greg Kroah-Hartman
maintainerPATCH 862/1276 netfilter: nf_nat_sip: reload possible stale data pointer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 77e43bcb7ec177e293a5c3f1b91a2c5aebfb6c68 upstream.
quoting sashiko:
------------------------------------------------------------------------
[..] noticed a potential memory bug and header corruption involving the SIP NAT helper.
In net/netfilter/nf_nat_sip.c:nf_nat_sip():
if (skb_ensure_writable(skb, skb->len)) {
nf_ct_helper_log(skb, ct, "cannot mangle packet");
return NF_DROP;
}
uh = (void *)skb->data + protoff;
uh->dest = ct_sip_info->forced_dport;
if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo, protoff,
0, 0, NULL, 0)) { If a cloned or fragmented SKB is reallocated by skb_ensure_writable(), the old data buffer is freed. However, nf_nat_sip() fails to update *dptr to point to the new buffer.
It also appears to use nf_nat_mangle_udp_packet() on what could be a TCP packet, which would overwrite the sequence number with a checksum update.
------------------------------------------------------------------------
nf_conntrack_sip linerizes skbs, hence no fragmented skb can be seen. But clones are possible, so rebuild dptr.
Disable nf_nat_mangle_udp_packet() branch for TCP streams. It doesn't look like this can ever happen, else we should have received bug reports about this, so just check the conntrack is UDP and drop otherwise.
The calling conntrack_sip set ->forced_dport for SIP_HDR_VIA_UDP messages, so I don't think this is ever expected to be true for a TCP stream.
--- net/netfilter/nf_nat_sip.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/netfilter/nf_nat_sip.c +11 -0
@@ -283,13 +283,24 @@ next:/* Mangle destination port for Cisco phones, then fix up checksums */ if (dir ==IP_CT_DIR_REPLY && ct_sip_info->forced_dport) { +int doff = *dptr - (const char *)skb->data;struct udphdr *uh; +if (doff <=0 ) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return NF_DROP ; + } + +/* ct_sip_info->forced_dport only expected with UDP */ +if (nf_ct_protonum (ct) !=IPPROTO_UDP ) +return NF_DROP ; +if (skb_ensure_writable (skb, skb->len)) {nf_ct_helper_log (skb, ct,"cannot mangle packet" );return NF_DROP ; } + *dptr = skb->data + doff; uh = (void *)skb->data + protoff; uh->dest = ct_sip_info->forced_dport;
Greg Kroah-Hartman
maintainerPATCH 863/1276 netfilter: nf_conntrack_reasm: guard mac_header adjustment after IPv6 defrag
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
commit 3b08fed5b7e0d5e3a25d73ef3ba09cd33ade16c9 upstream.
nf_ct_frag6_reasm() slides the packet head forward to drop the IPv6 fragment header and then unconditionally advances skb->mac_header:
skb->mac_header += sizeof(struct frag_hdr);
On the NF_INET_LOCAL_OUT defrag path the skb has no link-layer header yet, so skb->mac_header is still the "not set" sentinel (u16)~0U. Adding sizeof(struct frag_hdr) wraps it to a small value (0xffff + 8 == 7), after which skb_mac_header_was_set() wrongly reports a MAC header is present and skb_mac_header() points into the headroom.
The reassembler has done this unconditional add since it was introduced; it was harmless while mac_header was a bare pointer, but wrong once mac_header became a u16 offset whose unset state is the ~0U sentinel tested by skb_mac_header_was_set(). The sibling net/ipv6/reassembly.c does the same relocation and does guard the adjustment; mirror the guard here.
--- net/ipv6/netfilter/nf_conntrack_reasm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/netfilter/nf_conntrack_reasm.c +2 -1
@@ -345,7 +345,8 @@ static int nf_ct_frag6_reasm(struct fragskb_network_header (skb)[fq->nhoffset] =skb_transport_header (skb)[0 ];memmove (skb->head +sizeof (struct frag_hdr ), skb->head, (skb->data - skb->head) -sizeof (struct frag_hdr )); - skb->mac_header +=sizeof (struct frag_hdr ); +if (skb_mac_header_was_set (skb)) + skb->mac_header +=sizeof (struct frag_hdr ); skb->network_header +=sizeof (struct frag_hdr );skb_reset_transport_header (skb);
Greg Kroah-Hartman
maintainerPATCH 864/1276 netfilter: nf_conncount: fix zone comparison in tuple dedup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
commit f62c41b4910e65da396ec9a8c40c1fe7fe82e449 upstream.
The "already exists" dedup logic in __nf_conncount_add() decides whether a connection has already been counted and can be skipped instead of incrementing the connlimit count. It compares the conntrack zone of a list entry with the zone of the connection being added using nf_ct_zone_id() and nf_ct_zone_equal(), passing conn->zone.dir or zone->dir as the direction argument.
Those helpers take enum ip_conntrack_dir values: IP_CT_DIR_ORIGINAL is 0 and IP_CT_DIR_REPLY is 1. However, zone->dir is a u8 bitmask:NF_CT_ZONE_DIR_ORIG is 1, NF_CT_ZONE_DIR_REPL is 2 and NF_CT_DEFAULT_ZONE_DIR is 3. Passing that bitmask as the enum direction shifts the meaning of every non-zero value. An ORIG-only zone passes 1 and is tested as REPLY, while REPL-only and default zones pass 2 or 3 and test bits beyond the valid direction range. In those cases nf_ct_zone_id() can fall back to NF_CT_DEFAULT_ZONE_ID instead of using the real zone id, so different zones can be treated as equal and dedup collapses to tuple equality alone.
nf_conncount stores and compares the original-direction tuple for a connection. If an skb already has an attached conntrack entry, get_ct_or_tuple_from_skb() explicitly copies ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, regardless of the packet's ctinfo. Therefore the zone comparison in the tuple dedup path must use IP_CT_DIR_ORIGINAL as well; the zone direction bitmask describes where a zone id applies, not which direction this conncount tuple represents.
Fix the two dedup comparisons by passing IP_CT_DIR_ORIGINAL directly. Do not special-case NF_CT_DEFAULT_ZONE_DIR and do not compare raw zone
ids: using the existing helpers with IP_CT_DIR_ORIGINAL preserves the direction-aware NF_CT_DEFAULT_ZONE_ID fallback. A default bidirectional zone contains the ORIG bit, so it naturally returns the real zone id; reply-only zones continue to fall back for original-direction tuple comparisons.
--- net/netfilter/nf_conncount.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_conncount.c +3 -3
@@ -207,8 +207,8 @@ check_connections:/* Not found, but might be about to be confirmed */ if (PTR_ERR (found) == -EAGAIN ) {if (nf_ct_tuple_equal (&conn->tuple, &tuple) && -nf_ct_zone_id (&conn->zone, conn->zone.dir) == -nf_ct_zone_id (zone, zone->dir)) +nf_ct_zone_id (&conn->zone,IP_CT_DIR_ORIGINAL ) == +nf_ct_zone_id (zone,IP_CT_DIR_ORIGINAL )) goto out_put;/* already exists */ }else { collect++;
@@ -219,7 +219,7 @@ check_connections: found_ct =nf_ct_tuplehash_to_ctrack (found);if (nf_ct_tuple_equal (&conn->tuple, &tuple) && -nf_ct_zone_equal (found_ct, zone, zone->dir)) { +nf_ct_zone_equal (found_ct, zone,IP_CT_DIR_ORIGINAL )) {/* * We should not see tuples twice unless someone hooks * this into a table without "-p tcp --syn".
Greg Kroah-Hartman
maintainerPATCH 865/1276 netfilter: ecache: fix inverted time_after() check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
commit b06163ce52ec0561f202fbfb9b08090cb61f512e upstream.
ecache_work_evict_list() redelivers DESTROY events for conntracks that were moved to the per-netns dying_list after event delivery failed. It sets a 10ms deadline:
stop = jiffies + ECACHE_MAX_JIFFIES
but then tests:
time_after(stop, jiffies)
This condition is true while the deadline is still in the future, so the worker returns STATE_RESTART after the first successful redelivery in the usual case. ecache_work() maps STATE_RESTART to delay 0, which turns the redelivery path into one dying conntrack per workqueue dispatch and makes the sent > 16 batching/cond_resched() path effectively unreachable.
A conntrack netlink listener whose receive queue is congested can make DESTROY event delivery fail with -ENOBUFS. With sustained conntrack churn, entries then accumulate on the dying_list and are only drained at the degraded one-entry-per-dispatch rate once delivery succeeds again, wasting CPU on back-to-back workqueue reschedules and prolonging conntrack memory/resource pressure.
In a KASAN QEMU test with CONFIG_NF_CONNTRACK_EVENTS=y and nf_conntrack.enable_hooks=1, a congested DESTROY listener caused 8192 nf_ct_delete() calls to return false and move entries to the dying_list. After closing the listener, the unfixed kernel needed 7670 ecache_work() entries to destroy 7669 conntracks. With this change, the same 8192 entries were destroyed by 2 ecache_work() entries.
Swap the comparison so the worker restarts only after the deadline has expired.
--- net/netfilter/nf_conntrack_ecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_ecache.c +1 -1
@@ -77,7 +77,7 @@ next:hlist_nulls_del_rcu (&ct->tuplehash[IP_CT_DIR_ORIGINAL ].hnnode);hlist_nulls_add_head (&ct->tuplehash[IP_CT_DIR_REPLY ].hnnode, &evicted_list); -if (time_after (stop, jiffies)) { +if (time_after (jiffies, stop)) { ret =STATE_RESTART ;break ; }
Greg Kroah-Hartman
maintainerPATCH 866/1276 netfilter: xt_nat: reject unsupported target families
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wyatt Feng <[email protected]>
commit 5d1a2240935ea47e2673d0ea17fdb058e4dc91dd upstream.
xt_nat SNAT and DNAT target handlers assume IP-family conntrack state is present and can dereference a NULL pointer when instantiated from an unsupported family through nft_compat. A bridge-family compat rule can therefore trigger a NULL-dereference in nf_nat_setup_info().
Reject non-IP families in xt_nat_checkentry() so unsupported targets cannot be installed. Keep NFPROTO_INET allowed for valid inet NAT compat users and leave the runtime fast path unchanged.
[ The crash was fixed via
9dbba7e694ec ("netfilter: nft_compat: ebtables emulation must reject non-bridge targets"), so this patch is no longer critical.
Nevertheless, NAT is only relevant for ipv4/ipv6, so this extra
family check is a good idea in any case. ]
--- net/netfilter/xt_nat.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/netfilter/xt_nat.c +9 -0
@@ -26,6 +26,15 @@ static int xt_nat_checkentry_v0(const ststatic int xt_nat_checkentry (const struct xt_tgchk_param *par) { +switch (par->family) { +case NFPROTO_IPV4 : +case NFPROTO_IPV6 : +case NFPROTO_INET : +break ; +default : +return -EINVAL ; + } +return nf_ct_netns_get (par->net, par->family); }
Greg Kroah-Hartman
maintainerPATCH 867/1276 netfilter: bridge: fix stale prevhdr pointer in br_ip6_fragment()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei (Microsoft) <[email protected]>
commit 86f3ce81dd2b4b0aa2c3016c989a943e4b1b643d upstream.
br_ip6_fragment() gets prevhdr, a pointer into the skb head, from ip6_find_1stfragopt(), then calls skb_checksum_help(). For a cloned skb skb_checksum_help() reallocates the head via pskb_expand_head(), leaving prevhdr dangling. It is later dereferenced in ip6_frag_next(), causing a use-after-free write.
Save prevhdr's offset before skb_checksum_help() and recompute it after, like commit ef0efcd3bd3f ("ipv6: Fix dangling pointer when ipv6 fragment").
BUG: KASAN: slab-use-after-free in ip6_frag_next (net/ipv6/ip6_output.c:857) Write of size 1 at addr ffff888013ff5016 by task exploit/141 Call Trace: ... kasan_report (mm/kasan/report.c:595) ip6_frag_next (net/ipv6/ip6_output.c:857) br_ip6_fragment (net/ipv6/netfilter.c:212) nf_ct_bridge_post (net/bridge/netfilter/nf_conntrack_bridge.c:407) nf_hook_slow (net/netfilter/core.c:619) br_forward_finish (net/bridge/br_forward.c:66) __br_forward (net/bridge/br_forward.c:115) maybe_deliver (net/bridge/br_forward.c:191) br_flood (net/bridge/br_forward.c:245) br_handle_frame_finish (net/bridge/br_input.c:229) br_handle_frame (net/bridge/br_input.c:442) ... packet_sendmsg (net/packet/af_packet.c:3114) ... do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Kernel panic - not syncing: Fatal exception in interrupt
--- net/ipv6/netfilter.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/netfilter.c +3 -1
@@ -131,7 +131,7 @@ int br_ip6_fragment(struct net *net, strktime_t tstamp = skb->tstamp;struct ip6_frag_state state;u8 *prevhdr, nexthdr =0 ; -unsigned int mtu, hlen; +unsigned int mtu, hlen, nexthdr_offset;int hroom, err =0 ;__be32 frag_id;
@@ -140,6 +140,7 @@ int br_ip6_fragment(struct net *net, str goto blackhole; hlen = err; nexthdr = *prevhdr; + nexthdr_offset = prevhdr -skb_network_header (skb); mtu = skb->dev->mtu; if (frag_max_size > mtu ||
@@ -158,6 +159,7 @@ int br_ip6_fragment(struct net *net, str (err = skb_checksum_help(skb))) goto blackhole; + prevhdr =skb_network_header (skb) + nexthdr_offset; hroom =LL_RESERVED_SPACE (skb->dev);if (skb_has_frag_list (skb)) {unsigned int first_len =skb_pagelen (skb);
Greg Kroah-Hartman
maintainerPATCH 868/1276 gpu: host1x: Fix device reference leak in host1x_device_parse_dt() error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit e75717f9aec04355777be41070890c6a815c76df upstream.
After device_initialize(), the embedded struct device in struct host1x_device should be released through the device core with put_device().
In host1x_device_add(), if host1x_device_parse_dt() fails, the current error path frees the object directly with kfree(device). That bypasses the normal device lifetime handling and leaks the reference held on the embedded struct device.
The issue was identified by a static analysis tool I developed and confirmed by manual review.
Fix this by using put_device() in the host1x_device_parse_dt() failure path.
--- drivers/gpu/host1x/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/host1x/bus.c +1 -1
@@ -457,7 +457,7 @@ static int host1x_device_add(struct host err =host1x_device_parse_dt (device, driver);if (err <0 ) { -kfree (device); +put_device (&device->dev);return err; }
Greg Kroah-Hartman
maintainerPATCH 869/1276 soc: ti: k3-ringacc: Fix access mode for k3_ringacc_ring_pop_tail_io/proxy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siddharth Vadapalli <[email protected]>
commit b920352cfd2b0fcd1249ff006618c939b64fc8f7 upstream.
k3_ringacc_ring_pop_tail_io() and k3_ringacc_ring_pop_tail_proxy() incorrectly use K3_RINGACC_ACCESS_MODE_POP_HEAD instead of K3_RINGACC_ACCESS_MODE_POP_TAIL. This will result in ring elements being popped in the reverse order of that which the caller expects. Fix this.
--- drivers/soc/ti/k3-ringacc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/ti/k3-ringacc.c +2 -2
@@ -1012,7 +1012,7 @@ static int k3_ringacc_ring_pop_head_proxstatic int k3_ringacc_ring_pop_tail_proxy (struct k3_ring *ring,void *elem) {return k3_ringacc_ring_access_proxy (ring, elem, -K3_RINGACC_ACCESS_MODE_POP_HEAD ); +K3_RINGACC_ACCESS_MODE_POP_TAIL ); } static int k3_ringacc_ring_access_io(struct k3_ring *ring, void *elem,
@@ -1083,7 +1083,7 @@ static int k3_ringacc_ring_pop_io(structstatic int k3_ringacc_ring_pop_tail_io (struct k3_ring *ring,void *elem) {return k3_ringacc_ring_access_io (ring, elem, -K3_RINGACC_ACCESS_MODE_POP_HEAD ); +K3_RINGACC_ACCESS_MODE_POP_TAIL ); }/*
Greg Kroah-Hartman
maintainerPATCH 870/1276 soc: fsl: qe: panic on ioremap() failure in qe_reset()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wang Jun <[email protected]>
commit a0fe29d20e7822182e12324905af5115c1b3aed3 upstream.
When ioremap() fails in qe_reset(), the global pointer qe_immr remains NULL, leading to a subsequent NULL pointer dereference when the pointer is accessed. Since this happens early in the boot process, a failure to map a few bytes of I/O memory indicates a fatal error from which the system cannot recover.
Follow the same pattern as qe_sdma_init() and panic immediately when ioremap() fails. This avoids a silent NULL pointer dereference later and makes the error explicit.
--- drivers/soc/fsl/qe/qe.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/soc/fsl/qe/qe.c +3 -0
@@ -89,6 +89,9 @@ void qe_reset(void)if (qe_immr ==NULL ) qe_immr =ioremap (get_qe_base (),QE_IMMAP_SIZE ); +if (!qe_immr) +panic ("QE:ioremap failed!" ); +qe_snums_init (); qe_issue_cmd(QE_RESET, QE_CR_SUBBLOCK_INVALID,
Greg Kroah-Hartman
maintainerPATCH 871/1276 selinux: check connect-related permissions on TCP Fast Open
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Smalley <[email protected]>
commit 44c74d27d1b9aaa99fa8a83640c1223575262b80 upstream.
Similar to Landlock, SELinux was not updated when TCP Fast Open support was introduced to ensure connect-related permissions are checked when using TCP Fast Open. Update its socket_sendmsg() hook to call selinux_socket_connect() when MSG_FASTOPEN is passed.
--- security/selinux/hooks.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
security/selinux/hooks.c +18 -1
@@ -5077,7 +5077,24 @@ static int selinux_socket_accept(structstatic int selinux_socket_sendmsg (struct socket *sock,struct msghdr *msg,int size) { -return sock_has_perm (sock->sk,SOCKET__WRITE ); +int rc; +struct sockaddr *const addr = msg->msg_name; +const int addrlen = msg->msg_namelen; + + rc =sock_has_perm (sock->sk,SOCKET__WRITE ); +if (rc) +return rc; + +if (addr && (msg->msg_flags &MSG_FASTOPEN ) && + (sk_is_tcp (sock->sk) || + (sk_is_inet (sock->sk) && sock->sk->sk_type ==SOCK_STREAM && + sock->sk->sk_protocol ==IPPROTO_MPTCP ))) { + rc =selinux_socket_connect (sock, addr, addrlen); +if (rc) +return rc; + } + +return 0 ; } static int selinux_socket_recvmsg(struct socket *sock, struct msghdr *msg,
Greg Kroah-Hartman
maintainerPATCH 872/1276 selinux: avoid sk_socket dereference in selinux_sctp_bind_connect()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 56acfeb10019e200ab6787d01f8d7cbe0f01526f upstream.
selinux_sctp_bind_connect() dereferences sk->sk_socket to pass a struct socket * to selinux_socket_bind() and selinux_socket_connect_helper(). However, when the hook is invoked from the ASCONF softirq path (sctp_process_asconf), there is no file reference guaranteeing that sk->sk_socket is non-NULL. The setsockopt callers (bindx, connectx, set_primary, sendmsg connect) hold a file reference and are not affected.
Both selinux_socket_bind() and selinux_socket_connect_helper() immediately resolve sock->sk, never using the struct socket * for anything else. Refactor the inner logic into helpers that take a struct sock * directly so that selinux_sctp_bind_connect() never needs to touch sk->sk_socket at all.
--- security/selinux/hooks.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
security/selinux/hooks.c +10 -9
@@ -4801,9 +4801,8 @@ static int selinux_socket_socketpair(strNeed to determine whether we should perform a name_bind permission check between the socket and the port number. */ -static int selinux_socket_bind (struct socket *sock,struct sockaddr *address,int addrlen) +static int __selinux_socket_bind (struct sock *sk,struct sockaddr *address,int addrlen) { -struct sock *sk = sock->sk;struct sk_security_struct *sksec =selinux_sock (sk);u16 family;int err;
@@ -4937,13 +4936,17 @@ err_af:return -EAFNOSUPPORT ; } +static int selinux_socket_bind (struct socket *sock,struct sockaddr *address,int addrlen) +{ +return __selinux_socket_bind (sock->sk, address, addrlen); +} +/* This supports connect(2) and SCTP connect services such as sctp_connectx(3) * and sctp_sendmsg(3) as described in Documentation/security/SCTP.rst */ -static int selinux_socket_connect_helper (struct socket *sock, +static int selinux_socket_connect_helper (struct sock *sk,struct sockaddr *address,int addrlen) { -struct sock *sk = sock->sk;struct sk_security_struct *sksec =selinux_sock (sk);int err;
@@ -5036,7 +5039,7 @@ static int selinux_socket_connect(structint err;struct sock *sk = sock->sk; - err =selinux_socket_connect_helper (sock, address, addrlen); + err =selinux_socket_connect_helper (sk, address, addrlen);if (err)return err;
@@ -5538,13 +5541,11 @@ static int selinux_sctp_bind_connect(strint len, err =0 , walk_size =0 ;void *addr_buf;struct sockaddr *addr; -struct socket *sock;if (!selinux_policycap_extsockclass ())return 0 ;/* Process one or more addresses that may be IPv4 or IPv6 */ - sock = sk->sk_socket; addr_buf = address;while (walk_size < addrlen) {
@@ -5573,14 +5574,14 @@ static int selinux_sctp_bind_connect(strcase SCTP_PRIMARY_ADDR :case SCTP_SET_PEER_PRIMARY_ADDR :case SCTP_SOCKOPT_BINDX_ADD : - err =selinux_socket_bind (sock, addr, len); + err =__selinux_socket_bind (sk, addr, len);break ;/* Connect checks */ case SCTP_SOCKOPT_CONNECTX :case SCTP_PARAM_SET_PRIMARY :case SCTP_PARAM_ADD_IP :case SCTP_SENDMSG_CONNECT : - err =selinux_socket_connect_helper (sock, addr, len); + err =selinux_socket_connect_helper (sk, addr, len);if (err)return err;
Greg Kroah-Hartman
maintainerPATCH 873/1276 selinux: fix incorrect execmem checks on overlayfs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ondrej Mosnacek <[email protected]>
commit 9fe595fad54d4ac6a402edb3f60bec859d52cea6 upstream.
The commit fixing the overlayfs mmap() and mprotect() access checks failed to skip the execmem check in __file_map_prot_check() for the case where the "mounter check" is being performed. This check should be performed only against the credentials of the task that is calling mmap()/mprotect(), since it doesn't pertain to the file itself, but rather just gates the ability of the calling task to get an executable memory mapping in general.
The purpose of the "mounter check" is to guard against using an overlayfs mount to gain file access that would otherwise be denied to the mounter. For execmem this is not relevant, as there is no further file access granted based on it (notice that the file's context is not used as the target in the check), so checking it also against the mounter credentials would be incorrect.
Fix this by passing a boolean to [__]file_map_prot_check() and selinux_mmap_file_common() that indicates if we are doing the "mounter check" and skiping the execmem check in that case. Since this boolean also indicates if we use current_cred() or the mounter cred as the subject, also remove the "cred" argument from these functions and determine it based on the boolean and the file struct.
--- security/selinux/hooks.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
security/selinux/hooks.c +24 -18
@@ -3804,9 +3804,9 @@ static int selinux_file_ioctl_compat(strstatic int default_noexec__ro_after_init ; -static int __file_map_prot_check (const struct cred *cred, -const struct file *file,unsigned long prot, -bool shared,bool bf_user_file) +static int __file_map_prot_check (const struct file *file,unsigned long prot, +bool shared,bool mounter_check, +bool bf_user_file) {struct inode *inode =NULL ;bool prot_exec = prot &PROT_EXEC ;
@@ -3819,10 +3819,10 @@ static int __file_map_prot_check(const s inode =file_inode (file); } -if (default_noexec && prot_exec && +if (!mounter_check && default_noexec && prot_exec && (!file ||IS_PRIVATE (inode) || (!shared && prot_write))) {int rc; -u32 sid =cred_sid (cred); +u32 sid =current_sid ();/* * We are making executable an anonymous mapping or a private
@@ -3835,6 +3835,8 @@ static int __file_map_prot_check(const s }if (file) { +const struct cred *cred = mounter_check ? + file->f_cred :current_cred ();/* "read" always possible, "write" only if shared */ u32 av =FILE__READ ;if (shared && prot_write)
@@ -3848,11 +3850,11 @@ static int __file_map_prot_check(const sreturn 0 ; } -static inline int file_map_prot_check (const struct cred *cred, -const struct file *file, -unsigned long prot,bool shared) +static inline int file_map_prot_check (const struct file *file, +unsigned long prot,bool shared, +bool mounter_check) { -return __file_map_prot_check (cred, file, prot, shared, false); +return __file_map_prot_check (file, prot, shared, mounter_check, false); }static int selinux_mmap_addr (unsigned long addr)
@@ -3868,12 +3870,14 @@ static int selinux_mmap_addr(unsigned loreturn rc; } -static int selinux_mmap_file_common (const struct cred *cred,struct file *file, -unsigned long prot,bool shared) +static int selinux_mmap_file_common (struct file *file,unsigned long prot, +bool shared,bool mounter_check) {if (file) {int rc;struct common_audit_data ad; +const struct cred *cred = mounter_check ? + file->f_cred :current_cred (); ad.type =LSM_AUDIT_DATA_FILE ; ad.u.file = file;
@@ -3882,15 +3886,16 @@ static int selinux_mmap_file_common(consreturn rc; } -return file_map_prot_check (cred, file, prot, shared); +return file_map_prot_check (file, prot, shared, mounter_check); }static int selinux_mmap_file (struct file *file,unsigned long reqprot__always_unused ,unsigned long prot,unsigned long flags) { -return selinux_mmap_file_common (current_cred (), file, prot, - (flags &MAP_TYPE ) ==MAP_SHARED ); +return selinux_mmap_file_common (file, prot, + (flags &MAP_TYPE ) ==MAP_SHARED , + false); }/**
@@ -3922,8 +3927,9 @@ static int selinux_mmap_backing_file(strif (vma->vm_flags &VM_EXEC ) prot |=PROT_EXEC ; -return selinux_mmap_file_common (backing_file->f_cred, backing_file, - prot, vma->vm_flags &VM_SHARED ); +return selinux_mmap_file_common (backing_file, prot, + vma->vm_flags &VM_SHARED , + true); } static int selinux_file_mprotect(struct vm_area_struct *vma,
@@ -3984,11 +3990,11 @@ static int selinux_file_mprotect(struct } } - rc =__file_map_prot_check (cred, file, prot, shared, backing_file); + rc =__file_map_prot_check (file, prot, shared, false, backing_file);if (rc)return rc;if (backing_file) { - rc =file_map_prot_check (file->f_cred, file, prot, shared); + rc =file_map_prot_check (file, prot, shared, true);if (rc)return rc; }
Greg Kroah-Hartman
maintainerPATCH 874/1276 leds: uleds: Fix potential buffer overread
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Armin Wolf <[email protected]>
commit c19fe864f667afc49d1391d764e20b66555bcf7a upstream.
The name string supplied by userspace is not guaranteed to be null-terminated, so using strchr() on it might result in a buffer overread. The same thing will happen when said string is used by the LED class device.
Fix this by using strnchr() instead and explicitly check that the name string is properly null-terminated.
--- drivers/leds/uleds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/leds/uleds.c +2 -1
@@ -102,7 +102,8 @@ static ssize_t uleds_write(struct file * name = udev->user_dev.name;if (!name[0 ] || !strcmp (name,"." ) || !strcmp (name,".." ) || -strchr (name,'/' )) { +strnchr (name,sizeof (udev->user_dev.name),'/' ) || + !strnchr (name,sizeof (udev->user_dev.name),'\0' )) { ret = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 875/1276 mfd: sm501: Fix reference leak on failed device registration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 8c2f0b42fc252e1bf1c7746447091a468e784ca1 upstream.
When platform_device_register() fails in sm501_register_device(), the embedded struct device in pdev has already been initialized by device_initialize(), but the failure path only reports the error and returns without dropping the device reference for the current platform device:
sm501_register_device()
-> platform_device_register(pdev)
-> device_initialize(&pdev->dev)
-> setup_pdev_dma_masks(pdev)
-> platform_device_add(pdev)This leads to a reference leak when platform_device_register() fails. Fix this by calling platform_device_put() before returning the error.
The issue was identified by a static analysis tool I developed and confirmed by manual review.
--- drivers/mfd/sm501.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/sm501.c +3 -1
@@ -747,9 +747,11 @@ static int sm501_register_device(structif (ret >=0 ) {dev_dbg (sm->dev,"registered %s\n" , pdev->name);list_add_tail (&smdev->list, &sm->devices); - }else + }else {dev_err (sm->dev,"error registering %s (%d)\n" , pdev->name, ret); +platform_device_put (pdev); + }return ret; }
Greg Kroah-Hartman
maintainerPATCH 876/1276 tools/power/x86/intel-speed-select: Harden daemon pidfile open
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet MEMIS <[email protected]>
commit 607af438e6430893a822964c841a1994b33acccc upstream.
Avoid symlink-based pidfile clobbering by opening the pidfile with O_NOFOLLOW and validating it with fstat() before locking/writing.
The daemon currently uses a fixed pidfile path under /tmp. A local unprivileged user can pre-create a symlink at that path and cause a root-run daemon instance to write into an attacker-chosen file.
--- tools/power/x86/intel-speed-select/isst-daemon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/power/x86/intel-speed-select/isst-daemon.c +8 -1
@@ -148,6 +148,7 @@ static void daemonize(char *rundir, char {int pid, sid, i;char str[10 ]; +struct stat st;struct sigaction sig_actions;sigset_t sig_set;int ret;
@@ -200,11 +201,17 @@ static void daemonize(char *rundir, charif (ret ==-1 )exit (EXIT_FAILURE ); - pid_file_handle =open (pidfile,O_RDWR |O_CREAT ,0600 ); + pid_file_handle =open (pidfile,O_RDWR |O_CREAT |O_NOFOLLOW ,0600 );if (pid_file_handle ==-1 ) {/* Couldn't open lock file */ exit (1 ); } + +if (fstat (pid_file_handle, &st) ==-1 ) +exit (1 ); + +if (!S_ISREG (st.st_mode)) +exit (1 );/* Try to lock file */ #ifdef LOCKF_SUPPORT if (lockf (pid_file_handle,F_TLOCK ,0 ) ==-1 ) {
Greg Kroah-Hartman
maintainerPATCH 877/1276 x86/boot: Validate console=uart8250 baud rate to fix early boot hang
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit ffa0aa5b625fe0bed7463ac613f8b06676ff4542 upstream.
When the baud rate is empty, 0, invalid, or overflows to 0 when stored as an int, the system will hang during early boot because of a division by zero in early_serial_init().
Fall back to DEFAULT_BAUD when the resulting baud rate is 0 to prevent an early system hang.
--- arch/x86/boot/early_serial_console.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/boot/early_serial_console.c +7 -4
@@ -117,7 +117,7 @@ static unsigned int probe_baud(int port)static void parse_console_uart8250 (void ) {char optstr[64 ], *options; -int baud =DEFAULT_BAUD ; +int baud;int port =0 ;/*
@@ -136,10 +136,13 @@ static void parse_console_uart8250(void)else return ; -if (options && (options[0 ] ==',' )) - baud =simple_strtoull (options +1 , &options,0 ); -else +if (options && (options[0 ] ==',' )) { + baud =simple_strtoull (options +1 ,NULL ,0 ); +if (!baud) + baud =DEFAULT_BAUD ; + }else { baud =probe_baud (port); + }if (port)early_serial_init (port, baud);
Greg Kroah-Hartman
maintainerPATCH 878/1276 x86/boot: Reject too long acpi_rsdp= values
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit d130041a7b96f79cd4c7079a6c2431a6db4c9619 upstream.
cmdline_find_option() returns the full length of the parsed acpi_rsdp= value. get_cmdline_acpi_rsdp() then silently truncates values which do not fit in the val[] buffer.
Prevent boot_kstrtoul() from parsing a truncated value and then the kernel from silently using the wrong RSDP address, see discussion in Link:.
Issue a warning so that the user is aware that s/he supplied a malformed value and can get feedback instead of silent crashes.
[ bp: Make commit message more precise. ]
--- arch/x86/boot/compressed/acpi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/acpi.c +6 -1
@@ -184,10 +184,15 @@ static unsigned long get_cmdline_acpi_rschar val[MAX_ADDR_LEN ] = { };int ret; - ret =cmdline_find_option ("acpi_rsdp" , val,MAX_ADDR_LEN ); + ret =cmdline_find_option ("acpi_rsdp" , val,sizeof (val));if (ret <0 )return 0 ; +if (ret >=sizeof (val)) { +warn ("acpi_rsdp= value too long; ignoring" ); +return 0 ; + } +if (boot_kstrtoul (val,16 , &addr))return 0 ;#endif
Greg Kroah-Hartman
maintainerPATCH 879/1276 perf/x86/amd/lbr: Fix kernel address leakage
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sandipan Das <[email protected]>
commit 2a892294b83f541115c94b0bb637f39bef187657 upstream.
A user-only branch stack can contain branches that originate from the kernel. As a result, kernel addresses are exposed to user space even when PERF_SAMPLE_BRANCH_USER is requested. On AMD processors supporting X86_FEATURE_AMD_LBR_V2, perf can still report SYSRET/ERET entries for which the branch-from addresses are in the kernel.
E.g.
$ perf record -e cycles -o - -j any,save_type,u -- \
perf bench syscall basic --loop 1000 | \
perf script -i - -F brstack|tr ' ' '\n'| \
grep -E '0x[89a-f][0-9a-f]{15}' ...
0xffffffff81001268/0x717a90a38f1a/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a39157/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a2c628/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a41b60/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a260db/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a260db/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a8bef1c30/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a8e4d3c90/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH
...
The reason is that the hardware filter only considers the privilege level applicable to the branch target. Extend software filtering to also validate the branch-from addresses against br_sel, so that any branch record whose branch-from address is in the kernel is dropped when PERF_SAMPLE_BRANCH_USER is requested.
--- arch/x86/events/amd/lbr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/events/amd/lbr.c +2 -1
@@ -124,7 +124,8 @@ static void amd_pmu_lbr_filter(void) }/* If type does not correspond, then discard */ -if (type ==X86_BR_NONE || (br_sel & type) != type) { +if (type ==X86_BR_NONE || (br_sel & type) != type || + (!(br_sel &X86_BR_KERNEL ) &&kernel_ip (cpuc->lbr_entries[i].from))) { cpuc->lbr_entries[i].from =0 ;/* mark invalid */ compress = true; }
Greg Kroah-Hartman
maintainerPATCH 880/1276 cpufreq: intel_pstate: Set non-turbo capacity to HWP_GUARANTEED_PERF()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
commit 27d80e0f8b8dff97503fc0061754b1d3800cb961 upstream.
Setting cpu->capacity_perf to cpu->pstate.max_pstate_physical in the "no turbo" case is inconsistent with what happens elsewhere in the driver and causes arch_scale_cpu_capacity() to be incorrect. It also skews arch_scale_freq_capacity() which ends up differing from 1024 for the guaranteed P-state.
Address that by setting capacity_perf to HWP_GUARANTEED_PERF() in the "no turbo" case.
--- drivers/cpufreq/intel_pstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -2
@@ -964,12 +964,14 @@ static void hybrid_clear_cpu_capacity(unstatic void hybrid_get_capacity_perf (struct cpudata *cpu) { +u64 hwp_cap =READ_ONCE (cpu->hwp_cap_cached); +if (READ_ONCE (global.no_turbo)) { - cpu->capacity_perf = cpu->pstate.max_pstate_physical; + cpu->capacity_perf =HWP_GUARANTEED_PERF (hwp_cap);return ; } - cpu->capacity_perf =HWP_HIGHEST_PERF (READ_ONCE (cpu->hwp_cap_cached)); + cpu->capacity_perf =HWP_HIGHEST_PERF (hwp_cap); }static void hybrid_set_capacity_of_cpus (void )
Greg Kroah-Hartman
maintainerPATCH 881/1276 s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sumanth Korikkar <[email protected]>
commit 49145bce539117db4b6e9e83c0e5ef528e361050 upstream.
ev variable is userspace controlled via event->attr.config and used as an array index after bounds checking, but without speculation barriers.
Add the missing array_index_nospec() call to prevent speculative execution.
--- arch/s390/kernel/perf_cpum_cf.c | 3 +++ 1 file changed, 3 insertions(+)
arch/s390/kernel/perf_cpum_cf.c +3 -0
@@ -17,6 +17,7 @@#include <linux/export.h> #include <linux/miscdevice.h> #include <linux/perf_event.h> +#include <linux/nospec.h> #include <asm/cpu_mf.h> #include <asm/hwctrset.h>
@@ -770,6 +771,7 @@ static int __hw_perf_event_init(struct pif (!is_userspace_event (ev)) {if (ev >=ARRAY_SIZE (cpumf_generic_events_user))return -EOPNOTSUPP ; + ev =array_index_nospec (ev,ARRAY_SIZE (cpumf_generic_events_user)); ev = cpumf_generic_events_user[ev]; } }else if (!attr->exclude_kernel && attr->exclude_user) {
@@ -780,6 +782,7 @@ static int __hw_perf_event_init(struct pif (!is_userspace_event (ev)) {if (ev >=ARRAY_SIZE (cpumf_generic_events_basic))return -EOPNOTSUPP ; + ev =array_index_nospec (ev,ARRAY_SIZE (cpumf_generic_events_basic)); ev = cpumf_generic_events_basic[ev]; } }
Greg Kroah-Hartman
maintainerPATCH 882/1276 batman-adv: gw: acquire ethernet header only after skb realloc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 77880a3be88d378d60cc1e8f8ec70430e2ed0518 upstream.
The pskb_may_pull() called by batadv_get_vid() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
--- net/batman-adv/gateway_client.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/gateway_client.c +2 -1
@@ -693,12 +693,13 @@ bool batadv_gw_out_of_range(struct batadstruct batadv_gw_node *gw_node =NULL ;struct batadv_gw_node *curr_gw =NULL ;struct batadv_neigh_ifinfo *curr_ifinfo, *old_ifinfo; -struct ethhdr *ethhdr = (struct ethhdr *)skb->data; +struct ethhdr *ethhdr;bool out_of_range = false;u8 curr_tq_avg;unsigned short vid; vid =batadv_get_vid (skb,0 ); + ethhdr = (struct ethhdr *)skb->data;if (is_multicast_ether_addr (ethhdr->h_dest)) goto out;
Greg Kroah-Hartman
maintainerPATCH 883/1276 batman-adv: access unicast_ttvn skb->data only after skb realloc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 7141990add3f75436f2933cb310654cad3b1e3e9 upstream.
The pskb_may_pull() called by batadv_get_vid() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
This was done correctly for the ethernet header but missed for the unicast_packet pointer.
--- net/batman-adv/routing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/routing.c +1 -1
@@ -856,8 +856,8 @@ static bool batadv_check_unicast_ttvn(stif (skb_cow (skb,sizeof (*unicast_packet)) <0 )return false; - unicast_packet = (struct batadv_unicast_packet *)skb->data; vid =batadv_get_vid (skb, hdr_len); + unicast_packet = (struct batadv_unicast_packet *)skb->data; ethhdr = (struct ethhdr *)(skb->data + hdr_len);/* do not reroute multicast frames in a unicast header */
Greg Kroah-Hartman
maintainerPATCH 884/1276 batman-adv: dat: acquire ARP hw source only after skb realloc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 48067b2ae4504500a7093d9e1e16b42e70330480 upstream.
The pskb_may_pull() called by batadv_get_vid() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
--- net/batman-adv/distributed-arp-table.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/batman-adv/distributed-arp-table.c +4 -1
@@ -1757,6 +1757,7 @@ void batadv_dat_snoop_incoming_dhcp_ack(struct ethhdr *ethhdr;__be32 ip_src, yiaddr;unsigned short vid; +int hdr_size_tmp;__be16 proto;u8 *hw_src;
@@ -1773,8 +1774,10 @@ void batadv_dat_snoop_incoming_dhcp_ack(if (!batadv_dat_check_dhcp_ack (skb, proto, &ip_src, chaddr, &yiaddr))return ; + hdr_size_tmp = hdr_size; + vid =batadv_dat_get_vid (skb, &hdr_size_tmp); + ethhdr = (struct ethhdr *)(skb->data + hdr_size); hw_src = ethhdr->h_source; - vid =batadv_dat_get_vid (skb, &hdr_size);batadv_dat_entry_add (bat_priv, yiaddr, chaddr, vid);batadv_dat_entry_add (bat_priv, ip_src, hw_src, vid);
Greg Kroah-Hartman
maintainerPATCH 885/1276 batman-adv: bla: reacquire gw address after skb realloc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit cdf3b5af2bc4431e58629e8ad2086b1e9185c761 upstream.
The pskb_may_pull() called by batadv_bla_is_backbone_gw() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
--- net/batman-adv/routing.c | 1 + 1 file changed, 1 insertion(+)
net/batman-adv/routing.c +1 -0
@@ -1036,6 +1036,7 @@ int batadv_recv_unicast_packet(struct sk hdr_size);batadv_orig_node_put (orig_node_gw);if (is_gw) { + orig_addr_gw =eth_hdr (skb)->h_source;batadv_dbg (BATADV_DBG_BLA , bat_priv,"%s(): Dropped unicast pkt received from another backbone gw %pM.\n" , __func__, orig_addr_gw);
Greg Kroah-Hartman
maintainerPATCH 886/1276 batman-adv: dat: ensure accessible eth_hdr proto field
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 26560c4a03dc4d607331600c187f59ab2df5f341 upstream.
When batadv_get_vid() accesses the proto field of the ethernet header, it is not checking if the data itself is accessible. The caller is responsible for it. But in contrast to other call sites, batadv_dat_get_vid() and its caller didn't make sure this is true. This could have caused an out-of-bounds access.
--- net/batman-adv/distributed-arp-table.c | 23 +++++++++++++++++++++++ net/batman-adv/main.c | 3 +++ 2 files changed, 26 insertions(+)
net/batman-adv/distributed-arp-table.c +23 -0
@@ -1076,6 +1076,9 @@ out:* @skb: the buffer containing the packet to extract the VID from * @hdr_size: the size of the batman-adv header encapsulating the packet * +* The caller must ensure that at least @hdr_size + ETH_HLEN bytes are +* accessible after skb->data. +* * Return: If the packet embedded in the skb is vlan tagged this function * returns the VID with the BATADV_VLAN_HAS_TAG flag. Otherwise BATADV_NO_FLAGS * is returned.
@@ -1158,6 +1161,10 @@ bool batadv_dat_snoop_outgoing_arp_requeif (!atomic_read (&bat_priv->distributed_arp_table)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1253,6 +1260,10 @@ bool batadv_dat_snoop_incoming_arp_requeif (!atomic_read (&bat_priv->distributed_arp_table)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1315,6 +1326,10 @@ void batadv_dat_snoop_outgoing_arp_replyif (!atomic_read (&bat_priv->distributed_arp_table))return ; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) +return ; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1363,6 +1378,10 @@ bool batadv_dat_snoop_incoming_arp_replyif (!atomic_read (&bat_priv->distributed_arp_table)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1817,6 +1836,10 @@ bool batadv_dat_drop_broadcast_packet(stif (batadv_forw_packet_is_rebroadcast (forw_packet)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (forw_packet->skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (forw_packet->skb, &hdr_size); type =batadv_arp_get_type (bat_priv, forw_packet->skb, hdr_size);
net/batman-adv/main.c +3 -0
@@ -621,6 +621,9 @@ __be32 batadv_skb_crc32(struct sk_buff ** @skb: the buffer containing the packet * @header_len: length of the batman header preceding the ethernet header * +* The caller must ensure that at least @header_len + ETH_HLEN bytes are +* accessible after skb->data. +* * Return: VID with the BATADV_VLAN_HAS_TAG flag when the packet embedded in the * skb is vlan tagged. Otherwise BATADV_NO_FLAGS. */
Greg Kroah-Hartman
maintainerPATCH 887/1276 batman-adv: dat: fix tie-break for candidate selection
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 98052bdaf6ac1639a63ffc10244eeeab1f62ed2b upstream.
The original version of the candidate selection for DAT attempted to compare both candidate and max_orig_node to identify which has the smaller MAC address. This comparison is required as tie-break when a hash collision happened.
But the used function returned 0 when the function was not equal and a non-zero value when it was equal. As result, the actually selected node was dependent on the order of entries in the orig_hash and not actually on the mac addresses. The last originator in the hash collision would always win.
To have a proper ordering, it must diff the actual MAC address bytes and reject the candidate when the diff is not smaller than 0.
--- net/batman-adv/distributed-arp-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/distributed-arp-table.c +1 -1
@@ -546,7 +546,7 @@ static bool batadv_is_orig_node_eligible* the one with the lowest address */ if (tmp_max == max && max_orig_node && -batadv_compare_eth (candidate->orig, max_orig_node->orig)) +memcmp (candidate->orig, max_orig_node->orig,ETH_ALEN ) >=0 ) goto out; ret = true;
Greg Kroah-Hartman
maintainerPATCH 888/1276 batman-adv: tt: avoid request storms during pending request
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 27c7d40008231ae4140d35501b60087a9de2d2c3 upstream.
batadv_send_tt_request() allocates a tt_req_node when none exists for the destination originator node. This should prevent that a multiple TT requests are send at the same time to an originator.
But if allocation of the send buffer failed, this request must be cleaned up again. But indicator for such a failure is "ret == false". But the actual implementation is checking for "ret == true".
The check must be inverted to not loose the information about the TT request directly after it was attempted to be sent out. This should avoid potential request storms.
--- net/batman-adv/translation-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/translation-table.c +1 -1
@@ -3032,7 +3032,7 @@ static bool batadv_send_tt_request(struc out:batadv_hardif_put (primary_if); -if (ret && tt_req_node) { +if (!ret && tt_req_node) {spin_lock_bh (&bat_priv->tt.req_list_lock);if (!hlist_unhashed (&tt_req_node->list)) {hlist_del_init (&tt_req_node->list);
Greg Kroah-Hartman
maintainerPATCH 889/1276 batman-adv: fix VLAN priority offset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit fdb3be00ba4dafa313e699d6b5b90d13f22f3f25 upstream.
The batadv_skb_set_priority() receives an SKB with the inner ethernet header at position "offset". When it tries to extract the IPv4 and IPv6 header, it needs to skip the ethernet header to get access to the IP header.
But for VLAN header, it performs the access with the struct vlan_ethhdr. This struct contains both both the ethernet header and the VLAN header. It is therefore incorrect to skip over the whole vlan_ethhdr size to get access to the vlan_ethhdr.
--- net/batman-adv/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/main.c +1 -1
@@ -376,7 +376,7 @@ void batadv_skb_set_priority(struct sk_bswitch (ethhdr->h_proto) {case htons (ETH_P_8021Q ): - vhdr =skb_header_pointer (skb, offset +sizeof (*vhdr), + vhdr =skb_header_pointer (skb, offset,sizeof (*vhdr), &vhdr_tmp);if (!vhdr)return ;
Greg Kroah-Hartman
maintainerPATCH 890/1276 batman-adv: frag: free unfragmentable packet
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 6b628425aed49a1c7a4ffc997583840fc582d32b upstream.
The caller of batadv_frag_send_packet() assume that the skb provided to the function are always consumed. But the pre-check for an empty payload or the zero fragment size returned an error without any further actions.
A failed pre-check must use the same error handling code as the rest of the function.
--- net/batman-adv/fragmentation.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/batman-adv/fragmentation.c +4 -2
@@ -516,8 +516,10 @@ int batadv_frag_send_packet(struct sk_bu mtu = min_t(unsigned int, mtu, BATADV_FRAG_MAX_FRAG_SIZE); max_fragment_size = mtu - header_size; -if (skb->len ==0 || max_fragment_size ==0 ) -return -EINVAL ; +if (skb->len ==0 || max_fragment_size ==0 ) { + ret = -EINVAL ; + goto free_skb; + } num_fragments = (skb->len -1 ) / max_fragment_size +1 ; max_fragment_size = (skb->len -1 ) / num_fragments +1 ;
Greg Kroah-Hartman
maintainerPATCH 891/1276 batman-adv: frag: fix primary_if leak on failed linearization
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 353d2c1d5492e53ae34f490a84494124dc3d3531 upstream.
If the skb has a frag_list, it must be linearized before it can be split using skb_split(). But when this step failed, it must not only free the skb but also take care of the reference to the already found primary_if.
--- net/batman-adv/fragmentation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/fragmentation.c +1 -1
@@ -545,7 +545,7 @@ int batadv_frag_send_packet(struct sk_bu*/ if (skb_has_frag_list (skb) &&__skb_linearize (skb)) { ret = -ENOMEM ; - goto free_skb; + goto put_primary_if; }/* Create one header to be copied to all fragments */
Greg Kroah-Hartman
maintainerPATCH 892/1276 batman-adv: mcast: avoid OOB read of num_dests header
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 38eaed28e250895d56f4b7989bd65479a511c5c3 upstream.
Before the access to struct batadv_tvlv_mcast_tracker's num_dests, it is attempted to check whether enough space is actually in the network header. But instead of using offsetofend() to check for the whole size (2) which must be accessible, offsetof() of is called. The latter is always returning
0. The comparison with the network header length will always return that enough data is available - even when only 1 or 0 bytes are accessible.
Instead of using offsetofend(), use the more common check for the whole header.
--- net/batman-adv/multicast_forw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/batman-adv/multicast_forw.c +3 -4
@@ -927,11 +927,11 @@ static int batadv_mcast_forw_packet(stru {struct batadv_tvlv_mcast_tracker *mcast_tracker;struct batadv_neigh_node *neigh_node; -unsigned long offset, num_dests_off;struct sk_buff *nexthop_skb;unsigned char *skb_net_hdr;bool local_recv = false;unsigned int tvlv_len; +unsigned long offset;bool xmitted = false;u8 *dest, *next_dest;u16 num_dests;
@@ -940,9 +940,8 @@ static int batadv_mcast_forw_packet(stru/* (at least) TVLV part needs to be linearized */ SKB_LINEAR_ASSERT (skb); -/* check if num_dests is within skb length */ - num_dests_off = offsetof(struct batadv_tvlv_mcast_tracker , num_dests); -if (num_dests_off >skb_network_header_len (skb)) +/* check if batadv_tvlv_mcast_tracker header is within skb length */ +if (sizeof (*mcast_tracker) >skb_network_header_len (skb))return -EINVAL ; skb_net_hdr =skb_network_header (skb);
Greg Kroah-Hartman
maintainerPATCH 893/1276 batman-adv: tt: prevent TVLV OOB check overflow
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 7a581d9aaba8c82bd6177fa36b2588eea77f6e2b upstream.
A TT unicast TVLV contains the number of VLANs stored in it. This number is an u16 and gets multiplied by the size of the struct batadv_tvlv_tt_vlan_data (8 bytes). The size can therefore overflow the u16 used to store the tt_vlan_len. All additional safety checks to prevent out-of-bounds access of the TVLV buffer are invalid due to this overflow.
Using size_t prevents this overflow and ensures that the safety checks compare against the actual buffer requirements.
--- net/batman-adv/translation-table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/translation-table.c +2 -1
@@ -4101,7 +4101,8 @@ static int batadv_tt_tvlv_unicast_handle u16 tvlv_value_len) {struct batadv_tvlv_tt_data *tt_data; -u16 tt_vlan_len, tt_num_entries; +u16 tt_num_entries; +size_t tt_vlan_len;char tt_flag;bool ret;
Greg Kroah-Hartman
maintainerPATCH 894/1276 cifs: invalidate cfid on unlink/rename/rmdir
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shyam Prasad N <[email protected]>
commit f71d68d2b473e47db260c27c98212829590d8bae upstream.
Today we do not invalidate the cached_dirent or the entire parent cfid when a dentry in a dir has been removed/moved.
This change invalidates the parent cfid so that we don't serve directory contents from the cache.
--- fs/smb/client/inode.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
fs/smb/client/inode.c +29 -1
@@ -28,6 +28,23 @@#include "cached_dir.h" #include "reparse.h" +static void cifs_invalidate_cached_dir (struct cifs_tcon *tcon, +struct dentry *parent) +{ +struct cached_fid *parent_cfid =NULL ; + +if (!tcon || !parent) +return ; + +if (!open_cached_dir_by_dentry (tcon, parent, &parent_cfid)) { +mutex_lock (&parent_cfid->dirents.de_mutex); + parent_cfid->dirents.is_valid = false; + parent_cfid->dirents.is_failed = true; +mutex_unlock (&parent_cfid->dirents.de_mutex); +close_cached_dir (parent_cfid); + } +} +/* * Set parameters for the netfs library */
@@ -2026,6 +2043,9 @@ psx_del_no_retry:cifs_set_file_info (inode, attrs, xid, full_path, origattr); out_reval: +if (!rc && dentry->d_parent) +cifs_invalidate_cached_dir (tcon, dentry->d_parent); +if (inode) { cifs_inode =CIFS_I (inode); cifs_inode->time =0 ;/* will force revalidate to get info
@@ -2330,13 +2350,14 @@ int cifs_rmdir(struct inode *inode, stru } rc = server->ops->rmdir (xid, tcon, full_path, cifs_sb); -cifs_put_tlink (tlink);if (!rc) {spin_lock (&d_inode (direntry)->i_lock);i_size_write (d_inode (direntry),0 );clear_nlink (d_inode (direntry));spin_unlock (&d_inode (direntry)->i_lock); +if (direntry->d_parent) +cifs_invalidate_cached_dir (tcon, direntry->d_parent); } cifsInode =CIFS_I (d_inode (direntry));
@@ -2352,6 +2373,7 @@ int cifs_rmdir(struct inode *inode, struinode_set_ctime_current (d_inode (direntry));inode_set_mtime_to_ts (inode,inode_set_ctime_current (inode)); +cifs_put_tlink (tlink); rmdir_exit:free_dentry_path (page);
@@ -2576,6 +2598,12 @@ unlink_target: }/* force revalidate to go get info when needed */ +if (!rc) { +cifs_invalidate_cached_dir (tcon, source_dentry->d_parent); +if (target_dentry->d_parent != source_dentry->d_parent) +cifs_invalidate_cached_dir (tcon, target_dentry->d_parent); + } +CIFS_I (source_dir)->time =CIFS_I (target_dir)->time =0 ; cifs_rename_exit:
Greg Kroah-Hartman
maintainerPATCH 895/1276 mfd: tps6586x: Fix OF node refcount
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
commit 3001ed2b4e06da2276c42ace6551617065a5b1f9 upstream.
Platform devices created with platform_device_alloc() call platform_device_release() when the last reference to the device's kobject is dropped. This function calls of_node_put() unconditionally. This works fine for devices created with platform_device_register_full() but users of the split approach (platform_device_alloc() + platform_device_add()) must bump the reference of the of_node they assign manually. Add the missing call to of_node_get().
--- drivers/mfd/tps6586x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/tps6586x.c +1 -1
@@ -397,7 +397,7 @@ static int tps6586x_add_subdevs(struct t pdev->dev.parent = tps6586x->dev; pdev->dev.platform_data = subdev->platform_data; - pdev->dev.of_node = subdev->of_node; + pdev->dev.of_node =of_node_get (subdev->of_node); ret =platform_device_add (pdev);if (ret) {
Greg Kroah-Hartman
maintainerPATCH 896/1276 HID: playstation: validate num_touch_reports in DualShock 4 reports
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benoît Sevens <[email protected]>
commit 82a4fc46330910b4c1d9b189561439d468e3ff11 upstream.
The DualShock 4 HID driver fails to validate the num_touch_reports field received from the device in both USB and Bluetooth input reports. A malicious device could set this field to a value larger than the allocated size of the touch_reports array (3 for USB, 4 for Bluetooth), leading to an out-of-bounds read in dualshock4_parse_report().
This can result in kernel memory disclosure when processing malicious HID reports.
Validate num_touch_reports against the array size for the respective connection types before processing the touch data.
--- drivers/hid/hid-playstation.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/hid/hid-playstation.c +12 -0
@@ -2247,6 +2247,12 @@ static int dualshock4_parse_report(struc size == DS4_INPUT_REPORT_USB_SIZE) {struct dualshock4_input_report_usb *usb = (struct dualshock4_input_report_usb *)data; +if (usb->num_touch_reports >ARRAY_SIZE (usb->touch_reports)) { +hid_err (hdev,"DualShock4 USB input report has invalid num_touch_reports=%d\n" , + usb->num_touch_reports); +return -EINVAL ; + } + ds4_report = &usb->common; num_touch_reports =min_t (u8, usb->num_touch_reports,ARRAY_SIZE (usb->touch_reports));
@@ -2262,6 +2268,12 @@ static int dualshock4_parse_report(strucreturn -EILSEQ ; } +if (bt->num_touch_reports >ARRAY_SIZE (bt->touch_reports)) { +hid_err (hdev,"DualShock4 BT input report has invalid num_touch_reports=%d\n" , + bt->num_touch_reports); +return -EINVAL ; + } + ds4_report = &bt->common; num_touch_reports =min_t (u8, bt->num_touch_reports,ARRAY_SIZE (bt->touch_reports));
Greg Kroah-Hartman
maintainerPATCH 897/1276 Bluetooth: SCO: fix sleeping under spinlock in sco_conn_ready
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
commit b819db93d73f4593636299e229914052b89e3ef2 upstream.
sco_conn_ready calls sleeping functions under conn->lock spinlock.
The critical section can be reduced: conn->hcon is modified only with hdev->lock held. It is guaranteed to be held in sco_conn_ready, so conn->lock is not needed to guard it.
Move taking conn->lock after lock_sock(parent). This also follows the lock ordering lock_sock() > conn->lock elsewhere in the file.
--- net/bluetooth/sco.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
net/bluetooth/sco.c +9 -11
@@ -1317,26 +1317,24 @@ static void sco_conn_ready(struct sco_co sk->sk_state_change (sk);release_sock (sk); }else { -sco_conn_lock (conn); - -if (!conn->hcon) { -sco_conn_unlock (conn); +if (!conn->hcon)return ; - } + +lockdep_assert_held (&conn->hcon->hdev->lock); parent =sco_get_sock_listen (&conn->hcon->src); -if (!parent) { -sco_conn_unlock (conn); +if (!parent)return ; - }lock_sock (parent); +sco_conn_lock (conn); + sk =sco_sock_alloc (sock_net (parent),NULL ,BTPROTO_SCO ,GFP_ATOMIC ,0 );if (!sk) { -release_sock (parent);sco_conn_unlock (conn); +release_sock (parent);return ; }
@@ -1356,9 +1354,9 @@ static void sco_conn_ready(struct sco_co/* Wake up parent */ parent->sk_data_ready (parent); -release_sock (parent); -sco_conn_unlock (conn); + +release_sock (parent); } }
Greg Kroah-Hartman
maintainerPATCH 898/1276 Bluetooth: SCO: hold sk properly in sco_conn_ready
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
commit 4e37f6452d586b95c346a9abdd2fb80b67794f39 upstream.
sk deref in sco_conn_ready must be done either under conn->lock, or holding a refcount, to avoid concurrent close. conn->sk and parent sk is currently accessed without either, and without checking parent->sk_state:
[Task 1] [Task 2]
sco_sock_release
sco_conn_ready
sk = conn->sk
lock_sock(sk)
conn->sk = NULL
lock_sock(sk)
release_sock(sk)
sco_sock_kill(sk)
UAF on sk deref
and similarly for access to sco_get_sock_listen() return value.
Fix possible UAF by holding sk refcount in sco_conn_ready() and making sco_get_sock_listen() increase refcount. Also recheck after lock_sock that the socket is still valid. Adjust conn->sk locking so it's protected also by lock_sock() of the associated socket if any.
--- net/bluetooth/sco.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-)
net/bluetooth/sco.c +32 -12
@@ -410,9 +410,13 @@ static struct sock *sco_get_sock_listen( sk1 = sk; } + sk = sk ? sk : sk1; +if (sk) +sock_hold (sk); +read_unlock (&sco_sk_list.lock); -return sk ? sk : sk1; +return sk; }static void sco_sock_destruct (struct sock *sk)
@@ -452,11 +456,13 @@ static void sco_sock_kill(struct sock *sBT_DBG ("sk %p state %d" , sk, sk->sk_state);/* Sock is dead, so set conn->sk to NULL to avoid possible UAF */ +lock_sock (sk);if (sco_pi (sk)->conn) {sco_conn_lock (sco_pi (sk)->conn);sco_pi (sk)->conn->sk =NULL ;sco_conn_unlock (sco_pi (sk)->conn); } +release_sock (sk);/* Kill poor orphan */ bt_sock_unlink (&sco_sk_list, sk);
@@ -1305,17 +1311,28 @@ static int sco_sock_release(struct sockestatic void sco_conn_ready (struct sco_conn *conn) { -struct sock *parent; -struct sock *sk = conn->sk; +struct sock *parent, *sk; + +sco_conn_lock (conn); + sk =sco_sock_hold (conn); +sco_conn_unlock (conn);BT_DBG ("conn %p" , conn);if (sk) {lock_sock (sk); -sco_sock_clear_timer (sk); - sk->sk_state =BT_CONNECTED ; - sk->sk_state_change (sk); + +/* conn->sk may have become NULL if racing with sk close, but +* due to held hdev->lock, it can't become different sk. +*/ +if (conn->sk) { +sco_sock_clear_timer (sk); + sk->sk_state =BT_CONNECTED ; + sk->sk_state_change (sk); + } +release_sock (sk); +sock_put (sk); }else {if (!conn->hcon)return ;
@@ -1330,13 +1347,15 @@ static void sco_conn_ready(struct sco_cosco_conn_lock (conn); +/* hdev->lock guarantees conn->sk == NULL still here */ + +if (parent->sk_state !=BT_LISTEN ) + goto release; + sk =sco_sock_alloc (sock_net (parent),NULL ,BTPROTO_SCO ,GFP_ATOMIC ,0 ); -if (!sk) { -sco_conn_unlock (conn); -release_sock (parent); -return ; - } +if (!sk) + goto release;sco_sock_init (sk, parent);
@@ -1354,9 +1373,10 @@ static void sco_conn_ready(struct sco_co/* Wake up parent */ parent->sk_data_ready (parent); +release:sco_conn_unlock (conn); -release_sock (parent); +sock_put (parent); } }
Greg Kroah-Hartman
maintainerPATCH 899/1276 jbd2: fix integer underflow in jbd2_journal_initialize_fast_commit()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
commit 289a2ca0c9b7eae74f93fc213b0b971669b8683d upstream.
jbd2_journal_initialize_fast_commit() validates journal capacity by checking (journal->j_last - num_fc_blks < JBD2_MIN_JOURNAL_BLOCKS). Both j_last and num_fc_blks are unsigned, so when num_fc_blks exceeds j_last the subtraction wraps to a large value, bypassing the bounds check.
The resulting underflow corrupts j_last, j_fc_first, and j_free, leading to journal abort.
Fix by checking num_fc_blks against j_last before the subtraction, returning -EFSCORRUPTED.
--- fs/jbd2/journal.c | 2 ++ 1 file changed, 2 insertions(+)
fs/jbd2/journal.c +2 -0
@@ -2273,6 +2273,8 @@ jbd2_journal_initialize_fast_commit(jourunsigned long long num_fc_blks; num_fc_blks =jbd2_journal_get_num_fc_blks (sb); +if (num_fc_blks > journal->j_last) +return -EFSCORRUPTED ;if (journal->j_last - num_fc_blks <JBD2_MIN_JOURNAL_BLOCKS )return -ENOSPC ;
Greg Kroah-Hartman
maintainerPATCH 900/1276 nvdimm/btt: Free arenas on btt_init() error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 1a6b6442a982d0ca5fb6a1a39b6f6dfd760eda57 upstream.
The arenas allocated by discover_arenas() or create_arenas() are not freed on some error paths in btt_init(). This leaks memory when BTT initialization fails.
Call free_arenas() from the affected error paths to release the allocations.
[ as: commit message and log edits ]
--- drivers/nvdimm/btt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/nvdimm/btt.c +7 -4
@@ -1589,7 +1589,7 @@ static struct btt *btt_init(struct nd_btif (btt->init_state !=INIT_READY && nd_region->ro) {dev_warn (dev,"%s is read-only, unable to init btt metadata\n" ,dev_name (&nd_region->dev)); -return NULL ; + goto err; }else if (btt->init_state !=INIT_READY ) { btt->num_arenas = (rawsize /ARENA_MAX_SIZE ) + ((rawsize %ARENA_MAX_SIZE ) ?1 :0 );
@@ -1599,25 +1599,28 @@ static struct btt *btt_init(struct nd_bt ret =create_arenas (btt);if (ret) {dev_info (dev,"init: create_arenas: %d\n" , ret); -return NULL ; + goto err; } ret =btt_meta_init (btt);if (ret) {dev_err (dev,"init: error in meta_init: %d\n" , ret); -return NULL ; + goto err; } } ret =btt_blk_init (btt);if (ret) {dev_err (dev,"init: error in blk_init: %d\n" , ret); -return NULL ; + goto err; }btt_debugfs_init (btt);return btt; +err: +free_arenas (btt); +return NULL ; }/**
Greg Kroah-Hartman
maintainerPATCH 901/1276 nvdimm/btt: Free arena sub-allocations on discover_arenas() error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 13fe4cd9ddd0aacb7777812328be525a11ea3fea upstream.
Memory allocated by btt_freelist_init(), btt_rtt_init(), and btt_maplocks_init() is not freed on some discover_arenas() error paths. This leaks memory when arena discovery fails.
Add the missing kfree() calls to release the allocations before returning an error.
[ as: commit message and log edits ]
--- drivers/nvdimm/btt.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nvdimm/btt.c +3 -0
@@ -921,6 +921,9 @@ static int discover_arenas(struct btt *breturn ret; out: +kfree (arena->freelist); +kfree (arena->rtt); +kfree (arena->map_locks);kfree (arena);free_arenas (btt);return ret;
Greg Kroah-Hartman
maintainerPATCH 902/1276 sunrpc: pin svc_xprt across the asynchronous TLS handshake callback
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
commit 4f988f3a2808fb659f3880c282041ff067acad78 upstream.
svc_tcp_handshake() stores the raw svc_xprt pointer in tls_handshake_args.ta_data and submits the request through tls_server_hello_x509(). The handshake core takes only sock_hold(req->hr_sk); nothing references the embedding struct svc_sock that svc_tcp_handshake_done() reaches via container_of().
Two close races leave the in-flight callback writing through a freed svc_sock. svc_sock_free() calls tls_handshake_cancel() and discards its return value: a false return means handshake_complete() has already set HANDSHAKE_F_REQ_COMPLETED but hp_done() may not have finished, yet svc_sock_free() proceeds to kfree(svsk). The cancel-loser fall-through inside svc_tcp_handshake() itself produces the same window: when wait_for_completion_interruptible_timeout() returns <= 0 (timeout or signal) and tls_handshake_cancel() returns false, the function does not drain, returns, and svc_handle_xprt() calls svc_xprt_received(), which clears XPT_BUSY and can drop the last reference. A concurrent close then runs svc_sock_free() while svc_tcp_handshake_done() is still updating xpt_flags and walking svsk->sk_handshake_done.
The corruption surfaces as set_bit/clear_bit RMW into the freed xpt_flags slab slot and as complete_all() walking and writing the freed wait_queue_head_t list embedded in sk_handshake_done -- a slab-corruption primitive, not a benign read. The path is reachable on any TLS-enabled NFS server whenever a connection close overlaps the tlshd downcall delivery window; the interruptible wait means signal delivery suffices, not just SVC_HANDSHAKE_TO expiry.
Take svc_xprt_get(xprt) immediately before tls_server_hello_x509() so the in-flight callback owns its own reference. Release it on the two edges where the callback is guaranteed not to fire -- submission failure from tls_server_hello_x509() and a successful tls_handshake_cancel() -- and at the tail of svc_tcp_handshake_done() after complete_all().
--- net/sunrpc/svcsock.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/sunrpc/svcsock.c +6 -0
@@ -462,6 +462,7 @@ static void svc_tcp_handshake_done(void }clear_bit (XPT_HANDSHAKE , &xprt->xpt_flags);complete_all (&svsk->sk_handshake_done); +svc_xprt_put (xprt); }/**
@@ -485,9 +486,13 @@ static void svc_tcp_handshake(struct svcclear_bit (XPT_TLS_SESSION , &xprt->xpt_flags);init_completion (&svsk->sk_handshake_done); +/* Pin the transport across the asynchronous handshake callback. */ +svc_xprt_get (xprt); + ret =tls_server_hello_x509 (&args,GFP_KERNEL );if (ret) {trace_svc_tls_not_started (xprt); +svc_xprt_put (xprt); goto out_failed; }
@@ -496,6 +501,7 @@ static void svc_tcp_handshake(struct svcif (ret <=0 ) {if (tls_handshake_cancel (sk)) {trace_svc_tls_timed_out (xprt); +svc_xprt_put (xprt); goto out_close; } }
Greg Kroah-Hartman
maintainerPATCH 903/1276 sunrpc: wait for in-flight TLS handshake callback when cancel loses race
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit d00e32f84ca1a77cb67a3fbf59f58dada95f5a21 upstream.
When wait_for_completion_interruptible_timeout() in svc_tcp_handshake() returns 0 (timeout) or -ERESTARTSYS (signal) and tls_handshake_cancel() then returns false, handshake_complete() has won the cancellation race: it has set HANDSHAKE_F_REQ_COMPLETED and is about to invoke svc_tcp_handshake_done(), but the callback's side effects on xpt_flags and on svsk->sk_handshake_done have not yet committed.
The current code reads xpt_flags immediately to decide whether the session succeeded. Two races result.
If the callback has executed set_bit(XPT_TLS_SESSION) but not yet clear_bit(XPT_HANDSHAKE), svc_tcp_handshake() sees a session, enqueues the transport, and returns. svc_xprt_received() then clears XPT_BUSY, a worker thread picks the transport up, the dispatcher in svc_handle_xprt() observes XPT_HANDSHAKE still set, and xpo_handshake is invoked a second time. That svc_tcp_handshake() calls init_completion(&svsk->sk_handshake_done) while the original callback concurrently calls complete_all() on it, corrupting the embedded swait_queue.
If the callback has set HANDSHAKE_F_REQ_COMPLETED but not yet entered svc_tcp_handshake_done(), svc_tcp_handshake() reads XPT_TLS_SESSION as clear and tears the connection down even though the handshake is about to succeed.
Wait for the callback to commit before inspecting xpt_flags. The completion is guaranteed to fire because handshake_complete() invokes svc_tcp_handshake_done() unconditionally once it has set HANDSHAKE_F_REQ_COMPLETED.
--- net/sunrpc/svcsock.c | 4 ++++ 1 file changed, 4 insertions(+)
net/sunrpc/svcsock.c +4 -0
@@ -504,6 +504,10 @@ static void svc_tcp_handshake(struct svcsvc_xprt_put (xprt); goto out_close; } +/* Cancellation lost to handshake_complete(): the +* callback is in flight and should finish quickly. +*/ +wait_for_completion (&svsk->sk_handshake_done); }if (!test_bit (XPT_TLS_SESSION , &xprt->xpt_flags)) {
Greg Kroah-Hartman
maintainerPATCH 904/1276 lockd: Plug nlm_file leak when nlm_do_fopen() fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit f16a1513452edb532fec81e591c64c320866719c upstream.
A client can repeatedly drive nlm_do_fopen() failures by presenting file handles that the underlying export rejects. After kzalloc_obj() succeeds in nlm_lookup_file(), the freshly allocated nlm_file is not yet inserted into nlm_files[]. The nlm_do_fopen() failure path jumps to out_unlock, which releases nlm_file_mutex and returns without freeing the allocation, so each failure leaks one nlm_file.
Route the failure through out_free so kfree() runs before the function returns.
--- fs/lockd/svcsubs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svcsubs.c +1 -1
@@ -139,7 +139,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, nfserr =nlm_do_fopen (rqstp, file, mode);if (nfserr) - goto out_unlock; + goto out_free;hlist_add_head (&file->f_list, &nlm_files[hash]);
Greg Kroah-Hartman
maintainerPATCH 905/1276 lockd: Plug nlm_file refcount leak on cached nlm_do_fopen() failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit 70a38f87bed7f0694fd07988b47b2db1e10d8df3 upstream.
The cached-file path in nlm_lookup_file() reaches the found: label unconditionally, even when nlm_do_fopen() fails. At that label *result and file->f_count are updated before the error is returned. The wrappers nlm3svc_lookup_file() and nlm4svc_lookup_file() then bail out of their switch without copying *result back to their caller, so the proc handler's local nlm_file pointer remains NULL and the cleanup path skips nlm_release_file(). The f_count increment is never released, and nlm_traverse_files() can no longer reap the file because its refcount never returns to zero between requests.
Short-circuit the cached path so neither *result nor f_count is touched when nlm_do_fopen() fails on a hashed nlm_file.
--- fs/lockd/svcsubs.c | 2 ++ 1 file changed, 2 insertions(+)
fs/lockd/svcsubs.c +2 -0
@@ -123,6 +123,8 @@ nlm_lookup_file(struct svc_rqst *rqstp,mutex_lock (&file->f_mutex); nfserr =nlm_do_fopen (rqstp, file, mode);mutex_unlock (&file->f_mutex); +if (nfserr) + goto out_unlock; goto found; }nlm_debug_print_fh ("creating file for" , &lock->fh);
Greg Kroah-Hartman
maintainerPATCH 906/1276 SUNRPC: Bound-check xdr_buf_to_bvec() stores before writing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit 42f5b80dda6b86e424054baf1475df686c403d5c upstream.
xdr_buf_to_bvec() writes a bio_vec into the caller's array before testing whether that slot is in range, and the head branch performs the store with no check at all. When the caller's budget is exactly used up, the next store lands one element past the end of the array. The overflow label returns count - 1, which masks the surplus store but cannot undo it.
rq_bvec, the array passed by nfsd_vfs_write(), is allocated to exactly rq_maxpages entries with no slack. The OOB store can land in adjacent slab memory; the bv_len and bv_offset fields written there are derived from client-supplied RPC payload sizes.
Move the in-range check ahead of the store in the head, page-loop, and tail branches. With the check at the top of each sequence, count is incremented only after a successful store, so the overflow label can return count directly.
--- net/sunrpc/xdr.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
net/sunrpc/xdr.c +9 -5
@@ -180,6 +180,8 @@ unsigned int xdr_buf_to_bvec(struct bio_unsigned int count =0 ;if (head->iov_len) { +if (unlikely (count >= bvec_size)) + goto bvec_overflow;bvec_set_virt (bvec++, head->iov_base, head->iov_len); ++count; }
@@ -193,25 +195,27 @@ unsigned int xdr_buf_to_bvec(struct bio_while (remaining >0 ) { len = min_t(unsigned int, remaining,PAGE_SIZE - offset); +if (unlikely (count >= bvec_size)) + goto bvec_overflow;bvec_set_page (bvec++, *pages++, len, offset); remaining -= len; offset =0 ; -if (unlikely (++count > bvec_size)) - goto bvec_overflow; + ++count; } }if (tail->iov_len) { -bvec_set_virt (bvec, tail->iov_base, tail->iov_len); -if (unlikely (++count > bvec_size)) +if (unlikely (count >= bvec_size)) goto bvec_overflow; +bvec_set_virt (bvec, tail->iov_base, tail->iov_len); + ++count; }return count; bvec_overflow:pr_warn_once ("%s: bio_vec array overflow\n" , __func__); -return count -1 ; +return count; }/**
Greg Kroah-Hartman
maintainerPATCH 907/1276 remoteproc: qcom: Fix leak when custom dump_segments addition fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wasim Nazir <[email protected]>
commit ecf9fc18e62c58eae1ceb65dab2bccb8a724de2d upstream.
Free allocated minidump_region 'name' in qcom_add_minidump_segments() when failing before adding the region to 'dump_segments'. Otherwise, the 'name' is not tracked and is never freed by qcom_minidump_cleanup().
Return error when adding to 'dump_segments' fails.
--- drivers/remoteproc/qcom_common.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/remoteproc/qcom_common.c +10 -4
@@ -110,6 +110,7 @@ static int qcom_add_minidump_segments(ststruct minidump_region __iomem *ptr;struct minidump_region region;int seg_cnt, i; +int ret =0 ;dma_addr_t da;size_t size;char *name;
@@ -130,17 +131,22 @@ static int qcom_add_minidump_segments(stif (le32_to_cpu (region.valid) ==MINIDUMP_REGION_VALID ) { name =kstrndup (region.name,MAX_REGION_NAME_LENGTH -1 ,GFP_KERNEL );if (!name) { -iounmap (ptr); -return -ENOMEM ; + ret = -ENOMEM ; +break ; } da =le64_to_cpu (region.address); size =le64_to_cpu (region.size); -rproc_coredump_add_custom_segment (rproc, da, size, rproc_dumpfn_t, name); + ret =rproc_coredump_add_custom_segment (rproc, da, size, rproc_dumpfn_t, + name); +if (ret) { +kfree (name); +break ; + } } }iounmap (ptr); -return 0 ; +return ret; } void qcom_minidump(struct rproc *rproc, unsigned int minidump_id,
Greg Kroah-Hartman
maintainerPATCH 908/1276 MIPS: ip22-gio: fix gio device memory leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 7de9a1b45f5a95b58145653c525c8fb80292d9ab upstream.
The gio device release callback was never wired up so gio devices are not freed when the last reference is dropped.
--- arch/mips/sgi-ip22/ip22-gio.c | 2 ++ 1 file changed, 2 insertions(+)
arch/mips/sgi-ip22/ip22-gio.c +2 -0
@@ -101,6 +101,8 @@ int gio_device_register(struct gio_devic { giodev->dev.bus = &gio_bus_type; giodev->dev.parent = &gio_bus; + giodev->dev.release = gio_release_dev; +return device_register (&giodev->dev); }EXPORT_SYMBOL_GPL (gio_device_register);
Greg Kroah-Hartman
maintainerPATCH 909/1276 MIPS: ip22-gio: fix kfree() of static object
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit c62cdd3e919bdf84c37ec46810f87cdb1736e822 upstream.
The gio bus root device is a statically allocated object which must not be freed by kfree() on failure to register the device or bus.
--- arch/mips/sgi-ip22/ip22-gio.c | 1 - 1 file changed, 1 deletion(-)
arch/mips/sgi-ip22/ip22-gio.c +0 -1
@@ -30,7 +30,6 @@ static struct {static void gio_bus_release (struct device *dev) { -kfree (dev); }static struct device gio_bus = {
Greg Kroah-Hartman
maintainerPATCH 910/1276 MIPS: ip22-gio: fix device reference leak in probe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit b82930a4c5dbc5c4df39c0f93d968c239f2c6885 upstream.
The gio probe function needlessly takes a device reference which is never released and therefore prevents unbound gio devices from being freed.
--- arch/mips/sgi-ip22/ip22-gio.c | 4 ---- 1 file changed, 4 deletions(-)
arch/mips/sgi-ip22/ip22-gio.c +0 -4
@@ -133,13 +133,9 @@ static int gio_device_probe(struct devicif (!drv->probe)return error; -gio_dev_get (gio_dev); - match =gio_match_device (drv->id_table, gio_dev);if (match) error = drv->probe (gio_dev, match); -if (error) -gio_dev_put (gio_dev);return error; }
Greg Kroah-Hartman
maintainerPATCH 911/1276 MIPS: DEC: Ensure 32-bit stack location for o32 prom_printf()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej W. Rozycki <[email protected]>
commit 5ff79e8bdc75db51e30298a75939e2308e7658e0 upstream.
In 64-bit configurations calling any firmware entry points from a kernel thread other than the initial one will result in a situation where the stack has been placed in the XKPHYS 64-bit memory segment.
Consequently the stack pointer is no longer a 32-bit value and when the 32-bit firmware code called uses 32-bit ALU operations to manipulate the stack pointer, the calculated result is incorrect (in fact in the 64-bit MIPS ISA almost all 32-bit ALU operations will produce an unpredictable result when executed on 64-bit data) and control goes astray.
This may happen when no final console driver has been enabled in the configuration and consequently the initial console continues being used late into bootstrap, or with an upcoming change that will switch the zs driver to use a platform device, which in turn will make the console handover happen only after other kernel threads have already been started, and the kernel will hang at:
pid_max: default: 32768 minimum: 301
or somewhat later, but always before:
cblist_init_generic: Setting adjustable number of callback queues.
has been printed.
It seems that only the prom_printf() entry point is affected. Of all the other entry points wired only rex_slot_address() and rex_gettcinfo() are called from a kernel thread other than the initial one, specifically kernel_init(), and they are leaf functions that do no business with the stack, having worked with no issue ever since 64-bit support was added for the platform back in 2002.
To address this issue then, arrange for the stack to be switched in the o32 wrapper as required for prom_printf() only, by supplying call_o32() with a pointer to a chunk of initdata space, which is placed in the CKSEG0 32-bit compatibility segment, observing that prom_printf() is only called from console output handler and therefore with the console lock held, implying no need for this code to be reentrant.
Other firmware entry points may be called with interrupts enabled and no lock held, and may therefore require that call_o32() be reentrant. They trigger no issue at this point and "if it ain't broke, don't fix it," so just leave them alone.
--- arch/mips/dec/prom/init.c | 6 +++++- arch/mips/include/asm/dec/prom.h | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-)
arch/mips/dec/prom/init.c +5 -1
@@ -3,7 +3,7 @@* init.c: PROM library initialisation code. * * Copyright (C) 1998 Harald Koerfgen -* Copyright (C) 2002, 2004 Maciej W. Rozycki +* Copyright (C) 2002, 2004, 2026 Maciej W. Rozycki */ #include <linux/init.h> #include <linux/kernel.h>
@@ -20,6 +20,10 @@#include <asm/dec/prom.h> +#ifdef CONFIG_64BIT +unsigned long o32_stk[O32_STK_SIZE ]__initdata = {0 }; +#endif +int (*__rex_bootinit)(void );int (*__rex_bootread)(void );int (*__rex_getbitmap)(memmap *);
arch/mips/include/asm/dec/prom.h +13 -2
@@ -4,7 +4,7 @@* * DECstation PROM interface. * -* Copyright (C) 2002 Maciej W. Rozycki +* Copyright (C) 2002, 2026 Maciej W. Rozycki * * Based on arch/mips/dec/prom/prom.h by the Anonymous. */
@@ -97,6 +97,17 @@ extern int (*__pmax_close)(int);#ifdef CONFIG_64BIT +#define O32_STK_SIZE 512 +extern unsigned long o32_stk[]; + +/* Switch the stack if outside the 32-bit address space. */ +static inline unsigned long *o32_get_stk (void ) +{ +long fp = (long )__builtin_frame_address (0 ); + +return fp != (int )fp ? o32_stk +O32_STK_SIZE :NULL ; +} +/* * On MIPS64 we have to call PROM functions via a helper * dispatcher to accommodate ABI incompatibilities.
@@ -128,7 +139,7 @@ int __DEC_PROM_O32(_prom_printf, (int (*#define prom_getchar () _prom_getchar(__prom_getchar, NULL)#define prom_getenv (x) _prom_getenv(__prom_getenv, NULL, x) -#define prom_printf(x...) _prom_printf(__prom_printf, NULL, x) +#define prom_printf(x...) _prom_printf(__prom_printf, o32_get_stk(), x)#else /* !CONFIG_64BIT */
Greg Kroah-Hartman
maintainerPATCH 912/1276 power: supply: cpcap-battery: Fix missing nvmem_device_put() causing reference leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Ke <[email protected]>
commit a2c14ff63e0e02e3c832385e523e9cc81301171c upstream.
In cpcap_battery_detect_battery_type(), the reference to an nvmem device obtained via nvmem_device_find() is not released with nvmem_device_put() on the success or read-failure paths, causing a permanent reference leak. The driver’s retry logic on subsequent battery property reads can compound this leak, preventing the nvmem device from ever being freed.
Found by code review.
--- drivers/power/supply/cpcap-battery.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/power/supply/cpcap-battery.c +7 -4
@@ -415,10 +415,13 @@ static void cpcap_battery_detect_batteryif (IS_ERR_OR_NULL (nvmem)) { ddata->check_nvmem = true;dev_info_once (ddata->dev,"Can not find battery nvmem device. Assuming generic lipo battery\n" ); - }else if (nvmem_device_read (nvmem,2 ,1 , &battery_id) <0 ) { - battery_id =0 ; - ddata->check_nvmem = true; -dev_warn (ddata->dev,"Can not read battery nvmem device. Assuming generic lipo battery\n" ); + }else { +if (nvmem_device_read (nvmem,2 ,1 , &battery_id) <0 ) { + battery_id =0 ; + ddata->check_nvmem = true; +dev_warn (ddata->dev,"Can not read battery nvmem device. Assuming generic lipo battery\n" ); + } +nvmem_device_put (nvmem); }switch (battery_id) {
Greg Kroah-Hartman
maintainerPATCH 913/1276 mm/memory_hotplug: fix incorrect altmap passing in error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit 2fac4afa0e2e68841334c78c1821e49f74fbc66a upstream.
In create_altmaps_and_memory_blocks(), when arch_add_memory() succeeds with memmap_on_memory enabled, the vmemmap pages are allocated from params.altmap. If create_memory_block_devices() subsequently fails, the error path calls arch_remove_memory() with a NULL altmap instead of params.altmap.
This is a bug that could lead to memory corruption. Since altmap is NULL, vmemmap_free() falls back to freeing the vmemmap pages into the system buddy allocator via free_pages() instead of the altmap. arch_remove_memory() then immediately destroys the physical linear mapping for this memory. This injects unowned pages into the buddy allocator, causing machine checks or memory corruption if the system later attempts to allocate and use those freed pages.
Fix this by passing params.altmap to arch_remove_memory() in the error path.
--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c +1 -1
@@ -1456,7 +1456,7 @@ static int create_altmaps_and_memory_blo ret =create_memory_block_devices (cur_start, memblock_size, params.altmap, group);if (ret) { -arch_remove_memory (cur_start, memblock_size,NULL ); +arch_remove_memory (cur_start, memblock_size, params.altmap);kfree (params.altmap); goto out; }
Greg Kroah-Hartman
maintainerPATCH 914/1276 mm/damon/core: make charge_addr_from aware of end-address exclusivity
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit 5a2d162e22bf33eb89d53e802d0fc1ec422e19b6 upstream.
DAMON region end address is exclusive one, but charge_addr_from is assigned assuming the end address is inclusive. As a result, DAMOS action to next up to min_region_sz memory can be skipped. This is quite negligible user impact. But, the bug is a bug that can be very simply fixed. Fix the wrong assignment to respect the exclusiveness of the address.
The issue was discovered [1] by Sashiko.
--- mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/core.c +1 -1
@@ -1435,7 +1435,7 @@ static void damos_apply_scheme(struct da quota->charged_sz += sz;if (quota->esz && quota->charged_sz >= quota->esz) { quota->charge_target_from = t; - quota->charge_addr_from = r->ar.end +1 ; + quota->charge_addr_from = r->ar.end; } }if (s->action !=DAMOS_STAT )
Greg Kroah-Hartman
maintainerPATCH 915/1276 fs/ntfs3: fix syncing wrong inode on DIRSYNC cross-directory rename
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
commit 932fa0c1496286e39e14e27194c1ee7c2181629f upstream.
In ntfs3_rename(), when IS_DIRSYNC(new_dir) is true, the code syncs the renamed file inode instead of the target directory new_dir:
if (IS_DIRSYNC(new_dir))
ntfs_sync_inode(inode); /* should be new_dir */
DIRSYNC requires that directory metadata changes are written to disk synchronously. Since new_dir was modified (a new directory entry was added), it is new_dir that must be synced to satisfy the guarantee, not the renamed file itself.
This bug has existed since the initial ntfs3 implementation and was carried through the refactoring in commit 78ab59fee07f ("fs/ntfs3: Rework file operations").
Fix by syncing new_dir instead of inode.
--- fs/ntfs3/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/namei.c +1 -1
@@ -324,7 +324,7 @@ static int ntfs_rename(struct mnt_idmapntfs_sync_inode (dir);if (IS_DIRSYNC (new_dir)) -ntfs_sync_inode (inode); +ntfs_sync_inode (new_dir); }if (dir_ni != new_dir_ni)
Greg Kroah-Hartman
maintainerPATCH 916/1276 fs/ntfs3: bound DeleteIndexEntryAllocation memmove length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Komarov <[email protected]>
commit fc4626bb3656362de8b0ecd56605d47a19ec3518 upstream.
In do_action()'s DeleteIndexEntryAllocation case, e->size comes from an on-disk INDEX_BUFFER entry. When e->size makes e + e->size point past hdr + hdr->used,PtrOffset(e1, Add2Ptr(hdr, used)) returns a negative ptrdiff_t that is silently cast to a quasi-infinite size_t when passed to memmove(). The memmove then walks past the destination buffer.
The sibling DeleteIndexEntryRoot case at fslog.c:3540-3543 already carries the corresponding guard:
if (PtrOffset(e1, Add2Ptr(hdr, used)) < esize ||
Add2Ptr(e, esize) > Add2Ptr(lrh, rec_len) ||
used + esize > le32_to_cpu(hdr->total)) {
goto dirty_vol;
}Apply the same shape to the allocation-path case. Also reject esize == 0: memmove(e, e, ...) is a no-op and leaves hdr->used unchanged, hiding a malformed entry from the existing check_index_header() walk.
Reproduced under UML+KASAN on mainline 8d90b09e6741 by mounting a crafted NTFS image: the unguarded memmove takes a length of 0xffffffffffffff00 and the kernel oopses in memmove+0x81/0x1a0 on the do_action+0x36a2 frame.
--- fs/ntfs3/fslog.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
fs/ntfs3/fslog.c +15 -1
@@ -3574,9 +3574,23 @@ move_data: } e1 =Add2Ptr (e, esize); - nsize = esize; used =le32_to_cpu (hdr->used); +/* +* Reject crafted entries whose e->size makes e + esize +* point past the INDEX_HDR's used boundary. Without this, +* PtrOffset(e1, hdr + used) underflows to a quasi-infinite +* size_t when fed to the memmove() below. +* +* Also reject esize == 0: memmove(e, e, ...) is a no-op and +* leaves hdr->used unchanged, masking the crafted entry. +*/ +if (!esize ||Add2Ptr (e, esize) >Add2Ptr (hdr, used) || +PtrOffset (e1,Add2Ptr (hdr, used)) < esize) + goto dirty_vol; + + nsize = esize; +memmove (e, e1,PtrOffset (e1,Add2Ptr (hdr, used))); hdr->used =cpu_to_le32 (used - nsize);
Greg Kroah-Hartman
maintainerPATCH 917/1276 fs/ntfs3: bound copy_lcns dp->page_lcns[] index in analysis pass
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 5e7b598660cfa8e5af172cf4c65cffc126333307 upstream.
In log_replay()'s analysis pass, after find_dp() returns a valid DIR_PAGE_ENTRY for the (target_attr, target_vcn) tuple, the copy_lcns block walks lrh->lcns_follow further entries:
t16 = le16_to_cpu(lrh->lcns_follow);
for (i = 0; i < t16; i++) {
size_t j = (size_t)(le64_to_cpu(lrh->target_vcn) -
le64_to_cpu(dp->vcn));
dp->page_lcns[j + i] = lrh->page_lcns[i];
}find_dp() only validates that target_vcn falls within [dp->vcn, dp->vcn + dp->lcns_follow), i.e., that the FIRST cluster is covered. The walk through the further entries is not bounded against dp->lcns_follow. For a malformed LRH where target_vcn = dp->vcn + dp->lcns_follow - 1 and lrh->lcns_follow > 1, the i > 0 writes overflow the dp's allocated page_lcns[] array.
Add the missing j + lrh->lcns_follow <= dp->lcns_follow guard.
Reproduced under UML+KASAN on mainline 8d90b09e6741 as a slab-out-of-bounds write of size 8 from log_replay+0x68d4 on the mount path.
This is distinct from Pavitra Jha's 2026-05-02 patch ("fs/ntfs3: validate lcns_follow in log_replay conversion", <[email protected]>) which addresses the separate version-0 dirty-page-table conversion path's memmove(&dp->vcn, ...) call. The two fixes are complementary; both should land.
[[email protected]: clang-formatted the changes, fixed conflicts]
--- fs/ntfs3/fslog.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-)
fs/ntfs3/fslog.c +29 -17
@@ -3365,8 +3365,8 @@ move_data:if (run_get_highest_vcn (le64_to_cpu (attr->nres.svcn),attr_run (attr), -le32_to_cpu (attr->size) - -le16_to_cpu (attr->nres.run_off), +le32_to_cpu (attr->size) - +le16_to_cpu (attr->nres.run_off), &t64)) { goto dirty_vol; }
@@ -4580,22 +4580,34 @@ copy_lcns:* whole routine a loop, case Lcns do not fit below. */ t16 =le16_to_cpu (lrh->lcns_follow); - t32 =le32_to_cpu (dp->lcns_follow); -if (le64_to_cpu (lrh->target_vcn) <le64_to_cpu (dp->vcn)) { - err = -EINVAL ; - goto out; - } - -for (i =0 ; i < t16; i++) { -size_t j = (size_t )(le64_to_cpu (lrh->target_vcn) - -le64_to_cpu (dp->vcn)); -if (j >= t32 || i >= t32 - j) { - err = -EINVAL ; - goto out; - } - dp->page_lcns[j + i] = lrh->page_lcns[i]; - } + t32 =le32_to_cpu (dp->lcns_follow); +if (le64_to_cpu (lrh->target_vcn) <le64_to_cpu (dp->vcn)) { + err = -EINVAL ; + goto out; + } + +/* +* find_dp() only validates that target_vcn is the first +* cluster covered by dp. The walk through lrh->lcns_follow +* further entries must stay within the allocated +* dp->page_lcns[] array, which is sized by dp->lcns_follow. +*/ +if (le64_to_cpu (lrh->target_vcn) -le64_to_cpu (dp->vcn) + t16 > +le32_to_cpu (dp->lcns_follow)) { + err = -EINVAL ; + log->set_dirty = true; + goto out; + } +for (i =0 ; i < t16; i++) { +size_t j = (size_t )(le64_to_cpu (lrh->target_vcn) - +le64_to_cpu (dp->vcn)); +if (j >= t32 || i >= t32 - j) { + err = -EINVAL ; + goto out; + } + dp->page_lcns[j + i] = lrh->page_lcns[i]; + } goto next_log_record_analyze;case DeleteDirtyClusters: {
Greg Kroah-Hartman
maintainerPATCH 918/1276 fs/ntfs3: bound attr_off in UpdateResidentValue against data_off
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Komarov <[email protected]>
commit d1570c48f49a693974d000251030370ee2e83539 upstream.
In do_action()'s UpdateResidentValue case (fslog.c:3307), lrh->attr_off and lrh->redo_len come from the on-disk LRH. When they satisfy aoff + dlen < attr->res.data_off, the assignment
attr->res.data_size = cpu_to_le32(aoff + dlen - data_off);
underflows to ~4 GiB (e.g. 0xFFFFFFF9 when aoff=0x10, dlen=1, data_off=0x18). Subsequent code that reads attr->res.data_size to walk the resident attribute payload would then read up to 4 GiB past the 1024-byte MFT record allocation.
The existing mi_enum_attr() defense in fs/ntfs3/record.c:287 catches the corrupted data_size on the next attribute walk and fails the mount, but only on the path that walks all attributes. A read site that picks an attribute by name and reads its data_size without re-validating is not covered. Validate aoff against data_off and asize at the source.
Reproduced under UML+KASAN on mainline 8d90b09e6741 via pr_warn-only probe: with aoff=0x10 and data_off=0x18, the post-assignment data_size is 0xfffffff9 (mount then fails at -22 from mi_enum_attr).
--- fs/ntfs3/fslog.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/ntfs3/fslog.c +11 -0
@@ -3313,6 +3313,17 @@ skip_load_parent: nsize =ALIGN (nsize,8 ); data_off =le16_to_cpu (attr->res.data_off); +/* +* aoff comes from the on-disk lrh->attr_off. Forbid +* writes that begin below the resident attribute's +* data_off (which would overwrite the resident header), +* and forbid aoff + dlen < data_off, which would make +* the data_size assignment below underflow to ~4 GiB. +*/ +if (aoff < data_off || aoff + dlen < data_off || + aoff + dlen > asize) + goto dirty_vol; +if (nsize < asize) {memmove (Add2Ptr (attr, aoff), data, dlen); data =NULL ;// To skip below memmove().
Greg Kroah-Hartman
maintainerPATCH 919/1276 fs/ntfs3: validate lcns_follow in log_replay conversion
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Komarov <[email protected]>
commit 6a4c53a2e26a865565bd6a460961e8d6fcb32329 upstream.
log_replay() converts DIR_PAGE_ENTRY_32 records into DIR_PAGE_ENTRY records when replaying version 0 restart tables.
During this conversion, the memmove() length is derived directly from the on-disk lcns_follow field:
memmove(&dp->vcn, &dp0->vcn_low, 2 * sizeof(u64) + le32_to_cpu(dp->lcns_follow) * sizeof(u64));
check_rstbl() validates restart table structure, but does not constrain per-entry lcns_follow values relative to the entry size. A malformed filesystem image can provide an oversized lcns_follow value, causing the conversion memmove() to access memory beyond the bounds of the allocated restart table buffer.
The same field is later used to bound iteration over page_lcns[], so validating lcns_follow during conversion also prevents downstream out-of-bounds access from the same malformed metadata.
Compute the maximum valid lcns_follow from the already-validated restart table entry size and reject entries that exceed this bound. Reuse the existing t16/t32 scratch variables already declared in log_replay() to avoid introducing new declarations.
--- fs/ntfs3/fslog.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
fs/ntfs3/fslog.c +16 -3
@@ -4263,13 +4263,26 @@ check_dirty_page_table:if (rst->major_ver) goto end_conv_1;/* reduce tab pressure. */ + t16 =le16_to_cpu (dptbl->size); +if (t16 <sizeof (struct DIR_PAGE_ENTRY )) { + log->set_dirty = true; + goto out; + } + + t32 = (t16 -sizeof (struct DIR_PAGE_ENTRY )) /sizeof (u64); + dp =NULL ;while ((dp =enum_rstbl (dptbl, dp))) {struct DIR_PAGE_ENTRY_32 *dp0 = (struct DIR_PAGE_ENTRY_32 *)dp; -// NOTE: Danger. Check for of boundary. +u32 lcns =le32_to_cpu (dp->lcns_follow); + +if (lcns > t32) { + log->set_dirty = true; + goto out; + } +memmove (&dp->vcn, &dp0->vcn_low, -2 *sizeof (u64) + -le32_to_cpu (dp->lcns_follow) *sizeof (u64)); +2 *sizeof (u64) + lcns *sizeof (u64)); } end_conv_1:
Greg Kroah-Hartman
maintainerPATCH 920/1276 fs/ntfs3: add depth limit to indx_find_buffer to prevent stack overflow
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 1ebd684b8f627f75bc3e03f8b2ad8400fd1f02cd upstream.
indx_find_buffer() recursively descends the B+ tree index with no depth limit. A crafted NTFS image with circular index node references causes unbounded recursion, overflowing the kernel stack and panicking the system.
This is reachable by mounting a malicious NTFS filesystem (e.g. from a USB drive via desktop automount) and deleting a file whose index entry triggers the rebalancing fallback path in indx_delete_entry().
Add a depth parameter and bail out with -EINVAL when it reaches the fnd->nodes array bound, matching the constraint already enforced by fnd_push() in indx_find().
The related function indx_find() was previously patched for a similar infinite-loop issue (commit 1732053c8a6b), but indx_find_buffer() was missed.
--- fs/ntfs3/index.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/ntfs3/index.c +12 -3
@@ -2014,13 +2014,21 @@ out1:static struct indx_node *indx_find_buffer (struct ntfs_index *indx,struct ntfs_inode *ni,const struct INDEX_ROOT *root, -__le64 vbn,struct indx_node *n) +__le64 vbn,struct indx_node *n, +int depth) {int err;const struct NTFS_DE *e;struct indx_node *r;const struct INDEX_HDR *hdr = n ? &n->index->ihdr : &root->ihdr; +/* +* Limit recursion depth to prevent stack overflow from crafted +* images. Use the same bound as the fnd->nodes array (20). +*/ +if (depth >ARRAY_SIZE (((struct ntfs_fnd *)NULL )->nodes)) +return ERR_PTR (-EINVAL ); +/* Step 1: Scan one level. */ for (e =hdr_first_de (hdr);; e =hdr_next_de (hdr, e)) {if (!e)
@@ -2041,7 +2049,8 @@ static struct indx_node *indx_find_buffeif (err)return ERR_PTR (err); - r =indx_find_buffer (indx, ni, root, vbn, n); + r =indx_find_buffer (indx, ni, root, vbn, n, + depth +1 );if (r)return r; }
@@ -2446,7 +2455,7 @@ int indx_delete_entry(struct ntfs_indexfnd_clear (fnd); - in =indx_find_buffer (indx, ni, root, sub_vbn,NULL ); + in =indx_find_buffer (indx, ni, root, sub_vbn,NULL ,0 );if (IS_ERR (in)) { err =PTR_ERR (in); goto out;
Greg Kroah-Hartman
maintainerPATCH 921/1276 fs/ntfs3: bound NTFS_DE view.data_off in UpdateRecordData{Root,Allocation}
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 3e127829e57f5190f612412ece4541cb96d5ec7a upstream.
In do_action()'s UpdateRecordDataRoot (fslog.c:3489) and UpdateRecordDataAllocation (fslog.c:3697) cases, the memmove destination is Add2Ptr(e, le16_to_cpu(e->view.data_off)), where e->view.data_off comes from an on-disk NTFS_DE inside an INDEX_ROOT or INDEX_BUFFER. Neither case validates view.data_off + dlen against e->size; the existing check_if_index_root / check_if_alloc_index helpers walk the entry chain and validate the entry's offset, but not its internal view fields.
The neighbouring read sites (e.g., fs/ntfs3/index.c when iterating view entries) check view.data_off + view.data_size <= e->size. Apply the same bound at the two memmove sites.
Reproduced under UML+KASAN on mainline 8d90b09e6741 via pr_warn-only probe instrumentation: with view.data_off forced to 0xFFFC, the memmove writes 32 bytes past the end of the NTFS_DE.
This is similar in shape to Pavitra Jha's 2026-05-02 patch "fs/ntfs3: prevent oob in case UpdateRecordDataRoot" (<[email protected]>) which proposes calling ntfs3_bad_de_range(); that helper does not exist in mainline. This patch uses inline checks.
--- fs/ntfs3/fslog.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
fs/ntfs3/fslog.c +18 -0
@@ -3512,6 +3512,18 @@ move_data: e =Add2Ptr (attr,le16_to_cpu (lrh->attr_off)); +/* +* e->view.data_off and dlen come from the on-disk +* INDEX_ROOT entry / LRH. The neighbouring read sites +* (e.g. fs/ntfs3/index.c) check that +* view.data_off + view.data_size <= e->size; mirror that +* bound here so the memmove cannot reach past the entry. +*/ +if (le16_to_cpu (e->view.data_off) >le16_to_cpu (e->size) || +le16_to_cpu (e->view.data_off) + dlen > +le16_to_cpu (e->size)) + goto dirty_vol; +memmove (Add2Ptr (e,le16_to_cpu (e->view.data_off)), data, dlen); mi->dirty = true;
@@ -3718,6 +3730,12 @@ move_data: goto dirty_vol; } +/* See UpdateRecordDataRoot for the rationale. */ +if (le16_to_cpu (e->view.data_off) >le16_to_cpu (e->size) || +le16_to_cpu (e->view.data_off) + dlen > +le16_to_cpu (e->size)) + goto dirty_vol; +memmove (Add2Ptr (e,le16_to_cpu (e->view.data_off)), data, dlen); a_dirty = true;
Greg Kroah-Hartman
maintainerPATCH 922/1276 ntfs3: cap RESTART_TABLE free-chain walker at rt->used
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 9611f644302c07d21bc8af97e3e06a3d30064253 upstream.
A crafted NTFS3 disk image triggers an in-kernel infinite loop at mount time, hanging the mounting thread and firing the soft-lockup watchdog within ~22s on multi-CPU hosts (panic with kernel.softlockup_panic=1). The bug is reachable from desktop USB auto-mount on distributions where udisks2 routes the NTFS signature to the in-tree ntfs3 driver (Arch family and an increasing fraction of Fedora / openSUSE / RHEL deployments); CAP_SYS_ADMIN-class manual mount elsewhere.
check_rstbl()'s second walker iterates the free-entry singly-linked list headed by rt->first_free with no upper bound on iteration count:
for (off = ff; off;) {
if (off == RESTART_ENTRY_ALLOCATED)
return false;
off = le32_to_cpu(*(__le32 *)Add2Ptr(rt, off));
if (off > ts - sizeof(__le32))
return false;
}The existing guards cover three exits: end-of-list (off == 0), the in-use marker (off == RESTART_ENTRY_ALLOCATED), and out-of-bounds (off > ts - sizeof(__le32)). None of the three prevents an in-bounds cycle.
A crafted on-disk RESTART_TABLE whose free chain contains a self-loop or A->B->A cycle whose offsets satisfy:
- in range [sizeof(struct RESTART_TABLE), ts - sizeof(__le32)]
- (off - sizeof(struct RESTART_TABLE)) % rsize == 0
passes all existing guards and spins the mount-time thread forever. Reproduced in UML by hand-forging a 2 MB NTFS3 image whose journal RESTART_TABLE first_free = 0x18 and whose entry at offset 0x18 stores 0x18 as its next pointer; mount of the forged image with the in-tree ntfs3 driver never returns.
Bound the walker by rt->used. Each entry on a legitimate free chain is unique, and the total slot count is ne = le16_to_cpu (rt->used). A traversal that visits more than ne slots is by construction malformed; reject it as a corrupt RESTART_TABLE.
After this patch, mount of the forged image returns with -EINVAL and a log_replay failure message, and mkntfs-produced legitimate images mount cleanly (verified in the same UML harness).
--- fs/ntfs3/fslog.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/ntfs3/fslog.c +12 -1
@@ -764,8 +764,19 @@ static bool check_rstbl(const struct RES/* * Walk through the list headed by the first entry to make * sure none of the entries are currently being used. +* +* Bound traversal by ne (rt->used) to defeat a crafted on-disk +* cycle in the free chain. Each entry in a legitimate free +* list is unique, so a chain that visits more than ne slots +* is malformed. Without this guard, an attacker-controlled +* RESTART_TABLE with a self-loop or A->B->A cycle whose +* offsets satisfy the existing alignment + in-bounds guards +* spins forever at mount time. */ -for (off = ff; off;) { +for (off = ff, i =0 ; off; i++) { +if (i > ne) +return false; +if (off ==RESTART_ENTRY_ALLOCATED )return false;
Greg Kroah-Hartman
maintainerPATCH 923/1276 ntfs3: bound to_move in indx_insert_into_root before hdr_insert_head
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 9b6926ac9c970ae0b2c2fe6289b16e9aa10b6a67 upstream.
indx_insert_into_root() promotes a full resident $INDEX_ROOT into $INDEX_ALLOCATION and copies all non-last resident root entries into a newly allocated INDEX_BUFFER via hdr_insert_head(). The source byte count 'to_move' is summed from the on-disk resident entry sizes and is independent of the destination buffer size, which comes from root->index_block_size (via indx->index_bits).
A crafted NTFS image that keeps a valid, full resident root but shrinks root->index_block_size down to 512 after the root has been populated makes hdr_insert_head() memcpy attacker-controlled resident entry bytes past the end of the kmalloc(1u << indx->index_bits) allocation returned by indx_new(). For a 512-byte destination and a resident root whose non-last entries total 560 bytes, the memcpy overruns by 120 bytes and a following memmove extends the highest written offset to 136 bytes past the allocation. The overflow bytes are a direct copy of on-disk entries (via kmemdup), so they are fully attacker-controlled.
The write is reachable from unprivileged open(O_CREAT) on a mounted crafted NTFS image: a single sufficiently long create in a directory whose resident root is already full forces root promotion and triggers the copy.
This is a controlled out-of-bounds write of 120-136 bytes past a kmalloc(index_block_size) allocation, with attacker-controlled content. It is a bounded adjacent-heap corruption primitive; it is not an arbitrary-address write. Successful exploitation into a named victim object depends on the surrounding slab layout.
Reject the copy at the sink. The destination's INDEX_HDR already reports hdr_total (the payload capacity of the new buffer) and hdr_used (the bytes already consumed by the terminal END entry installed by indx_new()); require that to_move fits in the remaining payload before calling hdr_insert_head(). On mismatch, fail with -EINVAL and mark the filesystem as having a detected on-disk inconsistency, which is the same behaviour as the surrounding validation in this function.
--- fs/ntfs3/index.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/ntfs3/index.c +16 -0
@@ -1743,6 +1743,22 @@ static int indx_insert_into_root(struct hdr_used =le32_to_cpu (hdr->used); hdr_total =le32_to_cpu (hdr->total); +/* +* The destination INDEX_BUFFER has 'hdr_total' bytes of payload +* available after the header, of which 'hdr_used' are already +* consumed by the single terminal END entry installed by +* indx_new(). A crafted image can present a resident root whose +* non-last entries (summing to 'to_move') exceed what fits in +* this buffer; copying them unchecked would overrun the +* kmalloc(1u << indx->index_bits) allocation backing the new +* buffer. Reject the copy in that case. +*/ +if (to_move > hdr_total - hdr_used) { + err = -EINVAL ; +ntfs_set_state (sbi,NTFS_DIRTY_ERROR ); + goto out_put_n; + } +/* Copy root entries into new buffer. */ hdr_insert_head (hdr, re, to_move);
Greg Kroah-Hartman
maintainerPATCH 924/1276 ntfs3: validate split-point offset in indx_insert_into_buffer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit f1df9d771df47aa40de6d70949c28720ae1e430d upstream.
indx_insert_into_buffer() computes
used = used1 - to_copy - sp_size;
memmove(de_t, Add2Ptr(sp, sp_size), used - le32_to_cpu(hdr1->de_off));where sp and sp_size come from hdr_find_split(). hdr_find_split() walks entries by le16_to_cpu(e->size) without validating that each step stays within hdr->used or that the size field is at least sizeof(struct NTFS_DE). index_hdr_check(), the on-load gatekeeper, only validates header-level fields (used, total, de_off) and does not walk per-entry sizes.
A crafted NTFS image whose leaf INDEX_HDR reports used == total but contains one interior NTFS_DE with size = 0xFFF0 therefore passes validation, descends to indx_insert_into_buffer() through the ntfs_create() -> indx_insert_entry() path, and makes hdr_find_split() return an sp whose sp_size (0xFFF0) greatly exceeds the remaining bytes in the buffer. The u32 subtraction underflows and the memmove count becomes a near-4-GiB value, producing an out-of-bounds kernel write that corrupts adjacent allocations and panics the kernel.
Reproduced on 7.0.0-rc7 with UML + KASAN via a crafted image and a single 'touch' inside the mounted directory; crash site resolves to fs/ntfs3/index.c at the memmove. Trigger requires only local mount of an attacker-supplied filesystem image (USB, loopback, or removable media auto-mount).
Reject the split whenever the chosen sp plus its declared size already extends past hdr1->used. This is the minimal fix; it preserves the existing hdr_find_split() contract and relies on the same out: cleanup path as the pre-existing error returns.
A prior OOB read in the very same indx_insert_into_buffer() memmove was fixed in commit b8c44949044e ("fs/ntfs3: Fix OOB read in indx_insert_into_buffer") by tightening hdr_find_e(), but that fix does not cover the split-point size field path addressed here: sp is returned by hdr_find_split(), not hdr_find_e(), and the underflow is driven by sp->size rather than hdr->used exceeding hdr->total.
--- fs/ntfs3/index.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/ntfs3/index.c +14 -0
@@ -1863,6 +1863,20 @@ indx_insert_into_buffer(struct ntfs_indememcpy (up_e, sp, sp_size); used1 =le32_to_cpu (hdr1->used); + +/* +* hdr_find_split does not validate per-entry sizes, so a crafted +* NTFS_DE whose le16 size field is out of range can place sp such +* that (PtrOffset(hdr1, sp) + sp_size) exceeds used1. Without this +* guard the u32 'used = used1 - to_copy - sp_size' underflows and +* the subsequent memmove count becomes a near-4-GiB value, +* triggering an out-of-bounds kernel write. +*/ +if (PtrOffset (hdr1, sp) + sp_size > used1) { + err = -EINVAL ; + goto out; + } + hdr1_saved =kmemdup (hdr1, used1,GFP_NOFS );if (!hdr1_saved) { err = -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 925/1276 ntfs3: fix out-of-bounds read in decompress_lznt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 7160a57192fb16d7a6fa9b7f5c7ac341d2444a89 upstream.
decompress_lznt() does not validate array index bounds before accessing the decompression table. A corrupted NTFS3 image with invalid compressed data can trigger an out-of-bounds read.
Add index bounds checking to prevent the OOB access.
--- fs/ntfs3/lznt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/lznt.c +1 -1
@@ -240,7 +240,7 @@ static inline ssize_t decompress_chunk(uif (up - unc >LZNT_CHUNK_SIZE )return -EINVAL ;/* Correct index */ -while (unc + s_max_off[index] < up) +while (index <ARRAY_SIZE (s_max_off) -1 && unc + s_max_off[index] < up) index +=1 ;/* Check the current flag for zero. */
Greg Kroah-Hartman
maintainerPATCH 926/1276 power: supply: charger-manager: fix refcount leak in is_full_charged()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: WenTao Liang <[email protected]>
commit 4373cfa38ead58f980362c841b0d0bdf8c4d956c upstream.
In is_full_charged(), power_supply_get_by_name() is called to obtain a reference to the fuel_gauge power supply. If the voltage check (uV >= desc->fullbatt_uV) succeeds, the function returns true directly without releasing the reference, leaking the refcount.
Fix this by setting a flag and jumping to the out label where power_supply_put() properly drops the reference.
--- drivers/power/supply/charger-manager.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/power/supply/charger-manager.c +4 -2
@@ -302,8 +302,10 @@ static bool is_full_charged(struct chargif (cm->battery_status ==POWER_SUPPLY_STATUS_FULL && desc->fullbatt_vchkdrop_uV) uV += desc->fullbatt_vchkdrop_uV; -if (uV >= desc->fullbatt_uV) -return true; +if (uV >= desc->fullbatt_uV) { + is_full = true; + goto out; + } } }
Greg Kroah-Hartman
maintainerPATCH 927/1276 selftests/landlock: Test SCOPE_SIGNAL on the SIGIO/fowner pgid path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 76579d09beedaffe7fe76e9c05644f73983e1ceb upstream.
Add regression tests for the LANDLOCK_SCOPE_SIGNAL handling of the asynchronous SIGIO delivery path (fcntl(F_SETOWN)) with a process-group owner.
sigio_to_pgid_members covers the bypass: a sandboxed process at the head of its process group's PGID hlist (the default after fork()) arms F_SETOWN(-pgrp) + O_ASYNC and triggers the fan-out; the in-domain owner must be signaled (proving the trigger fired) while the non-sandboxed member of the group, outside the domain, must not.
sigio_to_pgid_self covers the same-process guarantee: the owner is registered from a sandboxed non-leader thread, whose domain differs from the thread-group leader the kernel signals for a process-group owner. That leader belongs to the owner's own process and must still be signaled.
Without the fix the first test sees the out-of-domain member signaled and the second sees the owner's own leader denied.
--- tools/testing/selftests/landlock/scoped_signal_test.c | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+)
tools/testing/selftests/landlock/scoped_signal_test.c +182 -0
@@ -559,4 +559,186 @@ TEST_F(fown, sigurg_socket) _metadata->exit_code =KSFT_FAIL ; } +/* +* Checks that LANDLOCK_SCOPE_SIGNAL is enforced on the asynchronous SIGIO +* delivery path (fcntl(F_SETOWN)) when the file owner is a process group. +* +* A sandboxed process sitting at the head of its process group's PID hlist (the +* default position right after fork()) used to escape the fcntl(F_SETOWN, +* -pgrp) domain recording: pid_task(pgrp, PIDTYPE_PGID) resolved to the process +* itself, so the same-thread-group exemption skipped recording its Landlock +* domain. At SIGIO time that domain was then unset and the signal fanned out +* to every group member, including non-sandboxed processes outside the domain. +*/ +TEST (sigio_to_pgid_members) +{ +int trigger[2 ], sync_child[2 ]; +char buf; +pid_t child; +int status, i; + +drop_caps (_metadata); + +/* +* Isolates the test in its own process group so the SIGIO fan-out stays +* bounded to this parent and the child forked below. +*/ +ASSERT_EQ (0 ,setpgid (0 ,0 )); + +/* The non-sandboxed parent is the protected (out-of-domain) target. */ +ASSERT_EQ (0 ,setup_signal_handler (SIGURG )); + signal_received =0 ; + +ASSERT_EQ (0 ,pipe2 (trigger,O_CLOEXEC )); +ASSERT_EQ (0 ,pipe2 (sync_child,O_CLOEXEC )); + + child =fork (); +ASSERT_LE (0 , child); +if (child ==0 ) { +/* +* The child inherits the parent's new process group and, just +* attached with hlist_add_head_rcu(), is now the head of the +* pgid hlist: this is the case that used to skip the recording. +*/ +EXPECT_EQ (0 ,close (sync_child[0 ])); + +/* In-domain positive control: the child must be signaled. */ +ASSERT_EQ (0 ,setup_signal_handler (SIGURG )); + signal_received =0 ; + +create_scoped_domain (_metadata,LANDLOCK_SCOPE_SIGNAL ); + +/* Owns the SIGIO source for the whole process group. */ +ASSERT_EQ (0 ,fcntl (trigger[0 ],F_SETSIG ,SIGURG )); +ASSERT_EQ (0 ,fcntl (trigger[0 ],F_SETOWN , -getpgrp ())); +ASSERT_EQ (0 ,fcntl (trigger[0 ],F_SETFL ,O_ASYNC )); + +/* Fans SIGURG out to every member of the process group. */ +ASSERT_EQ (1 ,write (trigger[1 ],"." ,1 )); + +/* +* The sandboxed child is in its own domain and must always be +* signaled: this proves the SIGIO actually fired. +*/ +for (i =0 ; i <1000 && !signal_received; i++) +usleep (1000 ); +EXPECT_EQ (1 , signal_received); + +ASSERT_EQ (1 ,write (sync_child[1 ],"." ,1 )); +EXPECT_EQ (0 ,close (sync_child[1 ])); + +_exit (_metadata->exit_code); +return ; + } +EXPECT_EQ (0 ,close (sync_child[1 ])); +EXPECT_EQ (0 ,close (trigger[0 ])); +EXPECT_EQ (0 ,close (trigger[1 ])); + +/* Waits for the child to generate the SIGIO. */ +ASSERT_EQ (1 ,read (sync_child[0 ], &buf,1 )); +EXPECT_EQ (0 ,close (sync_child[0 ])); + +/* Lets a delivered-but-pending signal run our handler, if any. */ +for (i =0 ; i <100 && !signal_received; i++) +usleep (1000 ); + +/* +* SCOPE_SIGNAL must block the fan-out to this non-sandboxed parent, +* which is outside the child's Landlock domain. Before the fix the +* parent was signaled here. +*/ +EXPECT_EQ (0 , signal_received); + +ASSERT_EQ (child,waitpid (child, &status,0 )); +if (WIFSIGNALED (status) || !WIFEXITED (status) || +WEXITSTATUS (status) !=EXIT_SUCCESS ) + _metadata->exit_code =KSFT_FAIL ; +} + +static void *thread_setown_scoped (void *arg) +{ +const int fd = *(int *)arg; +int ruleset_fd; +const struct landlock_ruleset_attr ruleset_attr = { + .scoped =LANDLOCK_SCOPE_SIGNAL , + }; + +/* Sandboxes only this non-leader thread (no thread syncing). */ + ruleset_fd = +landlock_create_ruleset (&ruleset_attr,sizeof (ruleset_attr),0 ); +if (ruleset_fd <0 ) +return (void *)THREAD_ERROR ; +if (prctl (PR_SET_NO_NEW_PRIVS ,1 ,0 ,0 ,0 ) || +landlock_restrict_self (ruleset_fd,0 )) { +close (ruleset_fd); +return (void *)THREAD_ERROR ; + } +close (ruleset_fd); + +/* Makes this process group own the SIGIO source. */ +if (fcntl (fd,F_SETSIG ,SIGURG ) ||fcntl (fd,F_SETOWN , -getpgrp ()) || +fcntl (fd,F_SETFL ,O_ASYNC )) +return (void *)THREAD_ERROR ; + +return (void *)THREAD_SUCCESS ; +} + +/* +* Checks that the SIGIO fan-out is still delivered to the file owner's own +* process when fcntl(F_SETOWN, -pgrp) was issued from a sandboxed non-leader +* thread. +* +* The Landlock domain is recorded for a process-group owner (so out-of-domain +* members stay blocked, see sigio_to_pgid_members), but the kernel signals a +* process group through its members' thread-group leaders. Here the leader is +* not sandboxed and thus has a different domain than the registering thread, so +* the registration-time check cannot tell that it belongs to the owner's own +* process. hook_file_send_sigiotask() must recognize it through the recorded +* thread group and allow the delivery, matching the same-process guarantee of +* commit 18eb75f3af40. Without that exemption the leader is wrongly denied and +* never signaled. +*/ +TEST (sigio_to_pgid_self) +{ +int trigger[2 ]; +pthread_t thread; +enum thread_return ret =THREAD_INVALID ; +int i; + +drop_caps (_metadata); + +/* Bounds the SIGIO fan-out to this process. */ +ASSERT_EQ (0 ,setpgid (0 ,0 )); + +/* The non-sandboxed thread-group leader is the SIGIO target. */ +ASSERT_EQ (0 ,setup_signal_handler (SIGURG )); + signal_received =0 ; + +ASSERT_EQ (0 ,pipe2 (trigger,O_CLOEXEC )); + +/* +* Registers the process-group fowner from a sibling thread that +* sandboxes only itself, so its domain differs from the leader's. +*/ +ASSERT_EQ (0 ,pthread_create (&thread,NULL , thread_setown_scoped, + &trigger[0 ])); +ASSERT_EQ (0 ,pthread_join (thread, (void **)&ret)); +ASSERT_EQ (THREAD_SUCCESS , ret); + +/* Fans SIGURG out to the process group. */ +ASSERT_EQ (1 ,write (trigger[1 ],"." ,1 )); + +for (i =0 ; i <1000 && !signal_received; i++) +usleep (1000 ); + +/* +* Same-process delivery must always be allowed, even though the owner +* was registered from a sandboxed sibling thread. +*/ +EXPECT_EQ (1 , signal_received); + +EXPECT_EQ (0 ,close (trigger[0 ])); +EXPECT_EQ (0 ,close (trigger[1 ])); +} +TEST_HARNESS_MAIN
Greg Kroah-Hartman
maintainerPATCH 928/1276 mips: sched: Fix CPUMASK_OFFSTACK memory corruption
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aaron Tomlin <[email protected]>
commit 98e37db4a34d3af3fb2f4648295c25b5e40b20e3 upstream.
This patch addresses a critical memory management flaw. When CONFIG_CPUMASK_OFFSTACK is enabled, cpumask_var_t is a pointer. Consequently, sizeof(new_mask) evaluates to the pointer size, causing copy_from_user() to clobber the mask pointer. Furthermore, the old logic performed copy_from_user() before allocating the mask.
Fix this by allocating new_mask first. To handle variable-sized user masks correctly, use cpumask_size() to truncate overly large user masks or pad undersized masks with zeros before copying the data directly into the allocated buffer.
--- arch/mips/kernel/mips-mt-fpaff.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
arch/mips/kernel/mips-mt-fpaff.c +15 -13
@@ -71,11 +71,16 @@ asmlinkage long mipsmt_sys_sched_setaffistruct task_struct *p;int retval; -if (len <sizeof (new_mask)) -return -EINVAL ; - -if (copy_from_user (&new_mask, user_mask_ptr,sizeof (new_mask))) -return -EFAULT ; +if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) +return -ENOMEM ; +if (len <cpumask_size ()) +cpumask_clear (new_mask); +else if (len >cpumask_size ()) + len =cpumask_size (); +if (copy_from_user (new_mask, user_mask_ptr, len)) { + retval = -EFAULT ; + goto out_free_new_mask; + }cpus_read_lock ();rcu_read_lock ();
@@ -84,7 +89,8 @@ asmlinkage long mipsmt_sys_sched_setaffiif (!p) {rcu_read_unlock ();cpus_read_unlock (); -return -ESRCH ; + retval = -ESRCH ; + goto out_free_new_mask; }/* Prevent p going away */
@@ -95,13 +101,9 @@ asmlinkage long mipsmt_sys_sched_setaffi retval = -ENOMEM ; goto out_put_task; } -if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) { - retval = -ENOMEM ; - goto out_free_cpus_allowed; - }if (!alloc_cpumask_var (&effective_mask,GFP_KERNEL )) { retval = -ENOMEM ; - goto out_free_new_mask; + goto out_free_cpus_allowed; }if (!check_same_owner (p) && !capable (CAP_SYS_NICE )) { retval = -EPERM ;
@@ -142,13 +144,13 @@ asmlinkage long mipsmt_sys_sched_setaffi } out_unlock:free_cpumask_var (effective_mask); -out_free_new_mask: -free_cpumask_var (new_mask); out_free_cpus_allowed:free_cpumask_var (cpus_allowed); out_put_task:put_task_struct (p);cpus_read_unlock (); +out_free_new_mask: +free_cpumask_var (new_mask);return retval; }
Greg Kroah-Hartman
maintainerPATCH 929/1276 riscv: cacheinfo: Fix node reference leak in populate_cache_leaves
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zishun Yi <[email protected]>
commit bf4a195f063b0a0805c1417f6aad1dd32ea48f0f upstream.
Currently, the while loop drops the reference to prev in each iteration. If the loop terminates early due to a break, the final of_node_put(np) correctly drops the reference to the current node.
However, if the loop terminates naturally because np == NULL, calling of_node_put(np) is a no-op. This leaves the last valid node stored in prev without its reference dropped, resulting in a node reference leak.
Fix this by changing the final of_node_put(np) to of_node_put(prev).
--- arch/riscv/kernel/cacheinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cacheinfo.c +1 -1
@@ -133,7 +133,7 @@ int populate_cache_leaves(unsigned int cci_leaf_init (this_leaf++,CACHE_TYPE_DATA , level); levels = level; } -of_node_put (np); +of_node_put (prev);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 930/1276 mm/damon/sysfs-schemes: fix dir put orders in access_pattern_add_dirs()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit d58fdbe37a829fd2e5803dd4e5a72992dd8c5368 upstream.
Patch series "mm/damon/sysfs-schemes: fix wrong directories put orders in error paths".
Error paths of damon_sysfs_access_pattern_add_dirs() and damon_sysfs_scheme_add_dirs() functions put references to directories in wrong orders. As a result, uninitialized memory dereference and/or memory leak can happen. Fix those.
This patch (of 2):
In access_pattern_add_dirs(), error handling path puts references starting from setup failed directories. If the failure happpened from the initial allication in the setup functions, uninitialized memory dereference happen. The allocation failures will not commonly happen, but the consequence is quite bad. Fix the wrong reference put orders.
The issue was discovered [1] by Sashiko.
--- mm/damon/sysfs-schemes.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
mm/damon/sysfs-schemes.c +3 -6
@@ -1393,22 +1393,19 @@ static int damon_sysfs_access_pattern_ad err =damon_sysfs_access_pattern_add_range_dir (access_pattern, &access_pattern->sz,"sz" );if (err) - goto put_sz_out; +return err; err =damon_sysfs_access_pattern_add_range_dir (access_pattern, &access_pattern->nr_accesses,"nr_accesses" );if (err) - goto put_nr_accesses_sz_out; + goto put_sz_out; err =damon_sysfs_access_pattern_add_range_dir (access_pattern, &access_pattern->age,"age" );if (err) - goto put_age_nr_accesses_sz_out; + goto put_nr_accesses_sz_out;return 0 ; -put_age_nr_accesses_sz_out: -kobject_put (&access_pattern->age->kobj); - access_pattern->age =NULL ; put_nr_accesses_sz_out:kobject_put (&access_pattern->nr_accesses->kobj); access_pattern->nr_accesses =NULL ;
Greg Kroah-Hartman
maintainerPATCH 931/1276 mm/damon/sysfs-schemes: put stats for scheme_add_dirs() internal error
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit 05ea83ee88ca70f8932906d9f2617ff996f45b50 upstream.
damon_sysfs_scheme_add_dirs() setup the tried_regions directory after the stats directory setup is completed. When the tried_regions directory setup is failed, the setup function ensures the reference for the tried regions directory is released. Hence the error path should put references on setup succeeded directory objects, starting from the stats directory. However, the error path is putting the tried_regions directory instead of the stats directory.
As a direct result, the stats directory object is leaked. Worse yet, if the tried_regions directory setup failed from the initial allocation, the scheme->tried_regions field remains uninitialized. The following kobject_put(&scheme->tried_regions->kobj) call in the error path will dereference the uninitialized memory. The setup failures should not be common. But once it happens, the consequence is quite bad.
Fix this issue by correctly putting the stats directory instead of the tried_regions directory.
The issue was discovered [1] by Sashiko.
--- mm/damon/sysfs-schemes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/damon/sysfs-schemes.c +4 -4
@@ -1624,12 +1624,12 @@ static int damon_sysfs_scheme_add_dirs(s goto put_filters_watermarks_quotas_access_pattern_out; err =damon_sysfs_scheme_set_tried_regions (scheme);if (err) - goto put_tried_regions_out; + goto put_stats_out;return 0 ; -put_tried_regions_out: -kobject_put (&scheme->tried_regions->kobj); - scheme->tried_regions =NULL ; +put_stats_out: +kobject_put (&scheme->stats->kobj); + scheme->stats =NULL ; put_filters_watermarks_quotas_access_pattern_out:kobject_put (&scheme->filters->kobj); scheme->filters =NULL ;
Greg Kroah-Hartman
maintainerPATCH 932/1276 fs/proc/task_mmu: fix hugetlb self-deadlock in pagemap_scan_pte_hole()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
commit e92d92bbafb264dc0518d52b846a3c07ed8d523f upstream.
A PAGEMAP_SCAN ioctl requesting PM_SCAN_WP_MATCHING on a hugetlb VMA hangs the calling thread, unkillably, as soon as the scan reaches an unpopulated part of the range:
do_pagemap_scan()
walk_page_range()
walk_hugetlb_range()
hugetlb_vma_lock_read() # take the vma lock for read ...
pagemap_scan_pte_hole() # ... ->pte_hole() for a hole
uffd_wp_range()
change_protection()
hugetlb_change_protection()
hugetlb_vma_lock_write() # ... and block taking it for write
walk_hugetlb_range() holds the hugetlb vma lock for read across the whole walk. A present entry goes to ->hugetlb_entry(); an unpopulated one goes to ->pte_hole(), i.e. pagemap_scan_pte_hole(). To write-protect the hole that handler calls uffd_wp_range(), which on a hugetlb VMA reaches hugetlb_change_protection() and takes the same vma lock for write. The thread then blocks in down_write() waiting for the read lock it is itself holding.
The populated path avoids this: pagemap_scan_hugetlb_entry() write-protects the entry inline under the page-table lock and never enters hugetlb_change_protection().
Do the same for holes. Fault in the page table and install the uffd-wp marker directly with make_uffd_wp_huge_pte() under the page-table lock, rather than routing through uffd_wp_range(). That is the same sequence hugetlb_change_protection() runs for an unpopulated entry, minus the vma write lock -- which is safe to skip because PMD sharing is disabled on uffd-wp VMAs (hugetlb_unshare_all_pmds() runs at registration), leaving nothing for that lock to serialise against.
--- fs/proc/task_mmu.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
fs/proc/task_mmu.c +58 -1
@@ -2623,8 +2623,62 @@ out_unlock: return ret; } + +/* +* Write-protect the unpopulated hugetlb entries covering [addr, end) by +* installing uffd-wp markers inline, exactly as pagemap_scan_hugetlb_entry() +* does for populated entries. +* +* walk_hugetlb_range() currently calls ->pte_hole() once per huge page, so the +* loop normally runs a single iteration; it is written to cover the full range +* in case the walker ever coalesces adjacent holes. +* +* The obvious route -- uffd_wp_range() -> hugetlb_change_protection() -- +* cannot be used here: it takes hugetlb_vma_lock_write(), but the page-table +* walker (walk_hugetlb_range()) already holds hugetlb_vma_lock_read() on the +* same VMA, so the scanning thread would deadlock against itself. PMD sharing +* is disabled on uffd-wp VMAs (hugetlb_unshare_all_pmds() at registration), so +* the vma lock guards nothing that matters for these entries anyway. +*/ +static int pagemap_scan_hugetlb_hole_wp (struct vm_area_struct *vma, +unsigned long addr,unsigned long end) +{ +struct hstate *h =hstate_vma (vma); +unsigned long psize =huge_page_size (h); +struct mm_struct *mm = vma->vm_mm; +spinlock_t *ptl; +pte_t *ptep; +pte_t pte; + +for (addr =ALIGN_DOWN (addr, psize); addr < end; addr += psize) { + ptep =huge_pte_alloc (mm, vma, addr, psize); +if (!ptep) +return -ENOMEM ; + +i_mmap_lock_write (vma->vm_file->f_mapping); + ptl =huge_pte_lock (h, mm, ptep); + pte =huge_ptep_get (mm, addr, ptep); +make_uffd_wp_huge_pte (vma, addr, ptep, pte); +/* +* A none entry has no cached translation, so installing the +* marker needs no TLB flush. Flush only if a fault populated +* the entry between huge_pte_alloc() and the page table lock. +*/ +if (!huge_pte_none (pte)) +flush_hugetlb_tlb_range (vma, addr, addr + psize); +spin_unlock (ptl); +i_mmap_unlock_write (vma->vm_file->f_mapping); + } + +return 0 ; +}#else #define pagemap_scan_hugetlb_entry NULL +static int pagemap_scan_hugetlb_hole_wp (struct vm_area_struct *vma, +unsigned long addr,unsigned long end) +{ +return 0 ; +}#endif static int pagemap_scan_pte_hole(unsigned long addr, unsigned long end,
@@ -2644,7 +2698,10 @@ static int pagemap_scan_pte_hole(unsigneif (~p->arg.flags &PM_SCAN_WP_MATCHING )return ret; - err =uffd_wp_range (vma, addr, end - addr, true); +if (is_vm_hugetlb_page (vma)) + err =pagemap_scan_hugetlb_hole_wp (vma, addr, end); +else + err =uffd_wp_range (vma, addr, end - addr, true);if (err <0 ) ret = err;
Greg Kroah-Hartman
maintainerPATCH 933/1276 fs/proc/task_mmu: use huge_page_size() in pagemap_scan_hugetlb_entry()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
commit 1b074e3270e1c061c829150c742eb83bad4dddd1 upstream.
The partial-page check compares against HPAGE_SIZE (PMD_SIZE), which is wrong for gigantic hugetlb hstates (e.g. 1G). The walker hands the callback a huge_page_size()-sized range, never start + HPAGE_SIZE, so the comparison always declares it partial and aborts the WP. Compare against the actual hstate's page size.
--- fs/proc/task_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/proc/task_mmu.c +1 -1
@@ -2606,7 +2606,7 @@ static int pagemap_scan_hugetlb_entry(ptif (~categories &PAGE_IS_WRITTEN ) goto out_unlock; -if (end != start +HPAGE_SIZE ) { +if (end != start +huge_page_size (hstate_vma (vma))) {/* Partial HugeTLB page WP isn't possible. */ pagemap_scan_backout_range (p, start, end); p->arg.walk_end = start;
Greg Kroah-Hartman
maintainerPATCH 934/1276 proc: only bump parent nlink when registering directories
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Wilczyński <[email protected]>
commit 16b02eb4b9b272c221255c20d34ccd5db53a3ed3 upstream.
proc_register() increments the parent directory's link count for every entry it registers, while remove_proc_entry() and remove_proc_subtree() decrement it only when the removed entry is a directory. Regular files thus inflate the parent's count while they exist, and leak one link permanently on every create and remove cycle.
For example, /proc/bus/pci/00 with twenty-two device files and no subdirectories reports nlink 24 instead of 2, and SR-IOV VF enable and disable cycles, each creating and removing the VF config space entries under /proc/bus/pci/<bus>, inflate the link count of that directory without bound.
Before commit e06689bf5701 ("proc: change ->nlink under proc_subdir_lock"), the increment lived in proc_mkdir_data() and proc_create_mount_point(), and was therefore applied only to directories. Moving it into proc_register() to bring it under proc_subdir_lock dropped the S_ISDIR check.
Thus, move the nlink accounting into pde_subdir_insert() and pde_erase(), only updating it for directories in both, so the link count is always changed together with the directory entry itself.
--- fs/proc/generic.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/proc/generic.c +4 -5
@@ -112,6 +112,8 @@ static bool pde_subdir_insert(struct pro/* Add new node and rebalance tree. */ rb_link_node (&de->subdir_node, parent, new);rb_insert_color (&de->subdir_node, root); +if (S_ISDIR (de->mode)) + dir->nlink++;return true; }
@@ -399,7 +401,6 @@ struct proc_dir_entry *proc_register(strwrite_unlock (&proc_subdir_lock); goto out_free_inum; } - dir->nlink++;write_unlock (&proc_subdir_lock);return dp;
@@ -698,6 +699,8 @@ static void pde_erase(struct proc_dir_en {rb_erase (&pde->subdir_node, &parent->subdir);RB_CLEAR_NODE (&pde->subdir_node); +if (S_ISDIR (pde->mode)) + parent->nlink--; }/*
@@ -723,8 +726,6 @@ void remove_proc_entry(const char *name, de =NULL ; }else {pde_erase (de, parent); -if (S_ISDIR (de->mode)) - parent->nlink--; } }write_unlock (&proc_subdir_lock);
@@ -783,8 +784,6 @@ int remove_proc_subtree(const char *namecontinue ; } next = de->parent; -if (S_ISDIR (de->mode)) - next->nlink--;write_unlock (&proc_subdir_lock);proc_entry_rundown (de);
Greg Kroah-Hartman
maintainerPATCH 935/1276 mm/mm_init: fix uninitialized struct pages for ZONE_DEVICE
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit cd681403a87085562499d60325b7b45d3be11217 upstream.
If DAX memory is hotplugged into an unoccupied subsection of an early section, section_activate() reuses the unoptimized boot memmap. However, compound_nr_pages() still assumes that vmemmap optimization is in effect and initializes only the reduced number of struct pages. As a result, the remaining tail struct pages are left uninitialized, which can later lead to unexpected behavior or crashes.
Fix this by treating early sections as unoptimized when calculating how many struct pages to initialize.
--- mm/mm_init.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
mm/mm_init.c +10 -3
@@ -1031,10 +1031,17 @@ static void __ref __init_zone_device_pag* of how the sparse_vmemmap internals handle compound pages in the lack * of an altmap. See vmemmap_populate_compound_pages(). */ -static inline unsigned long compound_nr_pages (struct vmem_altmap *altmap, +static inline unsigned long compound_nr_pages (unsigned long pfn, +struct vmem_altmap *altmap,struct dev_pagemap *pgmap) { -if (!vmemmap_can_optimize (altmap, pgmap)) +/* +* If DAX memory is hot-plugged into an unoccupied subsection +* of an early section, the unoptimized boot memmap is reused. +* See section_activate(). +*/ +if (early_section (__pfn_to_section (pfn)) || + !vmemmap_can_optimize (altmap, pgmap))return pgmap_vmemmap_nr (pgmap);return VMEMMAP_RESERVE_NR * (PAGE_SIZE /sizeof (struct page ));
@@ -1102,7 +1109,7 @@ void __ref memmap_init_zone_device(struccontinue ;memmap_init_compound (page, pfn, zone_idx, nid, pgmap, -compound_nr_pages (altmap, pgmap)); +compound_nr_pages (pfn, altmap, pgmap)); } pr_debug("%s initialised %lu pages in %ums\n", __func__,
Greg Kroah-Hartman
maintainerPATCH 936/1276 kcov: use WRITE_ONCE() for selftest mode stores
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 9a79524d1420e6b79a6868208c264f4518d1318e upstream.
The KCOV selftest enables coverage by setting current->kcov_mode to KCOV_MODE_TRACE_PC without installing a coverage area. If an interrupt records coverage in that window, the access should fault and expose the bug.
When building for QEMU raspi0 (Raspberry Pi Zero, ARMv6, CONFIG_CPU_V6K=y, CONFIG_CURRENT_POINTER_IN_TPIDRURO=y) with GCC 13.3.0, the store that enables the mode is removed. The generated kcov_init() code only stores zero after the wait loop:
mrc 15, 0, r3, cr13, cr0, {3}
str r4, [r3, #2028]
where r4 is zero. There is no store of KCOV_MODE_TRACE_PC before the loop, so the selftest reports success without exercising coverage.
Use WRITE_ONCE() for the temporary mode stores. With the same compiler and config, kcov_init() contains the intended mode store:
mov r3, #2
mrc 15, 0, r2, cr13, cr0, {3}
str r3, [r2, #2028]
Now that the KCOV selftest is actually executed, it may expose KCOV instrumentation issues depending on the kernel config. That is expected for a selftest that was intended to catch coverage from interrupt paths.
--- kernel/kcov.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcov.c +2 -2
@@ -1086,10 +1086,10 @@ static void __init selftest(void)* potentially traced functions in this region. */ start = jiffies; - current->kcov_mode =KCOV_MODE_TRACE_PC ; +WRITE_ONCE (current->kcov_mode,KCOV_MODE_TRACE_PC );while ((jiffies - start) *MSEC_PER_SEC /HZ <300 ) ; - current->kcov_mode =0 ; +WRITE_ONCE (current->kcov_mode,0 ); pr_err("done running self test\n"); }#endif
Greg Kroah-Hartman
maintainerPATCH 937/1276 mtd: slram: remove failed entries from the device list
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
commit 36f1648644d769c496a8e47e53603e863e358d73 upstream.
register_device() links a new slram_mtdlist entry before allocating all of the state needed by the entry. If a later allocation, memremap(), or mtd_device_register() fails, the partially initialized entry remains on the global list. A later cleanup can then dereference or free invalid state from that failed entry.
Unwind the partially initialized entry and clear the list tail on each failure path after the entry has been linked.
--- drivers/mtd/devices/slram.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/mtd/devices/slram.c +16 -6
@@ -129,6 +129,7 @@ static int slram_write(struct mtd_info *static int register_device (char *name,unsigned long start,unsigned long length) {slram_mtd_list_t **curmtd; +int ret = -ENOMEM ; curmtd = &slram_mtdlist;while (*curmtd) {
@@ -155,14 +156,15 @@ static int register_device(char *name, uif (!(*curmtd)->mtdinfo) {E ("slram: Cannot allocate new MTD device.\n" ); -return (-ENOMEM ); + goto err_free_list; }if (!(((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start =memremap (start, length,MEMREMAP_WB |MEMREMAP_WT |MEMREMAP_WC ))) {E ("slram: memremap failed\n" ); -return -EIO ; + ret = -EIO ; + goto err_free_priv; } ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end = ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start + length;
@@ -183,10 +185,8 @@ static int register_device(char *name, uif (mtd_device_register ((*curmtd)->mtdinfo,NULL ,0 )) {E ("slram: Failed to register new device\n" ); -memunmap (((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start); -kfree ((*curmtd)->mtdinfo->priv); -kfree ((*curmtd)->mtdinfo); -return (-EAGAIN ); + ret = -EAGAIN ; + goto err_unmap; }T ("slram: Registered device %s from %luKiB to %luKiB\n" , name, (start /1024 ), ((start + length) /1024 ));
@@ -194,6 +194,16 @@ static int register_device(char *name, u ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start, ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end);return (0 ); + +err_unmap: +memunmap (((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start); +err_free_priv: +kfree ((*curmtd)->mtdinfo->priv); +err_free_list: +kfree ((*curmtd)->mtdinfo); +kfree (*curmtd); + *curmtd =NULL ; +return ret; }static void unregister_devices (void )
Greg Kroah-Hartman
maintainerPATCH 938/1276 9p: skip nlink update in cacheless mode to fix WARN_ON
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
commit 574aa0b4799470ac814479f1138d19efe6262255 upstream.
v9fs_dec_count() unconditionally calls drop_nlink() on regular files, even when the inode's nlink is already zero. In cacheless mode the client refetches inode metadata from the server (the source of truth) on every operation, so by the time v9fs_remove() returns, the locally cached nlink may already reflect the post-unlink value:
1. Client initiates unlink, server processes it and sets nlink to 0
2. Client refetches inode metadata (nlink=0) before unlink returns
3. Client's v9fs_remove() completes successfully
4. Client calls v9fs_dec_count() which calls drop_nlink() on nlink=0
This race is easily triggered under heavy unlink workloads, such as stress-ng's unlink stressor, producing the following warning:
WARNING: fs/inode.c:417 at drop_nlink+0x4c/0xc8 Call trace: drop_nlink+0x4c/0xc8 v9fs_remove+0x1e0/0x250 [9p] v9fs_vfs_unlink+0x20/0x38 [9p] vfs_unlink+0x13c/0x258 ...
In cacheless mode the server is authoritative and the inode is on its way out, so locally adjusting nlink buys nothing. Skip v9fs_dec_count() entirely when neither CACHE_META nor CACHE_LOOSE is set, which both avoids the warning and removes a class of nlink races (two concurrent unlinkers observing nlink > 0 and both calling drop_nlink()) that an nlink == 0 guard alone would only narrow rather than close.
Message-ID: <[email protected]>
--- fs/9p/vfs_inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/9p/vfs_inode.c +9 -0
@@ -488,10 +488,19 @@ static int v9fs_at_to_dotl_flags(int fla* - ext4 (with dir_nlink feature enabled) sets nlink to 1 if a dir has more * than EXT4_LINK_MAX (65000) links. * +* In cacheless mode the server is the source of truth for nlink and the +* inode is going away immediately, so locally adjusting i_nlink buys +* nothing and races with concurrent metadata fetches that may already +* have observed the post-unlink value (nlink == 0). +* * @inode: inode whose nlink is being dropped */ static void v9fs_dec_count (struct inode *inode) { +struct v9fs_session_info *v9ses =v9fs_inode2v9ses (inode); + +if (!(v9ses->cache & (CACHE_META |CACHE_LOOSE ))) +return ;if (!S_ISDIR (inode->i_mode) || inode->i_nlink >2 )drop_nlink (inode); }
Greg Kroah-Hartman
maintainerPATCH 939/1276 scsi: smartpqi: Use shost_to_hba() in pqi_scan_finished()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Wilck <[email protected]>
commit 57db1307afb1f83d45f5ff53b93f8d040100d13e upstream.
shost_to_hba() is used everywhere except to obtain pqi_ctrl_info from shosti, except in pqi_scan_finished(), where shost_priv() is used. This causes one pointer dereference to be missed, as shost->hostdata is a pointer in smartpqi. Fix it.
--- drivers/scsi/smartpqi/smartpqi_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +1 -1
@@ -2629,7 +2629,7 @@ static int pqi_scan_finished(struct Scsi {struct pqi_ctrl_info *ctrl_info; - ctrl_info =shost_priv (shost); + ctrl_info =shost_to_hba (shost);return !mutex_is_locked (&ctrl_info->scan_mutex); }
Greg Kroah-Hartman
maintainerPATCH 940/1276 scsi: sas: Skip opt_sectors when DMA reports no real optimization hint
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ionut Nechita <[email protected]>
commit be8fcd4a8217a916344c88a4b1b84f5736dda17e upstream.
sas_host_setup() unconditionally sets shost->opt_sectors from dma_opt_mapping_size().
When the IOMMU is disabled or in passthrough mode and no DMA ops provide an opt_mapping_size callback, dma_opt_mapping_size() returns min(dma_max_mapping_size(), SIZE_MAX) which equals dma_max_mapping_size() — a hard upper bound, not an optimization hint.
On a Dell PowerEdge R750 with mpt3sas (Broadcom SAS3816, FW 33.15.00.00) and intel_iommu=off the following values are observed:
dma_opt_mapping_size() = dma_max_mapping_size() (no real hint)
shost->max_sectors = 32767
opt_sectors = min(32767, huge >> 9) = 32767
optimal_io_size = 32767 << 9 = 16776704
→ round_down(16776704, 4096) = 16773120The SAS disk (SAMSUNG MZILT800HBHQ0D3) does not report an Optimal Transfer Length in VPD page B0, so sdkp->opt_xfer_blocks remains 0.
sd_revalidate_disk() then uses min_not_zero(0, opt_sectors) = opt_sectors, propagating the bogus value into the block device's optimal_io_size (visible as OPT-IO = 16773120 in lsblk --topology).
mkfs.xfs picks up optimal_io_size and minimum_io_size and computes:
swidth = 16773120 / 4096 = 4095
sunit = 8192 / 4096 = 2
Since 4095 % 2 != 0, XFS rejects the geometry:
SB stripe unit sanity check failed
This makes it impossible to create XFS filesystems (e.g. for /var/lib/docker) during system bootstrap.
Fix this by introducing a sas_dma_setup_opt_sectors() helper that sets opt_sectors only when dma_opt_mapping_size() is strictly less than dma_max_mapping_size(), indicating a genuine DMA optimization constraint.
The helper computes min(opt_sectors, max_sectors) first, then rounds down to a power of two so that filesystem geometry calculations always produce clean results.
When the two DMA values are equal, no backend provided a real hint, so opt_sectors stays at 0 ("no preference").
[mkp: implemented hch's suggestion]
--- drivers/scsi/scsi_transport_sas.c | 41 +++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-)
drivers/scsi/scsi_transport_sas.c +36 -5
@@ -27,6 +27,7 @@#include <linux/module.h> #include <linux/jiffies.h> #include <linux/err.h> +#include <linux/log2.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/blkdev.h>
@@ -220,12 +221,45 @@ static int sas_bsg_initialize(struct Scs* SAS host attributes */ +/* +* Set shost->opt_sectors from the DMA optimal mapping size, but only +* when dma_opt_mapping_size() is strictly less than dma_max_mapping_size(), +* indicating a genuine optimization hint from an IOMMU or DMA backend. +* When the two are equal (e.g. IOMMU disabled / passthrough), no real +* hint exists, so leave opt_sectors at 0 to avoid bogus optimal_io_size +* values that break filesystem geometry (e.g. mkfs.xfs stripe alignment). +*/ +static void sas_dma_setup_opt_sectors (struct Scsi_Host *shost) +{ +struct device *dma_dev = shost->dma_dev; +size_t opt =dma_opt_mapping_size (dma_dev); +size_t max =dma_max_mapping_size (dma_dev); +unsigned int opt_sectors; + +/* opt >= max means no real hint was provided by the DMA layer */ +if (opt >= max) +return ; + +/* Clamp to max_sectors to avoid overflow in sector arithmetic */ + opt_sectors = min_t(unsigned int, opt >> SECTOR_SHIFT, + shost->max_sectors); + +/* Guard against zero before rounddown_pow_of_two() */ +if (!opt_sectors) +return ; + +/* +* Round down to power-of-two so filesystem geometry calculations +* (e.g. XFS stripe width/unit) always produce clean divisors. +*/ + shost->opt_sectors =rounddown_pow_of_two (opt_sectors); +} +static int sas_host_setup (struct transport_container *tc,struct device *dev,struct device *cdev) {struct Scsi_Host *shost =dev_to_shost (dev);struct sas_host_attrs *sas_host =to_sas_host_attrs (shost); -struct device *dma_dev = shost->dma_dev;INIT_LIST_HEAD (&sas_host->rphy_list);mutex_init (&sas_host->lock);
@@ -237,10 +271,7 @@ static int sas_host_setup(struct transpodev_printk (KERN_ERR , dev,"fail to a bsg device %d\n" , shost->host_no); -if (dma_dev->dma_mask) { - shost->opt_sectors = min_t(unsigned int, shost->max_sectors, -dma_opt_mapping_size (dma_dev) >>SECTOR_SHIFT ); - } +sas_dma_setup_opt_sectors (shost);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 941/1276 ocfs2: use kzalloc for quota recovery bitmap allocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 93c8c6ea90be9e9df8fe14048ad4e3caad0770a6 upstream.
ocfs2 quota recovery allocates a bitmap buffer with kmalloc and does not fully initialize it. This can lead to use of uninitialized bits during quota recovery from a corrupted filesystem image.
Use kzalloc instead to ensure the bitmap is zero-initialized.
--- fs/ocfs2/quota_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/quota_local.c +1 -1
@@ -302,7 +302,7 @@ static int ocfs2_add_recovery_chunk(struif (!rc)return -ENOMEM ; rc->rc_chunk = chunk; - rc->rc_bitmap =kmalloc (sb->s_blocksize,GFP_NOFS ); + rc->rc_bitmap =kzalloc (sb->s_blocksize,GFP_NOFS );if (!rc->rc_bitmap) {kfree (rc);return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 942/1276 mtd: rawnand: pl353: fix probe resource allocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bastien Curutchet <[email protected]>
commit 19ed11aee966d91beebdef9d32ce926474872f79 upstream.
During probe(), the devm_ioremap() is called with the parent device instead of the current one. So when the module is unloaded, the register area isn't released.
Target the pl35x device in the devm_ioremap() instead of its parent.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/pl35x-nand-controller.c +1 -1
@@ -1152,7 +1152,7 @@ static int pl35x_nand_probe(struct platf nfc->controller.ops = &pl35x_nandc_ops;INIT_LIST_HEAD (&nfc->chips); - nfc->conf_regs =devm_ioremap_resource (&smc_amba->dev, &smc_amba->res); + nfc->conf_regs =devm_ioremap_resource (nfc->dev, &smc_amba->res);if (IS_ERR (nfc->conf_regs))return PTR_ERR (nfc->conf_regs);
Greg Kroah-Hartman
maintainerPATCH 943/1276 net/9p: fix infinite loop in p9_client_rpc on fatal signal
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasiliy Kovalev <[email protected]>
commit 6b4f48728faa8bb514368f7eacda05565dea8696 upstream.
When p9_client_rpc() is called with type P9_TFLUSH and the transport has no peer (e.g. fd transport backed by pipes with no 9p server), a fatal signal causes an infinite loop:
again:
err = io_wait_event_killable(req->wq, ...)
/* SIGKILL wakes the task, returns -ERESTARTSYS */
if (err == -ERESTARTSYS && c->status == Connected &&
type == P9_TFLUSH) {
sigpending = 1;
clear_thread_flag(TIF_SIGPENDING);
goto again;
}clear_thread_flag() clears TIF_SIGPENDING before jumping back to io_wait_event_killable(). signal_pending_state() checks TIF_SIGPENDING, finds it zero, and the task goes to sleep again. The task can only wake on the next signal delivery that calls signal_wake_up() and sets TIF_SIGPENDING again. When that happens the loop repeats, clears TIF_SIGPENDING, and sleeps again indefinitely.
This is triggered in practice by coredump_wait(): when a thread in a multi-threaded process causes a coredump (e.g. via SIGSYS from Syscall User Dispatch), coredump_wait() sends SIGKILL to all other threads and waits for them to call mm_release(). If one of those threads is blocked in p9_client_rpc() over an fd transport with no peer, it enters the P9_TFLUSH loop and never calls mm_release(), so coredump_wait() stalls forever:
INFO: task syz.0.18:676 blocked for more than 143 seconds.
Not tainted 6.12.77+ #1
task:syz.0.18 state:D stack:27600 pid:676 tgid:673 ppid:630 flags:0x00000004
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5344 [inline]
__schedule+0xcb4/0x5d50 kernel/sched/core.c:6724
__schedule_loop kernel/sched/core.c:6801 [inline]
schedule+0xe5/0x350 kernel/sched/core.c:6816
schedule_timeout+0x253/0x290 kernel/time/timer.c:2593
do_wait_for_common kernel/sched/completion.c:95 [inline]
__wait_for_common+0x409/0x600 kernel/sched/completion.c:116
wait_for_common kernel/sched/completion.c:127 [inline]
wait_for_completion_state+0x1d/0x40 kernel/sched/completion.c:264
coredump_wait fs/coredump.c:448 [inline]
do_coredump+0x854/0x4350 fs/coredump.c:629
get_signal+0x1425/0x2730 kernel/signal.c:2903
arch_do_signal_or_restart+0x81/0x880 arch/x86/kernel/signal.c:337
exit_to_user_mode_loop kernel/entry/common.c:111 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
syscall_exit_to_user_mode+0xf9/0x160 kernel/entry/common.c:218
do_syscall_64+0x102/0x220 arch/x86/entry/common.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>Fix: check fatal_signal_pending() before clearing TIF_SIGPENDING in the P9_TFLUSH retry loop. At that point TIF_SIGPENDING is still set, so fatal_signal_pending() works correctly. If a fatal signal is pending, jump to recalc_sigpending to restore TIF_SIGPENDING and return -ERESTARTSYS to the caller.
The same defect is present in stable kernels back to 5.4. On those kernels the infinite loop is broken earlier by a second SIGKILL from the parent process (e.g. kill_and_wait() retrying after a timeout), resulting in a zombie process and a shutdown delay rather than a permanent D-state hang, but the underlying flaw is the same.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Message-ID: <[email protected]>
--- net/9p/client.c | 2 ++ 1 file changed, 2 insertions(+)
net/9p/client.c +2 -0
@@ -723,6 +723,8 @@ again:if (err == -ERESTARTSYS && c->status == Connected && type ==P9_TFLUSH ) { +if (fatal_signal_pending (current)) + goto recalc_sigpending; sigpending =1 ;clear_thread_flag (TIF_SIGPENDING ); goto again;
Greg Kroah-Hartman
maintainerPATCH 944/1276 mtd: rawnand: fix condition in nand_select_target()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arseniy Krasnov <[email protected]>
commit 8507c2cc9e4fa402401819f44d1e8a5ef4d11d8b upstream.
'cs' here must be in range [0:nanddev_ntargets[.
--- drivers/mtd/nand/raw/nand_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -174,7 +174,7 @@ void nand_select_target(struct nand_chip* cs should always lie between 0 and nanddev_ntargets(), when that's * not the case it's a bug and the caller should be fixed. */ -if (WARN_ON (cs >nanddev_ntargets (&chip->base))) +if (WARN_ON (cs >=nanddev_ntargets (&chip->base)))return ; chip->cur_cs = cs;
Greg Kroah-Hartman
maintainerPATCH 945/1276 ocfs2: avoid moving extents to occupied clusters
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
commit 22920541c35a9f23f219038ba5874c843a7c4419 upstream.
For non-auto OCFS2_IOC_MOVE_EXT operations, userspace supplies a physical me_goal. ocfs2_move_extent() initializes new_phys_cpos from that goal and expects ocfs2_probe_alloc_group() to replace it with a free run in the target block group.
The probe currently leaves *phys_cpos unchanged if the scan reaches the end of the group without finding a free run. An occupied goal at the last bit can therefore survive the probe and be passed to __ocfs2_move_extent(), which copies file data into a cluster still owned by another inode before the bitmap is updated.
When the probe does find a free run, it also subtracts move_len from the ending bit. The start of an N-bit run ending at i is i - N + 1, so the current calculation can report the bit immediately before the free run.
Clear *phys_cpos before scanning and use the correct free-run start. Callers already treat a zero result as -ENOSPC, so failed probes no longer continue with an occupied caller-controlled goal.
--- fs/ocfs2/move_extents.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ocfs2/move_extents.c +3 -1
@@ -534,6 +534,8 @@ static void ocfs2_probe_alloc_group(struu32 base_cpos =ocfs2_blocks_to_clusters (inode->i_sb,le64_to_cpu (gd->bg_blkno)); + *phys_cpos =0 ; +for (i = base_bit; i <le16_to_cpu (gd->bg_bits); i++) { used =ocfs2_test_bit (i, (unsigned long *)gd->bg_bitmap);
@@ -555,7 +557,7 @@ static void ocfs2_probe_alloc_group(stru last_free_bits++;if (last_free_bits == move_len) { - i -= move_len; + i = i - move_len +1 ; *goal_bit = i; *phys_cpos = base_cpos + i;break ;
Greg Kroah-Hartman
maintainerPATCH 946/1276 ocfs2: fix NULL h_transaction deref in ocfs2_assure_trans_credits
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
commit f9ab30c96b0f00c20c6dac93681bdae3a033d229 upstream.
[BUG]
A direct write over unwritten extents can panic the kernel in ocfs2_assure_trans_credits() when the journal aborts during DIO completion. The crash is a general protection fault from a NULL pointer dereference.
[CAUSE]ocfs2_dio_end_io_write() loops over a direct write's unwritten extents, marking each written under a single journal handle. If the journal aborts (for example after an I/O error) while the extent tree is being updated, the handle is left aborted with its transaction pointer cleared. The extent merge treats that failure as not critical and reports success, so the loop keeps using the handle. ocfs2_assure_trans_credits() reads the handle's remaining credits without first checking whether the handle is aborted, and that read dereferences the cleared transaction pointer.
[FIX]
A journal abort is recorded in the handle itself, so callers are expected to test the handle rather than rely on a returned error. Make ocfs2_assure_trans_credits() do that, as the other ocfs2 journal helpers already do, and return -EROFS when the handle is aborted.
--- fs/ocfs2/journal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ocfs2/journal.c +5 -1
@@ -476,8 +476,12 @@ bail:*/ int ocfs2_assure_trans_credits (handle_t *handle,int nblocks) { -int old_nblks =jbd2_handle_buffer_credits (handle); +int old_nblks; +if (is_handle_aborted (handle)) +return -EROFS ; + + old_nblks =jbd2_handle_buffer_credits (handle);trace_ocfs2_assure_trans_credits (old_nblks);if (old_nblks >= nblocks)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 947/1276 ocfs2: add journal NULL check in ocfs2_checkpoint_inode()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
commit a291c77c034b7a81849ce9b71cc9ecda9e587d89 upstream.
During unmount, ocfs2_journal_shutdown() frees the journal and sets osb->journal to NULL. Later, when VFS evicts remaining cached inodes, ocfs2_evict_inode() -> ocfs2_clear_inode() -> ocfs2_checkpoint_inode() -> ocfs2_ci_fully_checkpointed() dereferences osb->journal, causing a NULL pointer dereference.
Fix this by adding a NULL check for osb->journal in ocfs2_checkpoint_inode(). If the journal is NULL, it has already been fully flushed and destroyed during shutdown, so there is nothing to checkpoint.
--- fs/ocfs2/journal.h | 3 +++ 1 file changed, 3 insertions(+)
fs/ocfs2/journal.h +3 -0
@@ -196,6 +196,9 @@ static inline void ocfs2_checkpoint_inodif (ocfs2_mount_local (osb))return ; +if (!osb->journal) +return ; +if (!ocfs2_ci_fully_checkpointed (INODE_CACHE (inode))) {/* WARNING: This only kicks off a single * checkpoint. If someone races you and adds more
Greg Kroah-Hartman
maintainerPATCH 948/1276 ocfs2: reject dinodes with non-canonical i_mode type
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 5366a017099c6a3c443be908a05f26fd72af12a1 upstream.
Patch series "ocfs2: harden inode validators against forged metadata", v2.
This series adds three structural checks to OCFS2 dinode validation so malformed on-disk fields are rejected before ocfs2_populate_inode() copies them into the in-core inode.
The checks cover:
- i_mode values whose type bits do not name a canonical POSIX file
type;
- non-device dinodes whose id1.dev1.i_rdev field is non-zero; and
- non-inline dinodes that claim non-zero i_size while i_clusters is zero, covering directories unconditionally and regular files on non-sparse volumes.
The normal read path reports these through ocfs2_error(), matching the existing suballoc-slot, inline-data, chain-list, and refcount checks. The online filecheck path uses the same structural predicates but keeps its own reporting contract, returning OCFS2_FILECHECK_ERR_INVALIDINO instead of calling ocfs2_error().
This patch (of 3):
ocfs2_validate_inode_block() currently accepts any non-zero i_mode value. ocfs2_populate_inode() then copies that mode verbatim into inode->i_mode and dispatches on i_mode & S_IFMT to the file/dir/symlink/special_file iops; an unrecognised type falls through to ocfs2_special_file_iops and init_special_inode().
Reject dinodes whose type bits do not name one of the seven canonical POSIX file types. Use fs_umode_to_ftype(), the same generic file-type conversion helper OCFS2 already uses for directory entries, so the accepted inode type set matches the kernel file-type vocabulary instead of open-coding a local switch.
Apply the same structural check to the online filecheck read path. filecheck keeps its own error namespace, so it reports malformed i_mode through the filecheck logger and OCFS2_FILECHECK_ERR_INVALIDINO instead of calling ocfs2_error(), but it must not allow a malformed dinode to proceed into ocfs2_populate_inode().
--- fs/ocfs2/inode.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
fs/ocfs2/inode.c +33 -2
@@ -66,7 +66,12 @@ static int ocfs2_filecheck_read_inode_blstatic int ocfs2_filecheck_validate_inode_block (struct super_block *sb,struct buffer_head *bh);static int ocfs2_filecheck_repair_inode_block (struct super_block *sb, -struct buffer_head *bh); +struct buffer_head *bh); + +static bool ocfs2_valid_inode_mode (umode_t mode) +{ +return fs_umode_to_ftype (mode) !=FT_UNKNOWN ; +}void ocfs2_set_inode_flags (struct inode *inode) {
@@ -1419,6 +1424,24 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* Reject dinodes whose i_mode does not name one of the seven +* canonical POSIX file types. ocfs2_populate_inode() copies +* i_mode verbatim into inode->i_mode and then dispatches via +* switch (mode & S_IFMT) to file/dir/symlink/special_file iops; +* an unrecognised type falls into ocfs2_special_file_iops with +* init_special_inode(), which interprets i_rdev. Constrain the +* type here so the dispatch only ever sees a value mkfs.ocfs2 / +* VFS can produce. +*/ +if (!ocfs2_valid_inode_mode (le16_to_cpu (di->i_mode))) { + rc =ocfs2_error (sb, +"Invalid dinode #%llu: mode 0%o has unknown file type\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1515,6 +1538,15 @@ static int ocfs2_filecheck_validate_inod (unsigned long long )bh->b_blocknr, le32_to_cpu(di->i_fs_generation)); rc = -OCFS2_FILECHECK_ERR_GENERATION ; + goto bail; + } + +if (!ocfs2_valid_inode_mode (le16_to_cpu (di->i_mode))) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: mode 0%o has unknown file type\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
@@ -1692,4 +1724,3 @@ const struct ocfs2_caching_operations oc .co_io_lock = ocfs2_inode_cache_io_lock, .co_io_unlock = ocfs2_inode_cache_io_unlock, }; -
Greg Kroah-Hartman
maintainerPATCH 949/1276 ocfs2: reject dinodes whose i_rdev disagrees with the file type
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 51407c2d249987a466416890a5c931a2354a46aa upstream.
id1.dev1.i_rdev is the device-number arm of the ocfs2_dinode id1 union. It is only meaningful for character and block device inodes. For any other user-visible file type the on-disk value must be zero.
ocfs2_populate_inode() currently copies id1.dev1.i_rdev into inode->i_rdev before the S_IFMT switch decides whether the inode is a special file. A non-device inode with a non-zero i_rdev can therefore publish stale or attacker-controlled device state into the in-core inode.
System inodes legitimately use other arms of the same union, so keep the cross-check restricted to non-system inodes. Factor that predicate into a helper and use it in both the normal validator and online filecheck path; filecheck reports the malformed dinode through OCFS2_FILECHECK_ERR_INVALIDINO instead of ocfs2_error().
--- fs/ocfs2/inode.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
fs/ocfs2/inode.c +55 -0
@@ -73,6 +73,16 @@ static bool ocfs2_valid_inode_mode(umodereturn fs_umode_to_ftype (mode) !=FT_UNKNOWN ; } +static bool ocfs2_dinode_has_unexpected_rdev (struct ocfs2_dinode *di) +{ +umode_t mode =le16_to_cpu (di->i_mode); + +if (le32_to_cpu (di->i_flags) &OCFS2_SYSTEM_FL ) +return false; + +return !S_ISCHR (mode) && !S_ISBLK (mode) && di->id1.dev1.i_rdev !=0 ; +} +void ocfs2_set_inode_flags (struct inode *inode) {unsigned int flags =OCFS2_I (inode)->ip_attr;
@@ -1442,6 +1452,41 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* id1.dev1.i_rdev is the device-number arm of the id1 union and +* is only meaningful for character and block device inodes. For +* any other regular user-visible file type the on-disk value +* must be zero. ocfs2_populate_inode() currently runs +* +* inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev)); +* +* unconditionally, before the S_IFMT switch decides whether the +* inode is a special file. As a result, an i_rdev value present +* on a non-device inode is silently published into the in-core +* inode; a subsequent forced re-read or in-core mode mutation +* (cluster peer with raw write access to the shared LUN, +* on-disk corruption, or a separately forged dinode) can then +* expose the attacker-controlled device number to +* init_special_inode() without ever showing an unusual i_mode +* at validation time. +* +* System inodes (OCFS2_SYSTEM_FL) legitimately use the bitmap1 +* and journal1 arms of the same union (allocator i_used / +* i_total counters and the journal ij_flags / +* ij_recovery_generation pair); those bytes are not an i_rdev +* and must not be checked here. Restrict the cross-check to +* non-system inodes, which is the full attacker-controllable +* surface. +*/ +if (ocfs2_dinode_has_unexpected_rdev (di)) { + rc =ocfs2_error (sb, +"Invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode), + (unsigned long long )le64_to_cpu (di->id1.dev1.i_rdev)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1547,6 +1592,16 @@ static int ocfs2_filecheck_validate_inod (unsigned long long )bh->b_blocknr, le16_to_cpu(di->i_mode)); rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; + goto bail; + } + +if (ocfs2_dinode_has_unexpected_rdev (di)) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode), + (unsigned long long )le64_to_cpu (di->id1.dev1.i_rdev)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
Greg Kroah-Hartman
maintainerPATCH 950/1276 ocfs2: reject non-inline dinodes with i_size and zero i_clusters
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 7ebc672fab7a76e1e47e0f2fc1ee48118d27fde4 upstream.
On a volume mounted without OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC, a non-inline regular file with non-zero i_size and zero i_clusters is structurally malformed: the extent map declares no allocated clusters yet the size header claims content exists. Keep rejecting that shape, but express it through a shared predicate so the same invariant is available to normal inode reads and online filecheck.
The same zero-cluster shape is also malformed for non-inline directories. ocfs2 directory growth allocates backing storage before advancing i_size, and ocfs2_dir_foreach_blk_el() later walks until ctx->pos reaches i_size_read(inode). A forged directory dinode with a huge i_size and no clusters would repeatedly fail on holes while advancing through the claimed size.
Sparse regular files remain exempt: on sparse-alloc volumes, truncate can legitimately grow i_size without allocating clusters. System inodes and inline-data dinodes also retain their separate storage rules.
Mirror the check in ocfs2_filecheck_validate_inode_block() as well. filecheck reports through its own error namespace, so malformed size/cluster state is logged as a filecheck invalid-inode result rather than via ocfs2_error(), but it must not proceed into ocfs2_populate_inode().
--- fs/ocfs2/inode.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
fs/ocfs2/inode.c +60 -0
@@ -83,6 +83,24 @@ static bool ocfs2_dinode_has_unexpected_return !S_ISCHR (mode) && !S_ISBLK (mode) && di->id1.dev1.i_rdev !=0 ; } +static bool ocfs2_dinode_has_size_without_clusters (struct super_block *sb, +struct ocfs2_dinode *di) +{ +umode_t mode =le16_to_cpu (di->i_mode); + +if (le32_to_cpu (di->i_flags) &OCFS2_SYSTEM_FL ) +return false; +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) +return false; +if (!le64_to_cpu (di->i_size) ||le32_to_cpu (di->i_clusters)) +return false; + +if (S_ISDIR (mode)) +return true; + +return !ocfs2_sparse_alloc (OCFS2_SB (sb)) &&S_ISREG (mode); +} +void ocfs2_set_inode_flags (struct inode *inode) {unsigned int flags =OCFS2_I (inode)->ip_attr;
@@ -1487,6 +1505,33 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* Non-inline directories must not have i_size without allocated +* clusters: directory growth adds storage before advancing i_size, +* and readdir walks i_size block-by-block. A forged directory +* with zero clusters and a huge i_size would repeatedly fault on +* holes while advancing through the claimed size. +* +* Non-inline regular files have the same invariant on non-sparse +* volumes. Sparse regular files are different: truncate can +* legitimately grow i_size without allocating clusters, so keep +* the sparse-alloc carveout for S_IFREG only. System inodes and +* inline-data dinodes have their own storage rules. +*/ +if (ocfs2_dinode_has_size_without_clusters (sb, di)) { +if (S_ISDIR (le16_to_cpu (di->i_mode))) + rc =ocfs2_error (sb, +"Invalid dinode #%llu: directory i_size %llu with i_clusters 0 and no inline-data flag\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); +else + rc =ocfs2_error (sb, +"Invalid dinode #%llu: regular file i_size %llu with i_clusters 0 and no inline-data flag on non-sparse volume\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1602,6 +1647,21 @@ static int ocfs2_filecheck_validate_inodle16_to_cpu (di->i_mode), (unsigned long long)le64_to_cpu(di->id1.dev1.i_rdev)); rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; + goto bail; + } + +if (ocfs2_dinode_has_size_without_clusters (sb, di)) { +if (S_ISDIR (le16_to_cpu (di->i_mode))) +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: directory i_size %llu with i_clusters 0 and no inline-data flag\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); +else +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: regular file i_size %llu with i_clusters 0 and no inline-data flag on non-sparse volume\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
Greg Kroah-Hartman
maintainerPATCH 951/1276 fpga: dfl: add bounds check in dfh_get_param_size()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Alba Vives <[email protected]>
commit 9e8bc49f91f3f81d957c4f1c1f09fe94e2f88f6a upstream.
dfh_get_param_size() can return a parameter size larger than the feature region because the loop bounds check is evaluated before incrementing size. If the EOP (End of Parameters) bit is set in the same iteration, the inflated size is returned without re-validation against max.
This can cause create_feature_instance() to call memcpy_fromio() with a size exceeding the ioremap'd region when a malicious FPGA device provides crafted DFHv1 parameter headers.
Add a bounds check after the size increment to ensure the accumulated size never exceeds the feature boundary.
--- drivers/fpga/dfl.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/fpga/dfl.c +2 -0
@@ -1117,6 +1117,8 @@ static int dfh_get_param_size(void __iomreturn -EINVAL ; size += next *sizeof (u64); +if (size > max) +return -EINVAL ;if (FIELD_GET (DFHv1_PARAM_HDR_NEXT_EOP, v))return size;
Greg Kroah-Hartman
maintainerPATCH 952/1276 bus: mhi: ep: Protect mhi_ep_handle_syserr() in the error path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
commit 519ddf194b158b91439319f6b977b8a465fda0fb upstream.
All the callers of mhi_ep_handle_syserr() except mhi_ep_process_cmd_ring() are holding the 'state_lock' to avoid the race in setting the MHI state. So do the same in mhi_ep_process_cmd_ring() for sanity.
--- drivers/bus/mhi/ep/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bus/mhi/ep/main.c +2 -0
@@ -232,7 +232,9 @@ static int mhi_ep_process_cmd_ring(struc ret =mhi_ep_create_device (mhi_cntrl, ch_id);if (ret) {dev_err (dev,"Error creating device for channel (%u)\n" , ch_id); +mutex_lock (&mhi_cntrl->state_lock);mhi_ep_handle_syserr (mhi_cntrl); +mutex_unlock (&mhi_cntrl->state_lock);return ret; } }
Greg Kroah-Hartman
maintainerPATCH 953/1276 net: thunderbolt: Fix frags[] overflow by bounding frame_count
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 55d9895f89970501fe126d1026b586b04a224c27 upstream.
tbnet_poll() assembles a multi-frame ThunderboltIP packet into one skb. The first frame goes into the skb linear area and every further frame is added as a page fragment.
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, hdr_size, frame_size, TBNET_RX_PAGE_SIZE - hdr_size);
A packet of frame_count frames therefore ends up with frame_count - 1 fragments. tbnet_check_frame() only bounds the peer supplied frame_count to TBNET_RING_SIZE / 4 (64), which is far above MAX_SKB_FRAGS (17 by default). A peer that sends a packet of 19 or more small frames pushes nr_frags past MAX_SKB_FRAGS, so skb_add_rx_frag() writes past skb_shinfo()->frags[] and corrupts memory after the shared info.
Tighten the start of packet bound to MAX_SKB_FRAGS + 1 so a packet can never produce more fragments than frags[] can hold. This matches the recent skb frags overflow fixes in other receive paths, for example f0813bcd2d9d ("net:
wwan: t7xx: fix potential skb->frags overflow in RX path") and 600dc40554dc ("net: usb: cdc-phonet: fix skb frags[] overflow in rx_complete()").
--- drivers/net/thunderbolt/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/thunderbolt/main.c +6 -2
@@ -786,8 +786,12 @@ static bool tbnet_check_frame(struct tbnreturn true; } -/* Start of packet, validate the frame header */ -if (frame_count ==0 || frame_count >TBNET_RING_SIZE /4 ) { +/* Start of packet, validate the frame header. tbnet_poll() puts the +* first frame in the skb linear area and every further frame in a page +* fragment, so a packet may not span more than MAX_SKB_FRAGS + 1 frames +* without overflowing skb_shinfo()->frags[]. +*/ +if (frame_count ==0 || frame_count >MAX_SKB_FRAGS +1 ) { net->stats.rx_length_errors++;return false; }
Greg Kroah-Hartman
maintainerPATCH 954/1276 fpga: microchip-spi: fix zero header_size OOB read in mpf_ops_parse_header()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Alba Vives <[email protected]>
commit 43a1974da6bc7ce8f4d1dc1d03d56997428c29c3 upstream.
mpf_ops_parse_header() reads header_size from the bitstream at MPF_HEADER_SIZE_OFFSET (24). When header_size is zero, the expression *(buf + header_size - 1) reads one byte before the buffer start.
Since initial_header_size is set to 71 in mpf_ops, the fpga-mgr core guarantees the buffer is large enough to reach MPF_HEADER_SIZE_OFFSET. The only real gap is the zero header_size case, which cannot be resolved by providing a larger buffer, so return -EINVAL.
--- drivers/fpga/microchip-spi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/fpga/microchip-spi.c +3 -0
@@ -116,6 +116,9 @@ static int mpf_ops_parse_header(struct f } header_size = *(buf +MPF_HEADER_SIZE_OFFSET ); +if (!header_size) +return -EINVAL ; +if (header_size > count) { info->header_size = header_size;return -EAGAIN ;
Greg Kroah-Hartman
maintainerPATCH 955/1276 s390/pkey: Check length in PKEY_VERIFYPROTK ioctl
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Holger Dengler <[email protected]>
commit b3d4ab2d7df9426f7f1d3671d7e2108f2ca6e970 upstream.
Explicitly check the buffer length request structure provided by user-space and fail, if it exceeds the buffer size.
--- drivers/s390/crypto/pkey_api.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/s390/crypto/pkey_api.c +7 -0
@@ -332,6 +332,13 @@ static int pkey_ioctl_verifyprotk(structif (copy_from_user (&kvp, uvp,sizeof (kvp)))return -EFAULT ; +if (kvp.protkey.len >sizeof (kvp.protkey.protkey)) { +PKEY_DBF_ERR ("%s protkey length %u exceeds protkey buffer size\n" , + __func__, kvp.protkey.len); +memzero_explicit (&kvp,sizeof (kvp)); +return -EINVAL ; + } + keytype =pkey_aes_bitsize_to_keytype (8 * kvp.protkey.len);if (!keytype) { PKEY_DBF_ERR("%s unknown/unsupported protkey length %u\n",
Greg Kroah-Hartman
maintainerPATCH 956/1276 s390/pkey: Check length in pkey_pckmo handler implementation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Holger Dengler <[email protected]>
commit 1ac287e2af9a9112fe271427ef45eceb26bce8b4 upstream.
Explicitly check the length of the target buffer in the pkey_pckmo implementation of the key_to_protkey() handler function. The handler function fails, if the generated output data exceeds the length of the provided target buffer.
--- drivers/s390/crypto/pkey_pckmo.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/s390/crypto/pkey_pckmo.c +4 -0
@@ -321,6 +321,10 @@ static int pckmo_key2protkey(const u8 *k __func__, t->keytype); goto out; } +if (t->len > *protkeylen) { + rc = -EINVAL ; + goto out; + }memcpy (protkey, t->protkey, t->len); *protkeylen = t->len; *protkeytype = t->keytype;
Greg Kroah-Hartman
maintainerPATCH 957/1276 mtd: spi-nor: swp: Improve locking user experience
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit e1d456b26bf23e30db305a6184e8abd9ab68bbf2 upstream.
In the case of the first block being locked (or the few first blocks), if the user want to fully unlock the device it has two possibilities:
- either it asks to unlock the entire device, and this works;
- or it asks to unlock just the block(s) that are currently locked, which fails.
It fails because the conditions "can_be_top" and "can_be_bottom" are true. Indeed, in this case, we unlock everything, so the TB bit does not matter. However in the current implementation, use_top would be true (as this is the favourite option) and lock_len, which in practice should be reduced down to 0, is set to "nor->params->size - (ofs + len)" which is a positive number. This is wrong.
An easy way is to simply add an extra condition. In the unlock() path, if we can achieve the same result from both sides, it means we unlock everything and lock_len must simply be 0. A comment is added to clarify that logic.
--- drivers/mtd/spi-nor/swp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/swp.c +9 -2
@@ -281,8 +281,15 @@ static int spi_nor_sr_unlock(struct spi_/* Prefer top, if both are valid */ use_top = can_be_top; -/* lock_len: length of region that should remain locked */ -if (use_top) +/* +* lock_len: length of region that should remain locked. +* +* When can_be_top and can_be_bottom booleans are true, both adjacent +* regions are unlocked, thus the entire flash can be unlocked. +*/ +if (can_be_top && can_be_bottom) + lock_len =0 ; +else if (use_top) lock_len = nor->params->size - (ofs + len);else lock_len = ofs;
Greg Kroah-Hartman
maintainerPATCH 958/1276 mtd: spi-nor: spansion: use die erase for multi-die devices only
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takahiro Kuwano <[email protected]>
commit 306e443156b82a2a14a3f33da908c303be45529c upstream.
Die erase opcode is supported in multi-die devices only. For single die devices, default chip erase opcode must be used.
In s25hx_t_late_init(), die erase opcode is set only when the device is multi-die.
--- drivers/mtd/spi-nor/spansion.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/spansion.c +3 -1
@@ -674,7 +674,9 @@ static int s25hx_t_late_init(struct spi_ params->ready = cypress_nor_sr_ready_and_clear;cypress_nor_ecc_init (nor); - params->die_erase_opcode =SPINOR_OP_CYPRESS_DIE_ERASE ; +if (params->n_dice >1 ) + params->die_erase_opcode =SPINOR_OP_CYPRESS_DIE_ERASE ; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 959/1276 mtd: rawnand: Pause continuous reads at block boundaries
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit 8e4531667d718e2e9b193928cf9b2497fa0d01ef upstream.
Some chips do not support sequential cached reads past block boundaries, like Winbond. In practice when using UBI, this should very rarely happen, but let's make sure it never happens.
--- drivers/mtd/nand/raw/nand_base.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/mtd/nand/raw/nand_base.c +12 -12
@@ -1215,32 +1215,32 @@ static int nand_lp_exec_read_page_op(strreturn nand_exec_op (chip, &op); } -static unsigned int rawnand_last_page_of_lun (unsigned int pages_per_lun,unsigned int lun) +static unsigned int rawnand_last_page_of_block (unsigned int ppb,unsigned int block) { -/* lun is expected to be very small */ -return (lun * pages_per_lun) + pages_per_lun -1 ; +/* block is expected to be very small */ +return (block * ppb) + ppb -1 ; }static void rawnand_cap_cont_reads (struct nand_chip *chip) {struct nand_memory_organization *memorg; -unsigned int ppl, first_lun, last_lun; +unsigned int ppb, first_block, last_block; memorg =nanddev_get_memorg (&chip->base); - ppl = memorg->pages_per_eraseblock * memorg->eraseblocks_per_lun; - first_lun = chip->cont_read.first_page / ppl; - last_lun = chip->cont_read.last_page / ppl; - -/* Prevent sequential cache reads across LUN boundaries */ -if (first_lun != last_lun) - chip->cont_read.pause_page =rawnand_last_page_of_lun (ppl, first_lun); + ppb = memorg->pages_per_eraseblock; + first_block = chip->cont_read.first_page / ppb; + last_block = chip->cont_read.last_page / ppb; + +/* Prevent sequential cache reads across block boundaries */ +if (first_block != last_block) + chip->cont_read.pause_page =rawnand_last_page_of_block (ppb, first_block);else chip->cont_read.pause_page = chip->cont_read.last_page;if (chip->cont_read.first_page == chip->cont_read.pause_page) { chip->cont_read.first_page++; chip->cont_read.pause_page =min (chip->cont_read.last_page, -rawnand_last_page_of_lun (ppl, first_lun +1 )); +rawnand_last_page_of_block (ppb, first_block +1 )); }if (chip->cont_read.first_page >= chip->cont_read.last_page)
Greg Kroah-Hartman
maintainerPATCH 960/1276 mtd: maps: vmu-flash: fix NULL pointer dereference in initialization
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fuchs <[email protected]>
commit 357e3b8e3a8769ba36eb8ec5e053e4825f1a9329 upstream.
The mtd_info contains a struct device, which must be linked to its parent. Without this, the initialization of the MTD fails with a NULL pointer dereference.
--- drivers/mtd/maps/vmu-flash.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/maps/vmu-flash.c +1 -0
@@ -547,6 +547,7 @@ static void vmu_queryblocks(struct maple mpart->partition = card->partition; mtd_cur->priv = mpart; mtd_cur->owner =THIS_MODULE ; + mtd_cur->dev.parent = &mdev->dev; pcache =kzalloc (sizeof (struct vmu_cache ),GFP_KERNEL );if (!pcache)
Greg Kroah-Hartman
maintainerPATCH 961/1276 taskstats: retain dead thread stats in TGID queries
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
commit b3e4fbb04220efc3bc022bcf31b5689d39c6b111 upstream.
Patch series "taskstats: fix TGID dead-thread stat retention", v3.
This series fixes a taskstats TGID aggregation bug where fields added in the TGID query path were not preserved after thread exit, and adds a kselftest covering the regression.
The first patch keeps the cached TGID aggregate used for dead threads in step with the fields already accumulated for live threads, and also fixes the final TGID exit notification emitted when group_dead is true.
The second patch adds a kselftest that verifies TGID CPU stats do not regress after a worker thread exits and has been reaped.
This patch (of 2):
fill_stats_for_tgid() builds TGID stats from two sources: the cached aggregate in signal->stats and a scan of the live threads in the group.
However, fill_tgid_exit() only accumulates delay accounting into signal->stats. This means that once a thread exits, TGID queries lose the fields that fill_stats_for_tgid() adds for live threads.
This gap was introduced incrementally by two earlier changes that extended fill_stats_for_tgid() but did not make the corresponding update to fill_tgid_exit():
- commit 8c733420bdd5 ("taskstats: add e/u/stime for TGID command") added ac_etime, ac_utime, and ac_stime to the TGID query path.
- commit b663a79c1915 ("taskstats: add context-switch counters") added nvcsw and nivcsw to the TGID query path.
As a result, those fields were accounted for live threads in TGID queries, but were dropped from the cached TGID aggregate after thread exit. The final TGID exit notification emitted when group_dead is true also copies that cached aggregate, so it loses the same fields.
Factor the per-task TGID accumulation into tgid_stats_add_task() and use it in both fill_stats_for_tgid() and fill_tgid_exit(). This keeps the cached aggregate used for dead threads aligned with the live-thread accumulation used by TGID queries.
--- kernel/taskstats.c | 62 ++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 29 deletions(-)
kernel/taskstats.c +33 -29
@@ -210,13 +210,39 @@ static int fill_stats_for_pid(pid_t pid,return 0 ; } +static void tgid_stats_add_task (struct taskstats *stats, +struct task_struct *tsk,u64 now_ns) +{ +u64 delta, utime, stime; + +/* +* Each accounting subsystem calls its functions here to +* accumulate its per-task stats for tsk, into the per-tgid structure +* +* per-task-foo(stats, tsk); +*/ +delayacct_add_tsk (stats, tsk); + +/* calculate task elapsed time in nsec */ + delta = now_ns - tsk->start_time; +/* Convert to micro seconds */ +do_div (delta,NSEC_PER_USEC ); + stats->ac_etime += delta; + +task_cputime (tsk, &utime, &stime); + stats->ac_utime +=div_u64 (utime,NSEC_PER_USEC ); + stats->ac_stime +=div_u64 (stime,NSEC_PER_USEC ); + + stats->nvcsw += tsk->nvcsw; + stats->nivcsw += tsk->nivcsw; +} +static int fill_stats_for_tgid (pid_t tgid,struct taskstats *stats) {struct task_struct *tsk, *first;unsigned long flags;int rc = -ESRCH ; -u64 delta, utime, stime; -u64 start_time; +u64 now_ns;/* * Add additional stats from live tasks except zombie thread group
@@ -233,30 +259,12 @@ static int fill_stats_for_tgid(pid_t tgielse memset (stats,0 ,sizeof (*stats)); - start_time =ktime_get_ns (); + now_ns =ktime_get_ns ();for_each_thread (first, tsk) {if (tsk->exit_state)continue ; -/* -* Accounting subsystem can call its functions here to -* fill in relevant parts of struct taskstsats as follows -* -* per-task-foo(stats, tsk); -*/ -delayacct_add_tsk (stats, tsk); - -/* calculate task elapsed time in nsec */ - delta = start_time - tsk->start_time; -/* Convert to micro seconds */ -do_div (delta,NSEC_PER_USEC ); - stats->ac_etime += delta; - -task_cputime (tsk, &utime, &stime); - stats->ac_utime +=div_u64 (utime,NSEC_PER_USEC ); - stats->ac_stime +=div_u64 (stime,NSEC_PER_USEC ); - stats->nvcsw += tsk->nvcsw; - stats->nivcsw += tsk->nivcsw; +tgid_stats_add_task (stats, tsk, now_ns); }unlock_task_sighand (first, &flags);
@@ -275,18 +283,14 @@ out:static void fill_tgid_exit (struct task_struct *tsk) {unsigned long flags; +u64 now_ns;spin_lock_irqsave (&tsk->sighand->siglock, flags);if (!tsk->signal->stats) goto ret; -/* -* Each accounting subsystem calls its functions here to -* accumalate its per-task stats for tsk, into the per-tgid structure -* -* per-task-foo(tsk->signal->stats, tsk); -*/ -delayacct_add_tsk (tsk->signal->stats, tsk); + now_ns =ktime_get_ns (); +tgid_stats_add_task (tsk->signal->stats, tsk, now_ns); ret:spin_unlock_irqrestore (&tsk->sighand->siglock, flags);return ;
Greg Kroah-Hartman
maintainerPATCH 962/1276 irqchip/crossbar: Use correct index in crossbar_domain_free()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bhargav Joshi <[email protected]>
commit 043db005a8d6932dc7d217c86307e9af0bc10ddc upstream.
crossbar_domain_free() resets the domain data and then uses the nulled out irq_data->hwirq member as index to reset the irq_map[] entry and to write the relevant crossbar register with a safe entry. That means it never frees the correct index and keeps the crossbar register connection to the source interrupt active.
If it would not reset the domain data, then this would be even worse as irq_data->hwirq holds the source interrupt number, but both the map and register index need the corresponding GIC SPI number and not the source interrupt number. This might even result in an out of bounds access as the source interrupt number can be higher than the maximal index space.
Fix this by using the GIC SPI index from the parent domain's irq_data.
--- drivers/irqchip/irq-crossbar.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/irqchip/irq-crossbar.c +7 -2
@@ -158,9 +158,14 @@ static void crossbar_domain_free(structfor (i =0 ; i < nr_irqs; i++) {struct irq_data *d =irq_domain_get_irq_data (domain, virq + i); +/* +* irq_map[] is indexed by GIC SPI number. The parent domain's +* hwirq contains the GIC interrupt number (GIC SPI + +* GIC_IRQ_START). +*/ + cb->irq_map[d->parent_data->hwirq -GIC_IRQ_START ] =IRQ_FREE ; + cb->write (d->parent_data->hwirq -GIC_IRQ_START , cb->safe_map);irq_domain_reset_irq_data (d); - cb->irq_map[d->hwirq] =IRQ_FREE ; - cb->write (d->hwirq, cb->safe_map); }raw_spin_unlock (&cb->lock);irq_domain_free_irqs_parent (domain, virq, nr_irqs);
Greg Kroah-Hartman
maintainerPATCH 963/1276 tpm: tpm_tis_spi: Use wait_woken() in wait_for_tmp_stat()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit c0c9cfb3b75def8bf200a2d4db09015806acfeaf upstream.
wait_event_interruptible_timeout() evaluates its condition after setting the current task state to TASK_INTERRUPTIBLE.
With CONFIG_DEBUG_ATOMIC_SLEEP this triggers a warning when the IRQ wait path is used:
tpm_tis_status()
tpm_tis_spi_read_bytes()
tpm_tis_spi_transfer_full()
spi_bus_lock()
mutex_lock()Address this with the following measures:
1. Call wait_tpm_stat_cond() only while tasking is running.
2. Use wait_woken() to wait for changes.
--- drivers/char/tpm/tpm_tis_core.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/char/tpm/tpm_tis_core.c +21 -14
@@ -66,8 +66,8 @@ static int wait_for_tpm_stat(struct tpm_ bool check_cancel) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev); +DEFINE_WAIT_FUNC (wait, woken_wake_function);unsigned long stop; -long rc;u8 status;bool canceled = false;u8 sts_mask;
@@ -87,23 +87,30 @@ static int wait_for_tpm_stat(struct tpm_/* process status changes with irq support */ if (sts_mask) { ret = -ETIME ; +add_wait_queue (queue, &wait); again: +if (wait_for_tpm_stat_cond (chip, sts_mask, check_cancel, + &canceled)) { + ret = canceled ? -ECANCELED :0 ; + goto out; + } + timeout = stop - jiffies;if ((long )timeout <=0 ) -return -ETIME ; - rc =wait_event_interruptible_timeout (*queue, -wait_for_tpm_stat_cond (chip, sts_mask, check_cancel, - &canceled), - timeout); -if (rc >0 ) { -if (canceled) -return -ECANCELED ; - ret =0 ; - } -if (rc == -ERESTARTSYS &&freezing (current)) { -clear_thread_flag (TIF_SIGPENDING ); - goto again; + goto out; + +if (signal_pending (current)) { +if (freezing (current)) { +clear_thread_flag (TIF_SIGPENDING ); + goto again; + } + goto out; } + +wait_woken (&wait,TASK_INTERRUPTIBLE , timeout); + goto again; +out: +remove_wait_queue (queue, &wait); }if (ret)
Greg Kroah-Hartman
maintainerPATCH 964/1276 tpm: tpm2-sessions: wait for async KPP completion in tpm_buf_append_salt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 73851a7c43dfa52d2ed9415889b33daf85da0ed9 upstream.
tpm_buf_append_salt() in drivers/char/tpm/tpm2-sessions.c calls crypto_kpp_generate_public_key() and crypto_kpp_compute_shared_secret() without installing a completion callback, discards both return values, and immediately frees the kpp_request via kpp_request_free(). When the resolved ecdh-nist-p256 KPP backend is asynchronous (atmel-ecc, HPRE, keembay-ocs), either operation returns -EINPROGRESS and the deferred completion worker dereferences the freed request.
The path fires automatically from the hwrng_fillfn kernel thread via tpm_get_random -> tpm2_get_random -> tpm2_start_auth_session -> tpm_buf_append_salt on every entropy poll, without any userland action.
Install crypto_req_done as the completion callback, wrap both KPP operations in crypto_wait_req(), and propagate errors to the caller. The wait is a no-op for synchronous backends.
--- drivers/char/tpm/tpm2-sessions.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-)
drivers/char/tpm/tpm2-sessions.c +34 -11
@@ -534,15 +534,17 @@ static void tpm2_KDFe(u8 z[EC_PT_SZ], cosha256_final (&sctx, out); } -static void tpm_buf_append_salt (struct tpm_buf *buf,struct tpm_chip *chip, -struct tpm2_auth *auth) +static int tpm_buf_append_salt (struct tpm_buf *buf,struct tpm_chip *chip, +struct tpm2_auth *auth) {struct crypto_kpp *kpp;struct kpp_request *req; +DECLARE_CRYPTO_WAIT (wait);struct scatterlist s[2 ], d[1 ];struct ecdh p = {0 };u8 encoded_key[EC_PT_SZ ], *x, *y;unsigned int buf_len; +int rc;/* secret is two sized points */ tpm_buf_append_u16 (buf, (EC_PT_SZ +2 )*2 );
@@ -565,14 +567,15 @@ static void tpm_buf_append_salt(struct t kpp =crypto_alloc_kpp ("ecdh-nist-p256" ,CRYPTO_ALG_INTERNAL ,0 );if (IS_ERR (kpp)) {dev_err (&chip->dev,"crypto ecdh allocation failed\n" ); -return ; +return PTR_ERR (kpp); } buf_len =crypto_ecdh_key_len (&p);if (sizeof (encoded_key) < buf_len) {dev_err (&chip->dev,"salt buffer too small needs %d\n" , buf_len); - goto out; + rc = -EINVAL ; + goto err_free_kpp; }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */
@@ -580,11 +583,17 @@ static void tpm_buf_append_salt(struct t/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL ); -if (!req) - goto out; +if (!req) { + rc = -ENOMEM ; + goto err_free_kpp; + } +kpp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait);kpp_request_set_input (req,NULL ,0 );kpp_request_set_output (req, s,EC_PT_SZ *2 ); -crypto_kpp_generate_public_key (req); + rc =crypto_wait_req (crypto_kpp_generate_public_key (req), &wait); +if (rc) + goto err_free_req;/* * we're not done: now we have to compute the shared secret * which is our private key multiplied by the tpm_key public
@@ -596,8 +605,9 @@ static void tpm_buf_append_salt(struct tkpp_request_set_input (req, s,EC_PT_SZ *2 );sg_init_one (d, auth->salt,EC_PT_SZ );kpp_request_set_output (req, d,EC_PT_SZ ); -crypto_kpp_compute_shared_secret (req); -kpp_request_free (req); + rc =crypto_wait_req (crypto_kpp_compute_shared_secret (req), &wait); +if (rc) + goto err_free_req;/* * pass the shared secret through KDFe for salt. Note salt
@@ -607,8 +617,16 @@ static void tpm_buf_append_salt(struct t*/ tpm2_KDFe (auth->salt,"SECRET" , x, chip->null_ec_key_x, auth->salt); - out: +kpp_request_free (req);crypto_free_kpp (kpp); +return 0 ; + +err_free_req: +kpp_request_free (req); + +err_free_kpp: +crypto_free_kpp (kpp); +return rc; }/**
@@ -1061,7 +1079,12 @@ int tpm2_start_auth_session(struct tpm_ctpm_buf_append (&buf, auth->our_nonce,sizeof (auth->our_nonce));/* append encrypted salt and squirrel away unencrypted in auth */ -tpm_buf_append_salt (&buf, chip, auth); + rc =tpm_buf_append_salt (&buf, chip, auth); +if (rc) { +tpm2_flush_context (chip, null_key); +tpm_buf_destroy (&buf); + goto out; + }/* session type (HMAC, audit or policy) */ tpm_buf_append_u8 (&buf,TPM2_SE_HMAC );