5.15.210-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 268/411 erofs: fix the out-of-bounds nameoff handling for trailing dirents
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gao Xiang <[email protected]>
[ Upstream commit d18a3b5d337fa412a38e776e6b4b857a58836575 ]
Currently we already have boundary-checks for nameoffs, but the trailing dirents are special since the namelens are calculated with strnlen() with unchecked nameoffs.
If a crafted EROFS has a trailing dirent with nameoff >= maxsize, maxsize - nameoff can underflow, causing strnlen() to read past the directory block.
nameoff0 should also be verified to be a multiple of sizeof(struct erofs_dirent) as well [1].
[1] https://sashiko.dev/#/patchset/20260416063511.3173774-1-hsiangkao%40linux.alibaba.com
--- fs/erofs/dir.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
fs/erofs/dir.c +16 -14
@@ -37,20 +37,18 @@ static int erofs_fill_dentries(struct in nameoff =le16_to_cpu (de->nameoff); de_name = (char *)dentry_blk + nameoff; -/* the last dirent in the block? */ -if (de +1 >= end) - de_namelen =strnlen (de_name, maxsize - nameoff); -else +/* non-trailing dirent in the directory block? */ +if (de +1 < end) de_namelen =le16_to_cpu (de[1 ].nameoff) - nameoff; +else if (maxsize <= nameoff) + goto err_bogus; +else + de_namelen =strnlen (de_name, maxsize - nameoff); -/* a corrupted entry is found */ -if (nameoff + de_namelen > maxsize || - de_namelen >EROFS_NAME_LEN ) { -erofs_err (dir->i_sb,"bogus dirent @ nid %llu" , -EROFS_I (dir)->nid); -DBG_BUGON (1 ); -return -EFSCORRUPTED ; - } +/* a corrupted entry is found (including negative namelen) */ +if (!in_range32 (de_namelen,1 ,EROFS_NAME_LEN ) || + nameoff + de_namelen > maxsize) + goto err_bogus;debug_one_dentry (d_type, de_name, de_namelen); if (!dir_emit(ctx, de_name, de_namelen,
@@ -62,6 +60,10 @@ static int erofs_fill_dentries(struct in } *ofs = maxsize;return 0 ; +err_bogus: +erofs_err (dir->i_sb,"bogus dirent @ nid %llu" ,EROFS_I (dir)->nid); +DBG_BUGON (1 ); +return -EFSCORRUPTED ; }static int erofs_readdir (struct file *f,struct dir_context *ctx)
@@ -95,8 +97,8 @@ static int erofs_readdir(struct file *f, nameoff =le16_to_cpu (de->nameoff); -if (nameoff <sizeof (struct erofs_dirent ) || - nameoff >=PAGE_SIZE ) { +if (!nameoff || nameoff >=PAGE_SIZE || + (nameoff %sizeof (struct erofs_dirent ))) {erofs_err (dir->i_sb,"invalid de[0].nameoff %u @ nid %llu" , nameoff,EROFS_I (dir)->nid);
Greg Kroah-Hartman
maintainerPATCH 269/411 nvme: fix interpretation of DMRSL
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Yan <[email protected]>
[ Upstream commit 1a86924e4f464757546d7f7bdc469be237918395 ]
DMRSLl is in the unit of logical blocks, while max_discard_sectors is in the unit of "linux sector".
Stable-dep-of: 40f0496b617b ("nvme: respect NVME_QUIRK_DISABLE_WRITE_ZEROES when wzsl is set")
--- drivers/nvme/host/core.c | 6 ++++-- drivers/nvme/host/nvme.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +4 -2
@@ -1736,6 +1736,9 @@ static void nvme_config_discard(struct gif (blk_queue_flag_test_and_set (QUEUE_FLAG_DISCARD , queue))return ; +if (ctrl->dmrsl && ctrl->dmrsl <=nvme_sect_to_lba (ns,UINT_MAX )) + ctrl->max_discard_sectors =nvme_lba_to_sect (ns, ctrl->dmrsl); +blk_queue_max_discard_sectors (queue, ctrl->max_discard_sectors);blk_queue_max_discard_segments (queue, ctrl->max_discard_segments);
@@ -2948,8 +2951,7 @@ static int nvme_init_non_mdts_limits(strif (id->dmrl) ctrl->max_discard_segments = id->dmrl; -if (id->dmrsl) - ctrl->max_discard_sectors =le32_to_cpu (id->dmrsl); + ctrl->dmrsl =le32_to_cpu (id->dmrsl);if (id->wzsl) ctrl->max_zeroes_sectors =nvme_mps_to_sectors (ctrl, id->wzsl);
drivers/nvme/host/nvme.h +1 -0
@@ -299,6 +299,7 @@ struct nvme_ctrl {#endif u16 crdt[3 ];u16 oncs; +u32 dmrsl;u16 oacs;u16 nssa;u16 nr_streams;
Greg Kroah-Hartman
maintainerPATCH 270/411 nvme: respect NVME_QUIRK_DISABLE_WRITE_ZEROES when wzsl is set
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robert Beckett <[email protected]>
[ Upstream commit 40f0496b617b431f8d2dd94d7f785c1121f8a68a ]
The NVM Command Set Identify Controller data may report a non-zero Write Zeroes Size Limit (wzsl). When present, nvme_init_non_mdts_limits() unconditionally overrides max_zeroes_sectors from wzsl, even if NVME_QUIRK_DISABLE_WRITE_ZEROES previously set it to zero.
This effectively re-enables write zeroes for devices that need it disabled, defeating the quirk. Several Kingston OM* drives rely on this quirk to avoid firmware issues with write zeroes commands.
Check for the quirk before applying the wzsl override.
--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -2952,7 +2952,7 @@ static int nvme_init_non_mdts_limits(strif (id->dmrl) ctrl->max_discard_segments = id->dmrl; ctrl->dmrsl =le32_to_cpu (id->dmrsl); -if (id->wzsl) +if (id->wzsl && !(ctrl->quirks &NVME_QUIRK_DISABLE_WRITE_ZEROES )) ctrl->max_zeroes_sectors =nvme_mps_to_sectors (ctrl, id->wzsl); free_data:
Greg Kroah-Hartman
maintainerPATCH 271/411 media: rc: igorplugusb: heed coherency rules
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
[ Upstream commit eac69475b01fe1e861dfe3960b57fa95671c132e ]
In a control request, the USB request structure can be subject to DMA on some HCs. Hence it must obey the rules for DMA coherency. Allocate it separately.
--- drivers/media/rc/igorplugusb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/media/rc/igorplugusb.c +12 -5
@@ -14,6 +14,7 @@#include <linux/device.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/slab.h> #include <linux/usb.h> #include <linux/usb/input.h> #include <media/rc-core.h>
@@ -34,7 +35,7 @@ struct igorplugusb {struct device *dev;struct urb *urb; -struct usb_ctrlrequest request; +struct usb_ctrlrequest *request;struct timer_list timer;
@@ -123,7 +124,7 @@ static void igorplugusb_cmd(struct igorp {int ret; - ir->request.bRequest = cmd; + ir->request->bRequest = cmd; ir->urb->transfer_flags =0 ; ret =usb_submit_urb (ir->urb,GFP_ATOMIC );if (ret)
@@ -165,13 +166,17 @@ static int igorplugusb_probe(struct usb_if (!ir)return -ENOMEM ; + ir->request =kzalloc (sizeof (*ir->request),GFP_KERNEL ); +if (!ir->request) + goto fail; + ir->dev = &intf->dev;timer_setup (&ir->timer, igorplugusb_timer,0 ); - ir->request.bRequest =GET_INFRACODE ; - ir->request.bRequestType =USB_TYPE_VENDOR |USB_DIR_IN ; - ir->request.wLength =cpu_to_le16 (sizeof (ir->buf_in)); + ir->request->bRequest =GET_INFRACODE ; + ir->request->bRequestType =USB_TYPE_VENDOR |USB_DIR_IN ; + ir->request->wLength =cpu_to_le16 (sizeof (ir->buf_in)); ir->urb =usb_alloc_urb (0 ,GFP_KERNEL );if (!ir->urb)
@@ -223,6 +228,7 @@ fail:rc_free_device (ir->rc);usb_free_urb (ir->urb);del_timer (&ir->timer); +kfree (ir->request);return ret; }
@@ -236,6 +242,7 @@ static void igorplugusb_disconnect(strucusb_set_intfdata (intf,NULL );usb_kill_urb (ir->urb);usb_free_urb (ir->urb); +kfree (ir->request); }static const struct usb_device_id igorplugusb_table[] = {
Greg Kroah-Hartman
maintainerPATCH 272/411 sched: Use u64 for bandwidth ratio calculations
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Salisbury <[email protected]>
[ Upstream commit c6e80201e057dfb7253385e60bf541121bf5dc33 ]
to_ratio() computes BW_SHIFT-scaled bandwidth ratios from u64 period and runtime values, but it returns unsigned long. tg_rt_schedulable() also stores the current group limit and the accumulated child sum in unsigned long.
On 32-bit builds, large bandwidth ratios can be truncated and the RT group sum can wrap when enough siblings are present. That can let an overcommitted RT hierarchy pass the schedulability check, and it also narrows the helper result for other callers.
Return u64 from to_ratio() and use u64 for the RT group totals so bandwidth ratios are preserved and compared at full width on both 32-bit and 64-bit builds.
--- kernel/sched/core.c | 2 +- kernel/sched/rt.c | 2 +- kernel/sched/sched.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
kernel/sched/core.c +1 -1
@@ -4491,7 +4491,7 @@ void sched_post_fork(struct task_structuclamp_post_fork (p); } -unsigned long to_ratio (u64 period,u64 runtime) +u64 to_ratio (u64 period,u64 runtime) {if (runtime ==RUNTIME_INF )return BW_UNIT ;
kernel/sched/rt.c +1 -1
@@ -2606,7 +2606,7 @@ static int tg_rt_schedulable(struct task {struct rt_schedulable_data *d = data;struct task_group *child; -unsigned long total, sum =0 ; +u64 total, sum =0 ;u64 period, runtime; period =ktime_to_ns (tg->rt_bandwidth.rt_period);
kernel/sched/sched.h +1 -1
@@ -2340,7 +2340,7 @@ extern void init_dl_inactive_task_timer(#define RATIO_SHIFT 8#define MAX_BW_BITS (64 - BW_SHIFT)#define MAX_BW ((1ULL << MAX_BW_BITS) - 1) -unsigned long to_ratio (u64 period,u64 runtime); +u64 to_ratio (u64 period,u64 runtime);extern void init_entity_runnable_average (struct sched_entity *se);extern void post_init_entity_util_avg (struct task_struct *p);
Greg Kroah-Hartman
maintainerPATCH 273/411 ALSA: core: Fix potential data race at fasync handling
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 8146cd333d235ed32d48bb803fdf743472d7c783 ]
In snd_fasync_work_fn(), which is the offload work for traversing and processing the pending fasync list, the call of kill_fasync() is done outside the snd_fasync_lock for avoiding deadlocks. The problem is that its the references of fasync->on, fasync->signal and fasync->poll are done there also outside the lock. Since these may be modified by snd_kill_fasync() call concurrently from other process, inconsistent values might be passed to kill_fasync(). Although there shouldn't be critical UAF, it's still better to be addressed.
This patch moves the kill_fasync() argument evaluations inside the snd_fasync_lock for avoiding the data races above. The handling in fasync->on flag is optimized in the loop to skip directly.
Also, for more clarity, snd_fasync_free() takes the lock and unlink the pending entry more directly instead of clearing fasync->on flag.
--- sound/core/misc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
sound/core/misc.c +11 -3
@@ -171,14 +171,18 @@ static LIST_HEAD(snd_fasync_list);static void snd_fasync_work_fn (struct work_struct *work) {struct snd_fasync *fasync; +int signal, poll;spin_lock_irq (&snd_fasync_lock);while (!list_empty (&snd_fasync_list)) { fasync = list_first_entry(&snd_fasync_list, struct snd_fasync, list);list_del_init (&fasync->list); +if (!fasync->on) +continue ; + signal = fasync->signal; + poll = fasync->poll;spin_unlock_irq (&snd_fasync_lock); -if (fasync->on) -kill_fasync (&fasync->fasync, fasync->signal, fasync->poll); +kill_fasync (&fasync->fasync, signal, poll);spin_lock_irq (&snd_fasync_lock); }spin_unlock_irq (&snd_fasync_lock);
@@ -234,7 +238,11 @@ void snd_fasync_free(struct snd_fasync * {if (!fasync)return ; - fasync->on =0 ; + +spin_lock_irq (&snd_fasync_lock); +list_del_init (&fasync->list); +spin_unlock_irq (&snd_fasync_lock); +flush_work (&snd_fasync_work);kfree (fasync); }
Greg Kroah-Hartman
maintainerPATCH 274/411 net: qrtr: ns: Limit the maximum number of lookups
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit 5640227d9a21c6a8be249a10677b832e7f40dc55 ]
Current code does no bound checking on the number of lookups a client can perform. Though the code restricts the lookups to local clients, there is still a possibility of a malicious local client sending a flood of NEW_LOOKUP messages over the same socket.
Fix this issue by limiting the maximum number of lookups to 64 globally. Since the nameserver allows only atmost one local observer, this global lookup count will ensure that the lookups stay within the limit.
Note that, limit of 64 is chosen based on the current platform requirements. If requirement changes in the future, this limit can be increased.
--- net/qrtr/ns.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/qrtr/ns.c +14 -0
@@ -21,6 +21,7 @@ static struct {struct socket *sock;struct sockaddr_qrtr bcast_sq;struct list_head lookups; +u32 lookup_count;struct workqueue_struct *workqueue;struct work_struct work;void (*saved_data_ready)(struct sock *sk);
@@ -69,6 +70,11 @@ struct qrtr_node {struct radix_tree_root servers; }; +/* Max lookup limit is chosen based on the current platform requirements. If the +* requirement changes in the future, this value can be increased. +*/ +#define QRTR_NS_MAX_LOOKUPS 64 +static struct qrtr_node *node_get (unsigned int node_id) {struct qrtr_node *node;
@@ -457,6 +463,7 @@ static int ctrl_cmd_del_client(struct solist_del (&lookup->li);kfree (lookup); + qrtr_ns.lookup_count--; }/* Remove the server belonging to this port but don't broadcast
@@ -590,6 +597,11 @@ static int ctrl_cmd_new_lookup(struct soif (from->sq_node != qrtr_ns.local_node)return -EINVAL ; +if (qrtr_ns.lookup_count >=QRTR_NS_MAX_LOOKUPS ) { +pr_err_ratelimited ("QRTR client node exceeds max lookup limit!\n" ); +return -ENOSPC ; + } + lookup =kzalloc (sizeof (*lookup),GFP_KERNEL );if (!lookup)return -ENOMEM ;
@@ -598,6 +610,7 @@ static int ctrl_cmd_new_lookup(struct so lookup->service = service; lookup->instance = instance;list_add_tail (&lookup->li, &qrtr_ns.lookups); + qrtr_ns.lookup_count++;memset (&filter,0 ,sizeof (filter)); filter.service = service;
@@ -664,6 +677,7 @@ static void ctrl_cmd_del_lookup(struct slist_del (&lookup->li);kfree (lookup); + qrtr_ns.lookup_count--; } }
Greg Kroah-Hartman
maintainerPATCH 275/411 net: qrtr: ns: Change servers radix tree to xarray
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vignesh Viswanathan <[email protected]>
[ Upstream commit 608a147a88728f84bbd2efdde3d4984339f1d872 ]
There is a use after free scenario while iterating through the servers radix tree despite the ns being a single threaded process. This can happen when the radix tree APIs are not synchronized with the rcu_read_lock() APIs.
Convert the radix tree for servers to xarray to take advantage of the built in rcu lock usage provided by xarray.
Stable-dep-of: 68efba36446a ("net: qrtr: ns: Free the node during ctrl_cmd_bye()")
--- net/qrtr/ns.c | 133 ++++++++++------------------------------------------------ 1 file changed, 24 insertions(+), 109 deletions(-)
net/qrtr/ns.c +24 -109
@@ -67,7 +67,7 @@ struct qrtr_server {struct qrtr_node {unsigned int id; -struct radix_tree_root servers; +struct xarray servers; };/* Max lookup limit is chosen based on the current platform requirements. If the
@@ -89,6 +89,7 @@ static struct qrtr_node *node_get(unsignreturn NULL ; node->id = node_id; +xa_init (&node->servers);if (radix_tree_insert (&nodes, node_id, node)) {kfree (node);
@@ -199,40 +200,23 @@ static void lookup_notify(struct sockaddstatic int announce_servers (struct sockaddr_qrtr *sq) { -struct radix_tree_iter iter;struct qrtr_server *srv;struct qrtr_node *node; -void __rcu **slot; +unsigned long index;int ret; node =node_get (qrtr_ns.local_node);if (!node)return 0 ; -rcu_read_lock ();/* Announce the list of servers registered in this node */ -radix_tree_for_each_slot (slot, &node->servers, &iter,0 ) { - srv =radix_tree_deref_slot (slot); -if (!srv) -continue ; -if (radix_tree_deref_retry (srv)) { - slot =radix_tree_iter_retry (&iter); -continue ; - } - slot =radix_tree_iter_resume (slot, &iter); -rcu_read_unlock (); - +xa_for_each (&node->servers, index, srv) { ret =service_announce_new (sq, srv);if (ret <0 ) {pr_err ("failed to announce new service\n" );return ret; } - -rcu_read_lock (); } - -rcu_read_unlock (); -return 0 ; }
@@ -262,14 +246,17 @@ static struct qrtr_server *server_add(un goto err;/* Delete the old server on the same port */ - old =radix_tree_lookup (&node->servers, port); + old =xa_store (&node->servers, port, srv,GFP_KERNEL );if (old) { -radix_tree_delete (&node->servers, port); -kfree (old); +if (xa_is_err (old)) { +pr_err ("failed to add server [0x%x:0x%x] ret:%d\n" , + srv->service, srv->instance,xa_err (old)); + goto err; + }else { +kfree (old); + } } -radix_tree_insert (&node->servers, port, srv); -trace_qrtr_ns_server_add (srv->service, srv->instance, srv->node, srv->port);
@@ -286,11 +273,11 @@ static int server_del(struct qrtr_node *struct qrtr_server *srv;struct list_head *li; - srv =radix_tree_lookup (&node->servers, port); + srv =xa_load (&node->servers, port);if (!srv)return -ENOENT ; -radix_tree_delete (&node->servers, port); +xa_erase (&node->servers, port);/* Broadcast the removal of local servers */ if (srv->node == qrtr_ns.local_node && bcast)
@@ -350,13 +337,12 @@ static int ctrl_cmd_hello(struct sockaddstatic int ctrl_cmd_bye (struct sockaddr_qrtr *from) {struct qrtr_node *local_node; -struct radix_tree_iter iter;struct qrtr_ctrl_pkt pkt;struct qrtr_server *srv;struct sockaddr_qrtr sq;struct msghdr msg = { };struct qrtr_node *node; -void __rcu **slot; +unsigned long index;struct kvec iv;int ret;
@@ -367,22 +353,9 @@ static int ctrl_cmd_bye(struct sockaddr_if (!node)return 0 ; -rcu_read_lock ();/* Advertise removal of this client to all servers of remote node */ -radix_tree_for_each_slot (slot, &node->servers, &iter,0 ) { - srv =radix_tree_deref_slot (slot); -if (!srv) -continue ; -if (radix_tree_deref_retry (srv)) { - slot =radix_tree_iter_retry (&iter); -continue ; - } - slot =radix_tree_iter_resume (slot, &iter); -rcu_read_unlock (); +xa_for_each (&node->servers, index, srv)server_del (node, srv->port, true); -rcu_read_lock (); - } -rcu_read_unlock ();/* Advertise the removal of this client to all local servers */ local_node =node_get (qrtr_ns.local_node);
@@ -393,18 +366,7 @@ static int ctrl_cmd_bye(struct sockaddr_ pkt.cmd =cpu_to_le32 (QRTR_TYPE_BYE ); pkt.client.node =cpu_to_le32 (from->sq_node); -rcu_read_lock (); -radix_tree_for_each_slot (slot, &local_node->servers, &iter,0 ) { - srv =radix_tree_deref_slot (slot); -if (!srv) -continue ; -if (radix_tree_deref_retry (srv)) { - slot =radix_tree_iter_retry (&iter); -continue ; - } - slot =radix_tree_iter_resume (slot, &iter); -rcu_read_unlock (); - +xa_for_each (&local_node->servers, index, srv) { sq.sq_family =AF_QIPCRTR ; sq.sq_node = srv->node; sq.sq_port = srv->port;
@@ -417,11 +379,7 @@ static int ctrl_cmd_bye(struct sockaddr_pr_err ("failed to send bye cmd\n" );return ret; } -rcu_read_lock (); } - -rcu_read_unlock (); -return 0 ; }
@@ -429,7 +387,6 @@ static int ctrl_cmd_del_client(struct so unsigned int node_id, unsigned int port) {struct qrtr_node *local_node; -struct radix_tree_iter iter;struct qrtr_lookup *lookup;struct qrtr_ctrl_pkt pkt;struct msghdr msg = { };
@@ -438,7 +395,7 @@ static int ctrl_cmd_del_client(struct sostruct qrtr_node *node;struct list_head *tmp;struct list_head *li; -void __rcu **slot; +unsigned long index;struct kvec iv;int ret;
@@ -484,18 +441,7 @@ static int ctrl_cmd_del_client(struct so pkt.client.node =cpu_to_le32 (node_id); pkt.client.port =cpu_to_le32 (port); -rcu_read_lock (); -radix_tree_for_each_slot (slot, &local_node->servers, &iter,0 ) { - srv =radix_tree_deref_slot (slot); -if (!srv) -continue ; -if (radix_tree_deref_retry (srv)) { - slot =radix_tree_iter_retry (&iter); -continue ; - } - slot =radix_tree_iter_resume (slot, &iter); -rcu_read_unlock (); - +xa_for_each (&local_node->servers, index, srv) { sq.sq_family =AF_QIPCRTR ; sq.sq_node = srv->node; sq.sq_port = srv->port;
@@ -508,11 +454,7 @@ static int ctrl_cmd_del_client(struct sopr_err ("failed to send del client cmd\n" );return ret; } -rcu_read_lock (); } - -rcu_read_unlock (); -return 0 ; }
@@ -585,13 +527,12 @@ static int ctrl_cmd_del_server(struct sostatic int ctrl_cmd_new_lookup (struct sockaddr_qrtr *from,unsigned int service,unsigned int instance) { -struct radix_tree_iter node_iter;struct qrtr_server_filter filter; -struct radix_tree_iter srv_iter;struct qrtr_lookup *lookup; +struct qrtr_server *srv;struct qrtr_node *node; -void __rcu **node_slot; -void __rcu **srv_slot; +unsigned long node_idx; +unsigned long srv_idx;/* Accept only local observers */ if (from->sq_node != qrtr_ns.local_node)
@@ -616,40 +557,14 @@ static int ctrl_cmd_new_lookup(struct so filter.service = service; filter.instance = instance; -rcu_read_lock (); -radix_tree_for_each_slot (node_slot, &nodes, &node_iter,0 ) { - node =radix_tree_deref_slot (node_slot); -if (!node) -continue ; -if (radix_tree_deref_retry (node)) { - node_slot =radix_tree_iter_retry (&node_iter); -continue ; - } - node_slot =radix_tree_iter_resume (node_slot, &node_iter); - -radix_tree_for_each_slot (srv_slot, &node->servers, - &srv_iter,0 ) { -struct qrtr_server *srv; - - srv =radix_tree_deref_slot (srv_slot); -if (!srv) -continue ; -if (radix_tree_deref_retry (srv)) { - srv_slot =radix_tree_iter_retry (&srv_iter); -continue ; - } - +xa_for_each (&nodes, node_idx, node) { +xa_for_each (&node->servers, srv_idx, srv) {if (!server_match (srv, &filter))continue ; - srv_slot =radix_tree_iter_resume (srv_slot, &srv_iter); - -rcu_read_unlock ();lookup_notify (from, srv, true); -rcu_read_lock (); } } -rcu_read_unlock ();/* Empty notification, to indicate end of listing */ lookup_notify (from,NULL , true);
Greg Kroah-Hartman
maintainerPATCH 276/411 net: qrtr: ns: Free the node during ctrl_cmd_bye()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit 68efba36446a7774ea5b971257ade049272a07ac ]
A node sends the BYE packet when it is about to go down. So the nameserver should advertise the removal of the node to all remote and local observers and free the node finally. But currently, the nameserver doesn't free the node memory even after processing the BYE packet. This causes the node memory to leak.
Hence, remove the node from Xarray list and free the node memory during both success and failure case of ctrl_cmd_bye().
--- net/qrtr/ns.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
net/qrtr/ns.c +15 -5
@@ -344,7 +344,7 @@ static int ctrl_cmd_bye(struct sockaddr_struct qrtr_node *node;unsigned long index;struct kvec iv; -int ret; +int ret =0 ; iv.iov_base = &pkt; iv.iov_len =sizeof (pkt);
@@ -359,8 +359,10 @@ static int ctrl_cmd_bye(struct sockaddr_/* Advertise the removal of this client to all local servers */ local_node =node_get (qrtr_ns.local_node); -if (!local_node) -return 0 ; +if (!local_node) { + ret =0 ; + goto delete_node; + }memset (&pkt,0 ,sizeof (pkt)); pkt.cmd =cpu_to_le32 (QRTR_TYPE_BYE );
@@ -377,10 +379,18 @@ static int ctrl_cmd_bye(struct sockaddr_ ret =kernel_sendmsg (qrtr_ns.sock, &msg, &iv,1 ,sizeof (pkt));if (ret <0 ) {pr_err ("failed to send bye cmd\n" ); -return ret; + goto delete_node; } } -return 0 ; + +/* Ignore -ENODEV */ + ret =0 ; + +delete_node: +xa_erase (&nodes, from->sq_node); +kfree (node); + +return ret; } static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
Greg Kroah-Hartman
maintainerPATCH 277/411 net: mctp: fix dont require received header reserved bits to be zero
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Zhaoming <[email protected]>
[ Upstream commit a663bac71a2f0b3ac6c373168ca57b2a6e6381aa ]
Quoted 1 line
From the MCTP Base specification (DSP0236 v1.2.1), the first byte of
the MCTP header contains a 4 bit reserved field, and 4 bit version.
On our current receive path, we require those 4 reserved bits to be zero, but the 9500-8i card is non-conformant, and may set these reserved bits.
DSP0236 states that the reserved bits must be written as zero, and ignored when read. While the device might not conform to the former, we should accept these message to conform to the latter.
Relax our check on the MCTP version byte to allow non-zero bits in the reserved field.
--- include/net/mctp.h | 3 +++ net/mctp/route.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
include/net/mctp.h +3 -0
@@ -25,6 +25,9 @@ struct mctp_hdr {#define MCTP_VER_MIN 1#define MCTP_VER_MAX 1 +/* Definitions for ver field */ +#define MCTP_HDR_VER_MASK GENMASK(3, 0) +/* Definitions for flags_seq_tag field */ #define MCTP_HDR_FLAG_SOM BIT(7)#define MCTP_HDR_FLAG_EOM BIT(6)
net/mctp/route.c +6 -2
@@ -229,6 +229,7 @@ static int mctp_route_input(struct mctp_unsigned long f;u8 tag, flags;int rc; +u8 ver; msk =NULL ; rc = -EINVAL ;
@@ -246,7 +247,8 @@ static int mctp_route_input(struct mctp_ mh =mctp_hdr (skb);skb_pull (skb,sizeof (struct mctp_hdr )); -if (mh->ver !=1 ) + ver = mh->ver &MCTP_HDR_VER_MASK ; +if (ver <MCTP_VER_MIN || ver >MCTP_VER_MAX ) goto out; flags = mh->flags_seq_tag & (MCTP_HDR_FLAG_SOM |MCTP_HDR_FLAG_EOM );
@@ -859,6 +861,7 @@ static int mctp_pkttype_receive(struct sstruct mctp_skb_cb *cb;struct mctp_route *rt;struct mctp_hdr *mh; +u8 ver;/* basic non-data sanity checks */ if (dev->type !=ARPHRD_MCTP )
@@ -872,7 +875,8 @@ static int mctp_pkttype_receive(struct s/* We have enough for a header; decode and route */ mh =mctp_hdr (skb); -if (mh->ver <MCTP_VER_MIN || mh->ver >MCTP_VER_MAX ) + ver = mh->ver &MCTP_HDR_VER_MASK ; +if (ver <MCTP_VER_MIN || ver >MCTP_VER_MAX ) goto err_drop; cb =__mctp_cb (skb);
Greg Kroah-Hartman
maintainerPATCH 278/411 net: qrtr: ns: Limit the total number of nodes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit 27d5e84e810b0849d08b9aec68e48570461ce313 ]
Currently, the nameserver doesn't limit the number of nodes it handles. This can be an attack vector if a malicious client starts registering random nodes, leading to memory exhaustion.
Hence, limit the maximum number of nodes to 64. Note that, limit of 64 is chosen based on the current platform requirements. If requirement changes in the future, this limit can be increased.
--- net/qrtr/ns.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/qrtr/ns.c +17 -0
@@ -75,6 +75,16 @@ struct qrtr_node {*/ #define QRTR_NS_MAX_LOOKUPS 64 +/* Max nodes, server, lookup limits are chosen based on the current platform +* requirements. If the requirement changes in the future, these values can be +* increased. +*/ +#define QRTR_NS_MAX_NODES 64 +#define QRTR_NS_MAX_SERVERS 256 +#define QRTR_NS_MAX_LOOKUPS 64 + +static u8 node_count; +static struct qrtr_node *node_get (unsigned int node_id) {struct qrtr_node *node;
@@ -83,6 +93,11 @@ static struct qrtr_node *node_get(unsignif (node)return node; +if (node_count >=QRTR_NS_MAX_NODES ) { +pr_err_ratelimited ("QRTR clients exceed max node limit!\n" ); +return NULL ; + } +/* If node didn't exist, allocate and insert it to the tree */ node =kzalloc (sizeof (*node),GFP_KERNEL );if (!node)
@@ -96,6 +111,8 @@ static struct qrtr_node *node_get(unsignreturn NULL ; } + node_count++; +return node; }
Re: [PATCH 5.15 278/411] net: qrtr: ns: Limit the total number of nodes
Hi Sasha and Greg,
Quoted 12 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit
27d5e84e810b0849d08b9aec68e48570461ce313]Currently, the nameserver doesn't limit the number of nodes it handles. This can be an attack vector if a malicious client starts registering random nodes, leading to memory exhaustion.
Quoted 8 lines
Hence, limit the maximum number of nodes to 64. Note that, limit of 64 is chosen based on the current platform requirements. If requirement changes in the future, this limit can be increased.
Fixes 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")Signed-off-by Manivannan Sadhasivam <[email protected]>
I have run an AI assisted backport review and I think what it spotted it accurate.
Please see the analysis below:
Quoted 2 lines
Signed-off-by Jakub Kicinski <[email protected]>[ dropped node_count-- hunk since ctrl_cmd_bye() has no delete_node ]
I think that is added in PATCH 276/411
Upstream 27d5e84e810b increments node_count on successful node creation and then decrements it in ctrl_cmd_bye():
delete_node:
xa_erase(&nodes, from->sq_node);
kfree(node);
node_count--;
return ret;The 5.15.y backport has the limit and the node_count++ on insert, but its ctrl_cmd_bye() delete path still only does:
delete_node:
xa_erase(&nodes, from->sq_node);
kfree(node);
return ret;So every BYE deletion frees the node but leaves node_count elevated. After enough create/delete churn, QRTR nameservice may likely hit the 64-node limit even though the nodes were erased and freed.
I think 5.15.y just needs the missing node_count-- after kfree(node) in ctrl_cmd_bye(), thoughts?
Thanks,
Harshit
Quoted 49 lines
Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/qrtr/ns.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)net/qrtr/ns.c +17
-0@@ -75,6 +75,16 @@ struct qrtr_node {*/ #define QRTR_NS_MAX_LOOKUPS 64 +/* Max nodes, server, lookup limits are chosen based on the current platform +* requirements. If the requirement changes in the future, these values can be +* increased. +*/ +#define QRTR_NS_MAX_NODES 64 +#define QRTR_NS_MAX_SERVERS 256 +#define QRTR_NS_MAX_LOOKUPS 64 + +static u8 node_count; +static struct qrtr_node *node_get (unsigned int node_id) {struct qrtr_node *node;@@ -83,6 +93,11 @@ static struct qrtr_node *node_get(unsignif (node)return node; +if (node_count >=QRTR_NS_MAX_NODES ) { +pr_err_ratelimited ("QRTR clients exceed max node limit!\n" ); +return NULL ; + } +/* If node didn't exist, allocate and insert it to the tree */ node =kzalloc (sizeof (*node),GFP_KERNEL );if (!node)@@ -96,6 +111,8 @@ static struct qrtr_node *node_get(unsignreturn NULL ; } + node_count++; +return node; }
Greg Kroah-Hartman
maintainerPATCH 279/411 net: bridge: use a stable FDB dst snapshot in RCU readers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhengchuan Liang <[email protected]>
[ Upstream commit df4601653201de21b487c3e7fffd464790cab808 ]
Local FDB entries can be rewritten in place by fdb_delete_local(), which updates f->dst to another port or to NULL while keeping the entry alive. Several bridge RCU readers inspect f->dst, including br_fdb_fillbuf() through the brforward_read() sysfs path.
These readers currently load f->dst multiple times and can therefore observe inconsistent values across the check and later dereference. In br_fdb_fillbuf(), this means a concurrent local-FDB update can change f->dst after the NULL check and before the port_no dereference, leading to a NULL-ptr-deref.
Fix this by taking a single READ_ONCE() snapshot of f->dst in each affected RCU reader and using that snapshot for the rest of the access sequence. Also publish the in-place f->dst updates in fdb_delete_local() with WRITE_ONCE() so the readers and writer use matching access patterns.
--- net/bridge/br_arp_nd_proxy.c | 8 +++++--- net/bridge/br_fdb.c | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-)
net/bridge/br_arp_nd_proxy.c +5 -3
@@ -199,11 +199,12 @@ void br_do_proxy_suppress_arp(struct sk_ f =br_fdb_find_rcu (br, n->ha, vid);if (f) { +const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false;if ((p && (p->flags &BR_PROXYARP )) || - (f->dst && (f->dst->flags & (BR_PROXYARP_WIFI | -BR_NEIGH_SUPPRESS )))) { + (dst && (dst->flags & (BR_PROXYARP_WIFI | +BR_NEIGH_SUPPRESS )))) {if (!vid)br_arp_send (br, p, skb->dev, sip, tip, sha, n->ha, sha,0 ,0 );
@@ -463,9 +464,10 @@ void br_do_suppress_nd(struct sk_buff *s f =br_fdb_find_rcu (br, n->ha, vid);if (f) { +const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false; -if (f->dst && (f->dst->flags &BR_NEIGH_SUPPRESS )) { +if (dst && (dst->flags &BR_NEIGH_SUPPRESS )) {if (vid !=0 ) br_nd_send(br, p, skb, n, skb->vlan_proto,
net/bridge/br_fdb.c +18 -10
@@ -121,6 +121,7 @@ struct net_device *br_fdb_find_port(cons const unsigned char *addr, __u16 vid) { +const struct net_bridge_port *dst;struct net_bridge_fdb_entry *f;struct net_device *dev =NULL ;struct net_bridge *br;
@@ -133,8 +134,11 @@ struct net_device *br_fdb_find_port(cons br =netdev_priv (br_dev);rcu_read_lock (); f =br_fdb_find_rcu (br, addr, vid); -if (f && f->dst) - dev = f->dst->dev; +if (f) { + dst =READ_ONCE (f->dst); +if (dst) + dev = dst->dev; + }rcu_read_unlock ();return dev;
@@ -224,7 +228,7 @@ static void fdb_delete_local(struct net_ vg =nbp_vlan_group (op);if (op != p &ðer_addr_equal (op->dev->dev_addr, addr) && (!vid ||br_vlan_find (vg, vid))) { - f->dst = op; +WRITE_ONCE (f->dst, op);clear_bit (BR_FDB_ADDED_BY_USER , &f->flags);return ; }
@@ -235,7 +239,7 @@ static void fdb_delete_local(struct net_/* Maybe bridge device has same hw addr? */ if (p &ðer_addr_equal (br->dev->dev_addr, addr) && (!vid || (v &&br_vlan_should_use (v)))) { - f->dst =NULL ; +WRITE_ONCE (f->dst,NULL );clear_bit (BR_FDB_ADDED_BY_USER , &f->flags);return ; }
@@ -462,6 +466,7 @@ int br_fdb_test_addr(struct net_device *int br_fdb_fillbuf (struct net_bridge *br,void *buf,unsigned long maxnum,unsigned long skip) { +const struct net_bridge_port *dst;struct net_bridge_fdb_entry *f;struct __fdb_entry *fe = buf;int num =0 ;
@@ -477,7 +482,8 @@ int br_fdb_fillbuf(struct net_bridge *brcontinue ;/* ignore pseudo entry for local MAC address */ -if (!f->dst) + dst =READ_ONCE (f->dst); +if (!dst)continue ;if (skip) {
@@ -489,8 +495,8 @@ int br_fdb_fillbuf(struct net_bridge *brmemcpy (fe->mac_addr, f->key.addr.addr,ETH_ALEN );/* due to ABI compat need to split into hi/lo */ - fe->port_no = f->dst->port_no; - fe->port_hi = f->dst->port_no >>8 ; + fe->port_no = dst->port_no; + fe->port_hi = dst->port_no >>8 ; fe->is_local =test_bit (BR_FDB_LOCAL , &f->flags);if (!test_bit (BR_FDB_STATIC , &f->flags))
@@ -836,9 +842,11 @@ int br_fdb_dump(struct sk_buff *skb,rcu_read_lock ();hlist_for_each_entry_rcu (f, &br->fdb_list, fdb_node) { +const struct net_bridge_port *dst =READ_ONCE (f->dst); +if (*idx < cb->args[2 ]) goto skip; -if (filter_dev && (!f->dst || f->dst->dev != filter_dev)) { +if (filter_dev && (!dst || dst->dev != filter_dev)) {if (filter_dev != dev) goto skip;/* !f->dst is a special case for bridge
@@ -846,10 +854,10 @@ int br_fdb_dump(struct sk_buff *skb,* Therefore need a little more filtering * we only want to dump the !f->dst case */ -if (f->dst) +if (dst) goto skip; } -if (!filter_dev && f->dst) +if (!filter_dev && dst) goto skip; err = fdb_fill_info(skb, br, f,
Greg Kroah-Hartman
maintainerPATCH 280/411 fbdev: defio: Disconnect deferred I/O from the lifetime of struct fb_info
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
[ Upstream commit 9ded47ad003f09a94b6a710b5c47f4aa5ceb7429 ]
Hold state of deferred I/O in struct fb_deferred_io_state. Allocate an instance as part of initializing deferred I/O and remove it only after the final mapping has been closed. If the fb_info and the contained deferred I/O meanwhile goes away, clear struct fb_deferred_io_state.info to invalidate the mapping. Any access will then result in a SIGBUS signal.
Fixes a long-standing problem, where a device hot-unplug happens while user space still has an active mapping of the graphics memory. The hot- unplug frees the instance of struct fb_info. Accessing the memory will operate on undefined state.
--- drivers/video/fbdev/core/fb_defio.c | 152 +++++++++++++++++++++++++++++++----- include/linux/fb.h | 4 2 files changed, 138 insertions(+), 18 deletions(-)
drivers/video/fbdev/core/fb_defio.c +135 -17
@@ -23,6 +23,75 @@#include <linux/rmap.h> #include <linux/pagemap.h> +/* +* struct fb_deferred_io_state +*/ + +struct fb_deferred_io_state { +struct kref ref; + +struct mutex lock;/* mutex that protects the pageref list */ +/* fields protected by lock */ +struct fb_info *info; +}; + +static struct fb_deferred_io_state *fb_deferred_io_state_alloc (void ) +{ +struct fb_deferred_io_state *fbdefio_state; + + fbdefio_state =kzalloc (sizeof (*fbdefio_state),GFP_KERNEL ); +if (!fbdefio_state) +return NULL ; + +kref_init (&fbdefio_state->ref); +mutex_init (&fbdefio_state->lock); + +return fbdefio_state; +} + +static void fb_deferred_io_state_release (struct fb_deferred_io_state *fbdefio_state) +{ +mutex_destroy (&fbdefio_state->lock); + +kfree (fbdefio_state); +} + +static void fb_deferred_io_state_get (struct fb_deferred_io_state *fbdefio_state) +{ +kref_get (&fbdefio_state->ref); +} + +static void __fb_deferred_io_state_release (struct kref *ref) +{ +struct fb_deferred_io_state *fbdefio_state = + container_of(ref, struct fb_deferred_io_state, ref); + +fb_deferred_io_state_release (fbdefio_state); +} + +static void fb_deferred_io_state_put (struct fb_deferred_io_state *fbdefio_state) +{ +kref_put (&fbdefio_state->ref, __fb_deferred_io_state_release); +} + +/* +* struct vm_operations_struct +*/ + +static void fb_deferred_io_vm_open (struct vm_area_struct *vma) +{ +struct fb_deferred_io_state *fbdefio_state = vma->vm_private_data; + +fb_deferred_io_state_get (fbdefio_state); +} + +static void fb_deferred_io_vm_close (struct vm_area_struct *vma) +{ +struct fb_deferred_io_state *fbdefio_state = vma->vm_private_data; + +fb_deferred_io_state_put (fbdefio_state); +} +static struct page *fb_deferred_io_page (struct fb_info *info,unsigned long offs) {void *screen_base = (void __force *) info->screen_base;
@@ -93,17 +162,31 @@ static void fb_deferred_io_pageref_put(s/* this is to find and return the vmalloc-ed fb pages */ static vm_fault_t fb_deferred_io_fault (struct vm_fault *vmf) { +struct fb_info *info;unsigned long offset;struct page *page; -struct fb_info *info = vmf->vma->vm_private_data; +vm_fault_t ret; +struct fb_deferred_io_state *fbdefio_state = vmf->vma->vm_private_data; + +mutex_lock (&fbdefio_state->lock); + + info = fbdefio_state->info; +if (!info) { + ret =VM_FAULT_SIGBUS ;/* our device is gone */ + goto err_mutex_unlock; + } offset = vmf->pgoff <<PAGE_SHIFT ; -if (offset >= info->fix.smem_len) -return VM_FAULT_SIGBUS ; +if (offset >= info->fix.smem_len) { + ret =VM_FAULT_SIGBUS ; + goto err_mutex_unlock; + } page =fb_deferred_io_page (info, offset); -if (!page) -return VM_FAULT_SIGBUS ; +if (!page) { + ret =VM_FAULT_SIGBUS ; + goto err_mutex_unlock; + }get_page (page);
@@ -115,8 +198,14 @@ static vm_fault_t fb_deferred_io_fault(sBUG_ON (!page->mapping); page->index = vmf->pgoff;/* for page_mkclean() */ +mutex_unlock (&fbdefio_state->lock); + vmf->page = page;return 0 ; + +err_mutex_unlock: +mutex_unlock (&fbdefio_state->lock); +return ret; }int fb_deferred_io_fsync (struct file *file,loff_t start,loff_t end,int datasync)
@@ -143,8 +232,9 @@ EXPORT_SYMBOL_GPL(fb_deferred_io_fsync);static vm_fault_t fb_deferred_io_mkwrite (struct vm_fault *vmf) {struct page *page = vmf->page; -struct fb_info *info = vmf->vma->vm_private_data; -struct fb_deferred_io *fbdefio = info->fbdefio; +struct fb_deferred_io_state *fbdefio_state = vmf->vma->vm_private_data; +struct fb_info *info; +struct fb_deferred_io *fbdefio;struct fb_deferred_io_pageref *pageref;unsigned long offset;vm_fault_t ret;
@@ -160,7 +250,15 @@ static vm_fault_t fb_deferred_io_mkwritefile_update_time (vmf->vma->vm_file);/* protect against the workqueue changing the page list */ -mutex_lock (&fbdefio->lock); +mutex_lock (&fbdefio_state->lock); + + info = fbdefio_state->info; +if (!info) { + ret =VM_FAULT_SIGBUS ;/* our device is gone */ + goto err_mutex_unlock; + } + + fbdefio = info->fbdefio;/* first write in this cycle, notify the driver */ if (fbdefio->first_io &&list_empty (&fbdefio->pagereflist))
@@ -182,18 +280,20 @@ static vm_fault_t fb_deferred_io_mkwrite*/ lock_page (pageref->page); -mutex_unlock (&fbdefio->lock); +mutex_unlock (&fbdefio_state->lock);/* come back after delay to process the deferred IO */ schedule_delayed_work (&info->deferred_work, fbdefio->delay);return VM_FAULT_LOCKED ; err_mutex_unlock: -mutex_unlock (&fbdefio->lock); +mutex_unlock (&fbdefio_state->lock);return ret; }static const struct vm_operations_struct fb_deferred_io_vm_ops = { + .open = fb_deferred_io_vm_open, + .close = fb_deferred_io_vm_close, .fault = fb_deferred_io_fault, .page_mkwrite = fb_deferred_io_mkwrite, };
@@ -215,7 +315,10 @@ int fb_deferred_io_mmap(struct fb_info * vma->vm_flags |=VM_DONTEXPAND |VM_DONTDUMP ;if (!(info->flags &FBINFO_VIRTFB )) vma->vm_flags |=VM_IO ; - vma->vm_private_data = info; + vma->vm_private_data = info->fbdefio_state; + +fb_deferred_io_state_get (info->fbdefio_state);/* released in vma->vm_ops->close() */ +return 0 ; }
@@ -225,9 +328,10 @@ static void fb_deferred_io_work(struct w struct fb_info *info = container_of(work, struct fb_info, deferred_work.work);struct fb_deferred_io_pageref *pageref, *next;struct fb_deferred_io *fbdefio = info->fbdefio; +struct fb_deferred_io_state *fbdefio_state = info->fbdefio_state;/* here we mkclean the pages, then do all deferred IO */ -mutex_lock (&fbdefio->lock); +mutex_lock (&fbdefio_state->lock);list_for_each_entry (pageref, &fbdefio->pagereflist, list) {struct page *cur = pageref->page;lock_page (cur);
@@ -242,12 +346,13 @@ static void fb_deferred_io_work(struct wlist_for_each_entry_safe (pageref, next, &fbdefio->pagereflist, list)fb_deferred_io_pageref_put (pageref, info); -mutex_unlock (&fbdefio->lock); +mutex_unlock (&fbdefio_state->lock); }int fb_deferred_io_init (struct fb_info *info) {struct fb_deferred_io *fbdefio = info->fbdefio; +struct fb_deferred_io_state *fbdefio_state;struct fb_deferred_io_pageref *pagerefs;unsigned long npagerefs, i;int ret;
@@ -257,7 +362,11 @@ int fb_deferred_io_init(struct fb_info *if (WARN_ON (!info->fix.smem_len))return -EINVAL ; -mutex_init (&fbdefio->lock); + fbdefio_state =fb_deferred_io_state_alloc (); +if (!fbdefio_state) +return -ENOMEM ; + fbdefio_state->info = info; +INIT_DELAYED_WORK (&info->deferred_work, fb_deferred_io_work);INIT_LIST_HEAD (&fbdefio->pagereflist);if (fbdefio->delay ==0 )/* set a default of 1 s */
@@ -276,10 +385,12 @@ int fb_deferred_io_init(struct fb_info * info->npagerefs = npagerefs; info->pagerefs = pagerefs; + info->fbdefio_state = fbdefio_state; +return 0 ; err: -mutex_destroy (&fbdefio->lock); +fb_deferred_io_state_release (fbdefio_state);return ret; }EXPORT_SYMBOL_GPL (fb_deferred_io_init);
@@ -320,11 +431,18 @@ EXPORT_SYMBOL_GPL(fb_deferred_io_releasevoid fb_deferred_io_cleanup (struct fb_info *info) { -struct fb_deferred_io *fbdefio = info->fbdefio; +struct fb_deferred_io_state *fbdefio_state = info->fbdefio_state;fb_deferred_io_lastclose (info); + info->fbdefio_state =NULL ; + +mutex_lock (&fbdefio_state->lock); + fbdefio_state->info =NULL ; +mutex_unlock (&fbdefio_state->lock); + +fb_deferred_io_state_put (fbdefio_state); +kvfree (info->pagerefs); -mutex_destroy (&fbdefio->lock); }EXPORT_SYMBOL_GPL (fb_deferred_io_cleanup);
include/linux/fb.h +3 -1
@@ -213,12 +213,13 @@ struct fb_deferred_io {unsigned long delay;bool sort_pagereflist;/* sort pagelist by offset */ int open_count;/* number of opened files; protected by fb_info lock */ -struct mutex lock;/* mutex that protects the pageref list */ struct list_head pagereflist;/* list of pagerefs for touched pages */ /* callback */ void (*first_io)(struct fb_info *info); void (*deferred_io)(struct fb_info *info, struct list_head *pagelist); }; + +struct fb_deferred_io_state ;#endif /*
@@ -480,6 +481,7 @@ struct fb_info {unsigned long npagerefs;struct fb_deferred_io_pageref *pagerefs;struct fb_deferred_io *fbdefio; +struct fb_deferred_io_state *fbdefio_state;#endif const struct fb_ops *fbops;
Greg Kroah-Hartman
maintainerPATCH 281/411 randomize_kstack: Maintain kstack_offset per task
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Roberts <[email protected]>
[ Upstream commit 37beb42560165869838e7d91724f3e629db64129 ]
kstack_offset was previously maintained per-cpu, but this caused a couple of issues. So let's instead make it per-task.
Issue 1: add_random_kstack_offset() and choose_random_kstack_offset() expected and required to be called with interrupts and preemption disabled so that it could manipulate per-cpu state. But arm64, loongarch and risc-v are calling them with interrupts and preemption enabled. I don't _think_ this causes any functional issues, but it's certainly unexpected and could lead to manipulating the wrong cpu's state, which could cause a minor performance degradation due to bouncing the cache lines. By maintaining the state per-task those functions can safely be called in preemptible context.
Issue 2: add_random_kstack_offset() is called before executing the syscall and expands the stack using a previously chosen random offset. choose_random_kstack_offset() is called after executing the syscall and chooses and stores a new random offset for the next syscall. With per-cpu storage for this offset, an attacker could force cpu migration during the execution of the syscall and prevent the offset from being updated for the original cpu such that it is predictable for the next syscall on that cpu. By maintaining the state per-task, this problem goes away because the per-task random offset is updated after the syscall regardless of which cpu it is executing on.
--- include/linux/randomize_kstack.h | 44 +++++++++++++++++++++++++++++++-------- include/linux/sched.h | 4 +++ init/main.c | 1 kernel/fork.c | 2 + 4 files changed, 42 insertions(+), 9 deletions(-)
include/linux/randomize_kstack.h +36 -8
@@ -8,7 +8,6 @@DECLARE_STATIC_KEY_MAYBE (CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT , randomize_kstack_offset); -DECLARE_PER_CPU (u32, kstack_offset);/* * Do not use this anywhere else in the kernel. This is used here because
@@ -39,28 +38,57 @@ DECLARE_PER_CPU(u32, kstack_offset);*/ #define KSTACK_OFFSET_MAX (x) ((x) & 0x3FF) -/* -* These macros must be used during syscall entry when interrupts and -* preempt are disabled, and after user registers have been stored to -* the stack. +/** +* add_random_kstack_offset - Increase stack utilization by previously +* chosen random offset +* +* This should be used in the syscall entry path after user registers have been +* stored to the stack. Preemption may be enabled. For testing the resulting +* entropy, please see: tools/testing/selftests/lkdtm/stack-entropy.sh */ #define add_random_kstack_offset () do { \ if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \ &randomize_kstack_offset)) { \ - u32 offset = raw_cpu_read(kstack_offset); \ + u32 offset = current->kstack_offset; \ u8 *ptr = __kstack_alloca(KSTACK_OFFSET_MAX(offset)); \/* Keep allocation even after "ptr" loses scope. */ \ asmvolatile ("" ::"r" (ptr) :"memory" ); \ } \ } while (0) +/** +* choose_random_kstack_offset - Choose the random offset for the next +* add_random_kstack_offset() +* +* This should only be used during syscall exit. Preemption may be enabled. This +* position in the syscall flow is done to frustrate attacks from userspace +* attempting to learn the next offset: +* - Maximize the timing uncertainty visible from userspace: if the +* offset is chosen at syscall entry, userspace has much more control +* over the timing between choosing offsets. "How long will we be in +* kernel mode?" tends to be more difficult to predict than "how long +* will we be in user mode?" +* - Reduce the lifetime of the new offset sitting in memory during +* kernel mode execution. Exposure of "thread-local" memory content +* (e.g. current, percpu, etc) tends to be easier than arbitrary +* location memory exposure. + */#define choose_random_kstack_offset (rand) do { \ if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \ &randomize_kstack_offset)) { \ - u32 offset = raw_cpu_read(kstack_offset); \ + u32 offset = current->kstack_offset; \ offset = ror32(offset, 5) ^ (rand); \ - raw_cpu_write(kstack_offset, offset); \ + current->kstack_offset = offset; \ } \ } while (0) +#ifdef CONFIG_HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET +static inline void random_kstack_task_init (struct task_struct *tsk) +{ + tsk->kstack_offset =0 ; +} +#else +#define random_kstack_task_init (tsk) do { } while (0) +#endif +#endif
include/linux/sched.h +4 -0
@@ -1461,6 +1461,10 @@ struct task_struct {unsigned long prev_lowest_stack;#endif +#ifdef CONFIG_HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET +u32 kstack_offset; +#endif +#ifdef CONFIG_X86_MCE void __user *mce_vaddr;__u64 mce_kflags;
init/main.c +0 -1
@@ -882,7 +882,6 @@ static void __init mm_init(void)#ifdef CONFIG_HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET DEFINE_STATIC_KEY_MAYBE_RO (CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT , randomize_kstack_offset); -DEFINE_PER_CPU (u32, kstack_offset);static int __init early_randomize_kstack_offset (char *buf) {
kernel/fork.c +2 -0
@@ -94,6 +94,7 @@#include <linux/thread_info.h> #include <linux/stackleak.h> #include <linux/kasan.h> +#include <linux/randomize_kstack.h> #include <linux/scs.h> #include <linux/io_uring.h> #include <linux/bpf.h>
@@ -2300,6 +2301,7 @@ static __latent_entropy struct task_struif (retval) goto bad_fork_cleanup_io; +random_kstack_task_init (p);stackleak_task_init (p);if (pid != &init_struct_pid) {
Greg Kroah-Hartman
maintainerPATCH 282/411 mmc: sdhci-of-dwcmshc: Disable clock before DLL configuration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Lin <[email protected]>
[ Upstream commit 6546a49bbe656981d99a389195560999058c89c4 ]
According to the ASIC design recommendations, the clock must be disabled before operating the DLL to prevent glitches that could affect the internal digital logic. In extreme cases, failing to do so may cause the controller to malfunction completely.
Adds a step to disable the clock before DLL configuration and re-enables it at the end.
--- drivers/mmc/host/sdhci-of-dwcmshc.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci-of-dwcmshc.c +15 -2
@@ -213,10 +213,13 @@ static void dwcmshc_rk3568_set_clock(str extra &= ~BIT (0 );sdhci_writel (host, extra, reg); +/* Disable clock while config DLL */ +sdhci_writew (host,0 ,SDHCI_CLOCK_CONTROL ); +if (clock <=400000 ) {/* Disable DLL to reset sample clock */ sdhci_writel (host,0 ,DWCMSHC_EMMC_DLL_CTRL ); -return ; + goto enable_clk; }/* Reset DLL */
@@ -234,7 +237,7 @@ static void dwcmshc_rk3568_set_clock(str 500 * USEC_PER_MSEC);if (err) {dev_err (mmc_dev (host->mmc),"DLL lock timeout!\n" ); -return ; + goto enable_clk; } extra = 0x1 << 16 | /* tune clock stop en */
@@ -255,6 +258,16 @@ static void dwcmshc_rk3568_set_clock(strDLL_STRBIN_TAPNUM_DEFAULT |DLL_STRBIN_TAPNUM_FROM_SW ;sdhci_writel (host, extra,DWCMSHC_EMMC_DLL_STRBIN ); + +enable_clk: +/* +* The sdclk frequency select bits in SDHCI_CLOCK_CONTROL are not functional +* on Rockchip's SDHCI implementation. Instead, the clock frequency is fully +* controlled via external clk provider by calling clk_set_rate(). Consequently, +* passing 0 to sdhci_enable_clk() only re-enables the already-configured clock, +* which matches the hardware's actual behavior. +*/ +sdhci_enable_clk (host,0 ); }static void rk35xx_sdhci_reset (struct sdhci_host *host,u8 mask)
Greg Kroah-Hartman
maintainerPATCH 283/411 mtd: spi-nor: sst: Fix write enable before AAI sequence
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanjaikumar V S <[email protected]>
[ Upstream commit a0f64241d3566a49c0a9b33ba7ae458ae22003a9 ]
When writing to SST flash starting at an odd address, a single byte is first programmed using the byte program (BP) command. After this operation completes, the flash hardware automatically clears the Write Enable Latch (WEL) bit.
If an AAI (Auto Address Increment) word program sequence follows, it requires WEL to be set. Without re-enabling writes, the AAI sequence fails.
Add spi_nor_write_enable() after the odd-address byte program when more data needs to be written. Use a local boolean for clarity.
--- drivers/mtd/spi-nor/sst.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/mtd/spi-nor/sst.c +13 -0
@@ -112,6 +112,8 @@ static int sst_write(struct mtd_info *mt/* Start write from odd address. */ if (to %2 ) { +bool needs_write_enable = (len >1 ); + nor->program_opcode =SPINOR_OP_BP ;/* write one byte. */
@@ -125,6 +127,17 @@ static int sst_write(struct mtd_info *mt to++; actual++; + +/* +* Byte program clears the write enable latch. If more +* data needs to be written using the AAI sequence, +* re-enable writes. +*/ +if (needs_write_enable) { + ret =spi_nor_write_enable (nor); +if (ret) + goto out; + } }/* Write out most of the data here. */
Greg Kroah-Hartman
maintainerPATCH 284/411 udf: fix partition descriptor append bookkeeping
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Seohyeon Maeng <[email protected]>
[ Upstream commit 08841b06fa64d8edbd1a21ca6e613420c90cc4b8 ]
Mounting a crafted UDF image with repeated partition descriptors can trigger a heap out-of-bounds write in part_descs_loc[].
handle_partition_descriptor() deduplicates entries by partition number, but appended slots never record partnum. As a result duplicate Partition Descriptors are appended repeatedly and num_part_descs keeps growing.
Once the table is full, the growth path still sizes the allocation from partnum even though inserts are indexed by num_part_descs. If partnum is already aligned to PART_DESC_ALLOC_STEP, ALIGN(partnum, step) can keep the old capacity and the next append writes past the end of the table.
Store partnum in the appended slot and size growth from the next append count so deduplication and capacity tracking follow the same model.
--- fs/udf/super.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/udf/super.c +3 -1
@@ -1658,8 +1658,9 @@ static struct udf_vds_record *handle_parreturn &(data->part_descs_loc[i].rec);if (data->num_part_descs >= data->size_part_descs) {struct part_desc_seq_scan_data *new_loc; -unsigned int new_size =ALIGN (partnum,PART_DESC_ALLOC_STEP ); +unsigned int new_size; + new_size = data->num_part_descs +PART_DESC_ALLOC_STEP ; new_loc =kcalloc (new_size,sizeof (*new_loc),GFP_KERNEL );if (!new_loc)return ERR_PTR (-ENOMEM );
@@ -1669,6 +1670,7 @@ static struct udf_vds_record *handle_par data->part_descs_loc = new_loc; data->size_part_descs = new_size; } + data->part_descs_loc[data->num_part_descs].partnum = partnum;return &(data->part_descs_loc[data->num_part_descs++].rec); }
Greg Kroah-Hartman
maintainerPATCH 285/411 hfsplus: fix uninit-value by validating catalog record size
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Deepanshu Kartikey <[email protected]>
[ Upstream commit b6b592275aeff184aa82fcf6abccd833fb71b393 ]
Syzbot reported a KMSAN uninit-value issue in hfsplus_strcasecmp(). The root cause is that hfs_brec_read() doesn't validate that the on-disk record size matches the expected size for the record type being read.
When mounting a corrupted filesystem, hfs_brec_read() may read less data than expected. For example, when reading a catalog thread record, the debug output showed:
HFSPLUS_BREC_READ: rec_len=520, fd->entrylength=26
HFSPLUS_BREC_READ: WARNING - entrylength (26) < rec_len (520) - PARTIAL READ!
hfs_brec_read() only validates that entrylength is not greater than the buffer size, but doesn't check if it's less than expected. It successfully reads 26 bytes into a 520-byte structure and returns success, leaving 494 bytes uninitialized.
This uninitialized data in tmp.thread.nodeName then gets copied by hfsplus_cat_build_key_uni() and used by hfsplus_strcasecmp(), triggering the KMSAN warning when the uninitialized bytes are used as array indices in case_fold().
Fix by introducing hfsplus_brec_read_cat() wrapper that:
1. Calls hfs_brec_read() to read the data
2. Validates the record size based on the type field:
- Fixed size for folder and file records
- Variable size for thread records (depends on string length)
3. Returns -EIO if size doesn't match expected
For thread records, check against HFSPLUS_MIN_THREAD_SZ before reading nodeName.length to avoid reading uninitialized data at call sites that don't zero-initialize the entry structure.
Also initialize the tmp variable in hfsplus_find_cat() as defensive programming to ensure no uninitialized data even if validation is bypassed.
Stable-dep-of: 90c500e4fd83 ("hfsplus: fix held lock freed on hfsplus_fill_super()")
--- fs/hfsplus/bfind.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/hfsplus/catalog.c | 4 +-- fs/hfsplus/dir.c | 2 - fs/hfsplus/hfsplus_fs.h | 9 ++++++++ fs/hfsplus/super.c | 2 - 5 files changed, 64 insertions(+), 4 deletions(-)
fs/hfsplus/bfind.c +51 -0
@@ -287,3 +287,54 @@ out: fd->bnode = bnode;return res; } + +/** +* hfsplus_brec_read_cat - read and validate a catalog record +* @fd: find data structure +* @entry: pointer to catalog entry to read into +* +* Reads a catalog record and validates its size matches the expected +* size based on the record type. +* +* Returns 0 on success, or negative error code on failure. +*/ +int hfsplus_brec_read_cat (struct hfs_find_data *fd,hfsplus_cat_entry *entry) +{ +int res; +u32 expected_size; + + res =hfs_brec_read (fd, entry,sizeof (hfsplus_cat_entry)); +if (res) +return res; + +/* Validate catalog record size based on type */ +switch (be16_to_cpu (entry->type)) { +case HFSPLUS_FOLDER : + expected_size =sizeof (struct hfsplus_cat_folder ); +break ; +case HFSPLUS_FILE : + expected_size =sizeof (struct hfsplus_cat_file ); +break ; +case HFSPLUS_FOLDER_THREAD : +case HFSPLUS_FILE_THREAD : +/* Ensure we have at least the fixed fields before reading nodeName.length */ +if (fd->entrylength <HFSPLUS_MIN_THREAD_SZ ) { +pr_err ("thread record too short (got %u)\n" , fd->entrylength); +return -EIO ; + } + expected_size =hfsplus_cat_thread_size (&entry->thread); +break ; +default : +pr_err ("unknown catalog record type %d\n" , +be16_to_cpu (entry->type)); +return -EIO ; + } + +if (fd->entrylength != expected_size) { +pr_err ("catalog record size mismatch (type %d, got %u, expected %u)\n" , +be16_to_cpu (entry->type), fd->entrylength, expected_size); +return -EIO ; + } + +return 0 ; +}
fs/hfsplus/catalog.c +2 -2
@@ -194,12 +194,12 @@ static int hfsplus_fill_cat_thread(strucint hfsplus_find_cat (struct super_block *sb,u32 cnid,struct hfs_find_data *fd) { -hfsplus_cat_entry tmp; +hfsplus_cat_entry tmp = {0 };int err;u16 type;hfsplus_cat_build_key_with_cnid (sb, fd->search_key, cnid); - err =hfs_brec_read (fd, &tmp,sizeof (hfsplus_cat_entry)); + err =hfsplus_brec_read_cat (fd, &tmp);if (err)return err;
fs/hfsplus/dir.c +1 -1
@@ -49,7 +49,7 @@ static struct dentry *hfsplus_lookup(strif (unlikely (err <0 )) goto fail; again: - err =hfs_brec_read (&fd, &entry,sizeof (entry)); + err =hfsplus_brec_read_cat (&fd, &entry);if (err) {if (err == -ENOENT ) {hfs_find_exit (&fd);
fs/hfsplus/hfsplus_fs.h +9 -0
@@ -533,6 +533,15 @@ int hfsplus_submit_bio(struct super_bloc void **data, int op, int op_flags);int hfsplus_read_wrapper (struct super_block *sb); +static inline u32 hfsplus_cat_thread_size (const struct hfsplus_cat_thread *thread) +{ +return offsetof(struct hfsplus_cat_thread , nodeName) + + offsetof(struct hfsplus_unistr , unicode) + +be16_to_cpu (thread->nodeName.length) *sizeof (hfsplus_unichr); +} + +int hfsplus_brec_read_cat (struct hfs_find_data *fd,hfsplus_cat_entry *entry); +/* * time helpers: convert between 1904-base and 1970-base timestamps *
fs/hfsplus/super.c +1 -1
@@ -541,7 +541,7 @@ static int hfsplus_fill_super(struct sup err =hfsplus_cat_build_key (sb, fd.search_key,HFSPLUS_ROOT_CNID , &str);if (unlikely (err <0 )) goto out_put_root; -if (!hfs_brec_read (&fd, &entry,sizeof (entry))) { +if (!hfsplus_brec_read_cat (&fd, &entry)) {hfs_find_exit (&fd);if (entry.type !=cpu_to_be16 (HFSPLUS_FOLDER )) { err = -EIO ;
Greg Kroah-Hartman
maintainerPATCH 286/411 hfsplus: fix held lock freed on hfsplus_fill_super()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zilin Guan <[email protected]>
[ Upstream commit 90c500e4fd83fa33c09bc7ee23b6d9cc487ac733 ]
hfsplus_fill_super() calls hfs_find_init() to initialize a search structure, which acquires tree->tree_lock. If the subsequent call to hfsplus_cat_build_key() fails, the function jumps to the out_put_root error label without releasing the lock. The later cleanup path then frees the tree data structure with the lock still held, triggering a held lock freed warning.
Fix this by adding the missing hfs_find_exit(&fd) call before jumping to the out_put_root error label. This ensures that tree->tree_lock is properly released on the error path.
The bug was originally detected on v6.13-rc1 using an experimental static analysis tool we are developing, and we have verified that the issue persists in the latest mainline kernel. The tool is specifically designed to detect memory management issues. It is currently under active development and not yet publicly available.
We confirmed the bug by runtime testing under QEMU with x86_64 defconfig, lockdep enabled, and CONFIG_HFSPLUS_FS=y. To trigger the error path, we used GDB to dynamically shrink the max_unistr_len parameter to 1 before hfsplus_asc2uni() is called. This forces hfsplus_asc2uni() to naturally return -ENAMETOOLONG, which propagates to hfsplus_cat_build_key() and exercises the faulty error path. The following warning was observed during mount:
=========================
WARNING: held lock freed!
7.0.0-rc3-00016-gb4f0dd314b39 #4 Not tainted
-------------------------
mount/174 is freeing memory ffff888103f92000-ffff888103f92fff, with a lock still held there!
ffff888103f920b0 (&tree->tree_lock){+.+.}-{4:4}, at: hfsplus_find_init+0x154/0x1e0
2 locks held by mount/174:
#0: ffff888103f960e0 (&type->s_umount_key#42/1){+.+.}-{4:4}, at: alloc_super.constprop.0+0x167/0xa40
#1: ffff888103f920b0 (&tree->tree_lock){+.+.}-{4:4}, at: hfsplus_find_init+0x154/0x1e0
stack backtrace:
CPU: 2 UID: 0 PID: 174 Comm: mount Not tainted 7.0.0-rc3-00016-gb4f0dd314b39 #4 PREEMPT(lazy)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x82/0xd0
debug_check_no_locks_freed+0x13a/0x180
kfree+0x16b/0x510
? hfsplus_fill_super+0xcb4/0x18a0
hfsplus_fill_super+0xcb4/0x18a0
? __pfx_hfsplus_fill_super+0x10/0x10
? srso_return_thunk+0x5/0x5f
? bdev_open+0x65f/0xc30
? srso_return_thunk+0x5/0x5f
? pointer+0x4ce/0xbf0
? trace_contention_end+0x11c/0x150
? __pfx_pointer+0x10/0x10
? srso_return_thunk+0x5/0x5f
? bdev_open+0x79b/0xc30
? srso_return_thunk+0x5/0x5f
? srso_return_thunk+0x5/0x5f
? vsnprintf+0x6da/0x1270
? srso_return_thunk+0x5/0x5f
? __mutex_unlock_slowpath+0x157/0x740
? __pfx_vsnprintf+0x10/0x10
? srso_return_thunk+0x5/0x5f
? srso_return_thunk+0x5/0x5f
? mark_held_locks+0x49/0x80
? srso_return_thunk+0x5/0x5f
? srso_return_thunk+0x5/0x5f
? irqentry_exit+0x17b/0x5e0
? trace_irq_disable.constprop.0+0x116/0x150
? __pfx_hfsplus_fill_super+0x10/0x10
? __pfx_hfsplus_fill_super+0x10/0x10
get_tree_bdev_flags+0x302/0x580
? __pfx_get_tree_bdev_flags+0x10/0x10
? vfs_parse_fs_qstr+0x129/0x1a0
? __pfx_vfs_parse_fs_qstr+0x3/0x10
vfs_get_tree+0x89/0x320
fc_mount+0x10/0x1d0
path_mount+0x5c5/0x21c0
? __pfx_path_mount+0x10/0x10
? trace_irq_enable.constprop.0+0x116/0x150
? trace_irq_enable.constprop.0+0x116/0x150
? srso_return_thunk+0x5/0x5f
? srso_return_thunk+0x5/0x5f
? kmem_cache_free+0x307/0x540
? user_path_at+0x51/0x60
? __x64_sys_mount+0x212/0x280
? srso_return_thunk+0x5/0x5f
__x64_sys_mount+0x212/0x280
? __pfx___x64_sys_mount+0x10/0x10
? srso_return_thunk+0x5/0x5f
? trace_irq_enable.constprop.0+0x116/0x150
? srso_return_thunk+0x5/0x5f
do_syscall_64+0x111/0x680
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7ffacad55eae
Code: 48 8b 0d 85 1f 0f 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 a5 00 00 8
RSP: 002b:00007fff1ab55718 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ffacad55eae
RDX: 000055740c64e5b0 RSI: 000055740c64e630 RDI: 000055740c651ab0
RBP: 000055740c64e380 R08: 0000000000000000 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000055740c64e5b0 R14: 000055740c651ab0 R15: 000055740c64e380
</TASK>After applying this patch, the warning no longer appears.
--- fs/hfsplus/super.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/hfsplus/super.c +3 -1
@@ -539,8 +539,10 @@ static int hfsplus_fill_super(struct supif (err) goto out_put_root; err =hfsplus_cat_build_key (sb, fd.search_key,HFSPLUS_ROOT_CNID , &str); -if (unlikely (err <0 )) +if (unlikely (err <0 )) { +hfs_find_exit (&fd); goto out_put_root; + }if (!hfsplus_brec_read_cat (&fd, &entry)) {hfs_find_exit (&fd);if (entry.type !=cpu_to_be16 (HFSPLUS_FOLDER )) {
Greg Kroah-Hartman
maintainerPATCH 287/411 Bluetooth: hci_event: fix potential UAF in SSP passkey handlers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuvam Pandey <[email protected]>
[ Upstream commit 85fa3512048793076eef658f66489112dcc91993 ]
hci_conn lookup and field access must be covered by hdev lock in hci_user_passkey_notify_evt() and hci_keypress_notify_evt(), otherwise the connection can be freed concurrently.
Extend the hci_dev_lock critical section to cover all conn usage in both handlers.
Keep the existing keypress notification behavior unchanged by routing the early exits through a common unlock path.
--- net/bluetooth/hci_event.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
net/bluetooth/hci_event.c +14 -4
@@ -4953,9 +4953,11 @@ static void hci_user_passkey_notify_evt(BT_DBG ("%s" , hdev->name); +hci_dev_lock (hdev); + conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr);if (!conn) -return ; + goto unlock; conn->passkey_notify =__le32_to_cpu (ev->passkey); conn->passkey_entered =0 ;
@@ -4964,6 +4966,9 @@ static void hci_user_passkey_notify_evt(mgmt_user_passkey_notify (hdev, &conn->dst, conn->type, conn->dst_type, conn->passkey_notify, conn->passkey_entered); + +unlock: +hci_dev_unlock (hdev); }static void hci_keypress_notify_evt (struct hci_dev *hdev,struct sk_buff *skb)
@@ -4973,14 +4978,16 @@ static void hci_keypress_notify_evt(struBT_DBG ("%s" , hdev->name); +hci_dev_lock (hdev); + conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr);if (!conn) -return ; + goto unlock;switch (ev->type) {case HCI_KEYPRESS_STARTED : conn->passkey_entered =0 ; -return ; + goto unlock;case HCI_KEYPRESS_ENTERED : conn->passkey_entered++;
@@ -4995,13 +5002,16 @@ static void hci_keypress_notify_evt(strubreak ;case HCI_KEYPRESS_COMPLETED : -return ; + goto unlock; }if (hci_dev_test_flag (hdev,HCI_MGMT ))mgmt_user_passkey_notify (hdev, &conn->dst, conn->type, conn->dst_type, conn->passkey_notify, conn->passkey_entered); + +unlock: +hci_dev_unlock (hdev); } static void hci_simple_pair_complete_evt(struct hci_dev *hdev,
Greg Kroah-Hartman
maintainerPATCH 288/411 can: ucan: fix typos in comments
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julia Lawall <[email protected]>
[ Upstream commit c34983c94166689358372d4af8d5def57752860c ]
Various spelling mistakes in comments.
Detected with the help of Coccinelle.
Stable-dep-of: fed4626501c8 ("can: ucan: fix devres lifetime")
--- drivers/net/can/usb/ucan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/ucan.c +2 -2
@@ -1395,7 +1395,7 @@ static int ucan_probe(struct usb_interfa* Stage 3 for the final driver initialisation. */ -/* Prepare Memory for control transferes */ +/* Prepare Memory for control transfers */ ctl_msg_buffer =devm_kzalloc (&udev->dev,sizeof (union ucan_ctl_payload ),GFP_KERNEL );
@@ -1529,7 +1529,7 @@ static int ucan_probe(struct usb_interfa ret =ucan_device_request_in (up,UCAN_DEVICE_GET_FW_STRING ,0 ,sizeof (union ucan_ctl_payload ));if (ret >0 ) { -/* copy string while ensuring zero terminiation */ +/* copy string while ensuring zero termination */ strncpy (firmware_str, up->ctl_msg_buffer->raw,sizeof (union ucan_ctl_payload )); firmware_str[sizeof (union ucan_ctl_payload )] ='\0' ;
Greg Kroah-Hartman
maintainerPATCH 289/411 can: ucan: fix devres lifetime
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit fed4626501c871890da287bec62a96e52da1af89 ]
USB drivers bind to USB interfaces and any device managed resources should have their lifetime tied to the interface rather than parent USB device. This avoids issues like memory leaks when drivers are unbound without their devices being physically disconnected (e.g. on probe deferral or configuration changes).
Fix the control message buffer lifetime so that it is released on driver unbind.
--- drivers/net/can/usb/ucan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/usb/ucan.c +1 -1
@@ -1396,7 +1396,7 @@ static int ucan_probe(struct usb_interfa*/ /* Prepare Memory for control transfers */ - ctl_msg_buffer =devm_kzalloc (&udev->dev, + ctl_msg_buffer =devm_kzalloc (&intf->dev,sizeof (union ucan_ctl_payload ),GFP_KERNEL );if (!ctl_msg_buffer) {
Greg Kroah-Hartman
maintainerPATCH 290/411 crypto: nx - Avoid -Wflex-array-member-not-at-end warning
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Gustavo A. R. Silva" <[email protected]>
[ Upstream commit 1e6b251ce1759392666856908113dd5d7cea044d ]
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. So, we are deprecating flexible-array members in the middle of another structure.
There is currently an object (header) in struct nx842_crypto_ctx that contains a flexible structure (struct nx842_crypto_header):
struct nx842_crypto_ctx {
...
struct nx842_crypto_header header;
struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
...
};So, in order to avoid ending up with a flexible-array member in the middle of another struct, we use the struct_group_tagged() helper to separate the flexible array from the rest of the members in the flexible structure:
struct nx842_crypto_header {
struct_group_tagged(nx842_crypto_header_hdr, hdr,
... the rest of the members
);
struct nx842_crypto_header_group group[];
} __packed;With the change described above, we can now declare an object of the type of the tagged struct, without embedding the flexible array in the middle of another struct:
struct nx842_crypto_ctx {
...
struct nx842_crypto_header_hdr header;
struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
... } __packed;
We also use container_of() whenever we need to retrieve a pointer to the flexible structure, through which we can access the flexible array if needed.
So, with these changes, fix the following warning:
In file included from drivers/crypto/nx/nx-842.c:55:drivers/crypto/nx/nx-842.h:174:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
174 | struct nx842_crypto_header header;
| ^~~~~~
Stable-dep-of: adb3faf2db1a ("crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx")
--- drivers/crypto/nx/nx-842.c | 6 ++++-- drivers/crypto/nx/nx-842.h | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/crypto/nx/nx-842.c +4 -2
@@ -251,7 +251,9 @@ int nx842_crypto_compress(struct crypto_ u8 *dst, unsigned int *dlen) { struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); -struct nx842_crypto_header *hdr = &ctx->header; +struct nx842_crypto_header *hdr = +container_of (&ctx->header, + struct nx842_crypto_header, hdr);struct nx842_crypto_param p;struct nx842_constraints c = *ctx->driver->constraints;unsigned int groups, hdrsize, h;
@@ -490,7 +492,7 @@ int nx842_crypto_decompress(struct crypt }memcpy (&ctx->header, src, hdr_len); - hdr = &ctx->header; + hdr = container_of(&ctx->header, struct nx842_crypto_header, hdr);for (n =0 ; n < hdr->groups; n++) {/* ignore applies to last group */
drivers/crypto/nx/nx-842.h +6 -4
@@ -157,9 +157,11 @@ struct nx842_crypto_header_group { } __packed;struct nx842_crypto_header { -__be16 magic;/* NX842_CRYPTO_MAGIC */ -__be16 ignore;/* decompressed end bytes to ignore */ -u8 groups;/* total groups in this header */ + struct_group_tagged(nx842_crypto_header_hdr, hdr, + __be16 magic; /* NX842_CRYPTO_MAGIC */ +__be16 ignore;/* decompressed end bytes to ignore */ +u8 groups;/* total groups in this header */ + );struct nx842_crypto_header_group group[]; } __packed;
@@ -171,7 +173,7 @@ struct nx842_crypto_ctx {u8 *wmem;u8 *sbounce, *dbounce; -struct nx842_crypto_header header; +struct nx842_crypto_header_hdr header;struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX ];struct nx842_driver *driver;
Greg Kroah-Hartman
maintainerPATCH 291/411 crypto: nx - Migrate to scomp API
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit 980b5705f4e73f567e405cd18337cc32fd51cf79 ]
The only remaining user of 842 compression has been migrated to the acomp compression API, and so the NX hardware driver has to follow suit, given that no users of the obsolete 'comp' API remain, and it is going to be removed.
So migrate the NX driver code to scomp. These will be wrapped and exposed as acomp implementation via the crypto subsystem's acomp-to-scomp adaptation layer.
Stable-dep-of: adb3faf2db1a ("crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx")
--- drivers/crypto/nx/nx-842.c | 33 +++++++++++++++++++-------------- drivers/crypto/nx/nx-842.h | 14 ++++++++------ drivers/crypto/nx/nx-common-powernv.c | 31 +++++++++++++++---------------- drivers/crypto/nx/nx-common-pseries.c | 33 ++++++++++++++++----------------- 4 files changed, 58 insertions(+), 53 deletions(-)
drivers/crypto/nx/nx-842.c +19 -14
@@ -101,9 +101,13 @@ static int update_param(struct nx842_cryreturn 0 ; } -int nx842_crypto_init (struct crypto_tfm *tfm,struct nx842_driver *driver) +void *nx842_crypto_alloc_ctx (struct nx842_driver *driver) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return ERR_PTR (-ENOMEM );spin_lock_init (&ctx->lock); ctx->driver = driver;
@@ -114,22 +118,23 @@ int nx842_crypto_init(struct crypto_tfmkfree (ctx->wmem);free_page ((unsigned long )ctx->sbounce);free_page ((unsigned long )ctx->dbounce); -return -ENOMEM ; +kfree (ctx); +return ERR_PTR (-ENOMEM ); } -return 0 ; +return ctx; } -EXPORT_SYMBOL_GPL (nx842_crypto_init); +EXPORT_SYMBOL_GPL (nx842_crypto_alloc_ctx); -void nx842_crypto_exit (struct crypto_tfm *tfm) +void nx842_crypto_free_ctx (void *p) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx = p;kfree (ctx->wmem);free_page ((unsigned long )ctx->sbounce);free_page ((unsigned long )ctx->dbounce); } -EXPORT_SYMBOL_GPL (nx842_crypto_exit); +EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);static void check_constraints (struct nx842_constraints *c) {
@@ -246,11 +251,11 @@ nospc:return update_param (p, slen, dskip + dlen); } -int nx842_crypto_compress (struct crypto_tfm *tfm, +int nx842_crypto_compress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen) +u8 *dst,unsigned int *dlen,void *pctx) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx = pctx;struct nx842_crypto_header *hdr =container_of (&ctx->header, struct nx842_crypto_header, hdr);
@@ -431,11 +436,11 @@ usesw:return update_param (p, slen + padding, dlen); } -int nx842_crypto_decompress (struct crypto_tfm *tfm, +int nx842_crypto_decompress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen) +u8 *dst,unsigned int *dlen,void *pctx) { -struct nx842_crypto_ctx *ctx =crypto_tfm_ctx (tfm); +struct nx842_crypto_ctx *ctx = pctx;struct nx842_crypto_header *hdr;struct nx842_crypto_param p;struct nx842_constraints c = *ctx->driver->constraints;
drivers/crypto/nx/nx-842.h +8 -6
@@ -101,6 +101,8 @@#define LEN_ON_SIZE (pa, size) ((size) - ((pa) & ((size) - 1)))#define LEN_ON_PAGE (pa) LEN_ON_SIZE(pa, PAGE_SIZE) +struct crypto_scomp ; +static inline unsigned long nx842_get_pa (void *addr) {if (!is_vmalloc_addr (addr))
@@ -179,13 +181,13 @@ struct nx842_crypto_ctx { struct nx842_driver *driver; }; -int nx842_crypto_init (struct crypto_tfm *tfm,struct nx842_driver *driver); -void nx842_crypto_exit (struct crypto_tfm *tfm); -int nx842_crypto_compress (struct crypto_tfm *tfm, +void *nx842_crypto_alloc_ctx (struct nx842_driver *driver); +void nx842_crypto_free_ctx (void *ctx); +int nx842_crypto_compress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen); -int nx842_crypto_decompress (struct crypto_tfm *tfm, +u8 *dst,unsigned int *dlen,void *ctx); +int nx842_crypto_decompress (struct crypto_scomp *tfm,const u8 *src,unsigned int slen, -u8 *dst,unsigned int *dlen); +u8 *dst,unsigned int *dlen,void *ctx);#endif /* __NX_842_H__ */
drivers/crypto/nx/nx-common-powernv.c +15 -16
@@ -9,6 +9,7 @@#include "nx-842.h" +#include <crypto/internal/scompress.h> #include <linux/timer.h> #include <asm/prom.h>
@@ -1034,23 +1035,21 @@ static struct nx842_driver nx842_powernv .decompress = nx842_powernv_decompress, }; -static int nx842_powernv_crypto_init (struct crypto_tfm *tfm) +static void *nx842_powernv_crypto_alloc_ctx (void ) { -return nx842_crypto_init (tfm, &nx842_powernv_driver); +return nx842_crypto_alloc_ctx (&nx842_powernv_driver); } -static struct crypto_alg nx842_powernv_alg = { - .cra_name ="842" , - .cra_driver_name ="842-nx" , - .cra_priority =300 , - .cra_flags =CRYPTO_ALG_TYPE_COMPRESS , - .cra_ctxsize =sizeof (struct nx842_crypto_ctx ), - .cra_module =THIS_MODULE , - .cra_init = nx842_powernv_crypto_init, - .cra_exit = nx842_crypto_exit, - .cra_u = { .compress = { - .coa_compress = nx842_crypto_compress, - .coa_decompress = nx842_crypto_decompress } } +static struct scomp_alg nx842_powernv_alg = { + .base.cra_name ="842" , + .base.cra_driver_name ="842-nx" , + .base.cra_priority =300 , + .base.cra_module =THIS_MODULE , + + .alloc_ctx = nx842_powernv_crypto_alloc_ctx, + .free_ctx = nx842_crypto_free_ctx, + .compress = nx842_crypto_compress, + .decompress = nx842_crypto_decompress, };static __init int nx_compress_powernv_init (void )
@@ -1110,7 +1109,7 @@ static __init int nx_compress_powernv_in nx842_powernv_exec = nx842_exec_vas; } - ret =crypto_register_alg (&nx842_powernv_alg); + ret =crypto_register_scomp (&nx842_powernv_alg);if (ret) {nx_delete_coprocs ();return ret;
@@ -1131,7 +1130,7 @@ static void __exit nx_compress_powernv_eif (!nx842_ct)vas_unregister_api_powernv (); -crypto_unregister_alg (&nx842_powernv_alg); +crypto_unregister_scomp (&nx842_powernv_alg);nx_delete_coprocs (); }
drivers/crypto/nx/nx-common-pseries.c +16 -17
@@ -11,6 +11,7 @@#include <asm/vio.h> #include <asm/hvcall.h> #include <asm/vas.h> +#include <crypto/internal/scompress.h> #include "nx-842.h" #include "nx_csbcpb.h" /* struct nx_csbcpb */
@@ -1006,23 +1007,21 @@ static struct nx842_driver nx842_pseries .decompress = nx842_pseries_decompress, }; -static int nx842_pseries_crypto_init (struct crypto_tfm *tfm) +static void *nx842_pseries_crypto_alloc_ctx (void ) { -return nx842_crypto_init (tfm, &nx842_pseries_driver); +return nx842_crypto_alloc_ctx (&nx842_pseries_driver); } -static struct crypto_alg nx842_pseries_alg = { - .cra_name ="842" , - .cra_driver_name ="842-nx" , - .cra_priority =300 , - .cra_flags =CRYPTO_ALG_TYPE_COMPRESS , - .cra_ctxsize =sizeof (struct nx842_crypto_ctx ), - .cra_module =THIS_MODULE , - .cra_init = nx842_pseries_crypto_init, - .cra_exit = nx842_crypto_exit, - .cra_u = { .compress = { - .coa_compress = nx842_crypto_compress, - .coa_decompress = nx842_crypto_decompress } } +static struct scomp_alg nx842_pseries_alg = { + .base.cra_name ="842" , + .base.cra_driver_name ="842-nx" , + .base.cra_priority =300 , + .base.cra_module =THIS_MODULE , + + .alloc_ctx = nx842_pseries_crypto_alloc_ctx, + .free_ctx = nx842_crypto_free_ctx, + .compress = nx842_crypto_compress, + .decompress = nx842_crypto_decompress, }; static int nx842_probe(struct vio_dev *viodev,
@@ -1070,7 +1069,7 @@ static int nx842_probe(struct vio_dev *vif (ret) goto error; - ret =crypto_register_alg (&nx842_pseries_alg); + ret =crypto_register_scomp (&nx842_pseries_alg);if (ret) {dev_err (&viodev->dev,"could not register comp alg: %d\n" , ret); goto error;
@@ -1118,7 +1117,7 @@ static void nx842_remove(struct vio_devif (caps_feat)sysfs_remove_group (&viodev->dev.kobj, &nxcop_caps_attr_group); -crypto_unregister_alg (&nx842_pseries_alg); +crypto_unregister_scomp (&nx842_pseries_alg);spin_lock_irqsave (&devdata_mutex, flags); old_devdata = rcu_dereference_check(devdata,
@@ -1247,7 +1246,7 @@ static void __exit nx842_pseries_exit(vovas_unregister_api_pseries (); -crypto_unregister_alg (&nx842_pseries_alg); +crypto_unregister_scomp (&nx842_pseries_alg);spin_lock_irqsave (&devdata_mutex, flags); old_devdata = rcu_dereference_check(devdata,
Greg Kroah-Hartman
maintainerPATCH 292/411 crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit adb3faf2db1a66d0f015b44ac909a32dfc7f2f9c ]
The bounce buffers are allocated with __get_free_pages() using BOUNCE_BUFFER_ORDER (order 2 = 4 pages), but both the allocation error path and nx842_crypto_free_ctx() release the buffers with free_page(). Use free_pages() with the matching order instead.
--- drivers/crypto/nx/nx-842.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/nx/nx-842.c +4 -4
@@ -116,8 +116,8 @@ void *nx842_crypto_alloc_ctx(struct nx84 ctx->dbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER );if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER );kfree (ctx);return ERR_PTR (-ENOMEM ); }
@@ -131,8 +131,8 @@ void nx842_crypto_free_ctx(void *p)struct nx842_crypto_ctx *ctx = p;kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); }EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);
Greg Kroah-Hartman
maintainerPATCH 293/411 erofs: fix unsigned underflow in z_erofs_lz4_handle_overlap()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
[ Upstream commit 21e161de2dc660b1bb70ef5b156ab8e6e1cca3ab ]
Some crafted images can have illegal (!partial_decoding && m_llen < m_plen) extents, and the LZ4 inplace decompression path can be wrongly hit, but it cannot handle (outpages < inpages)
properly: "outpages - inpages" wraps to a large value and the subsequent rq->out[] access reads past the decompressed_pages array.
However, such crafted cases can correctly result in a corruption report in the normal LZ4 non-inplace path.
Let's add an additional check to fix this for backporting.
Reproducible image (base64-encoded gzipped blob):
H4sIAJGR12kCA+3SPUoDQRgG4MkmkkZk8QRbRFIIi9hbpEjrHQI5ghfwCN5BLCzTGtLbBI+g dilSJo1CnIm7GEXFxhT6PDDwfrs73/ywIQD/1ePD4r7Ou6ETsrq4mu7XcWfj++Pb58nJU/9i PNtbjhan04/9GtX4qVYc814WDqt6FaX5s+ZwXXeq52lndT6IuVvlblytLMvh4Gzwaf90nsvz 2DF/21+20T/ldgp5s1jXRaN4t/8izsy/OUB6e/Qa79r+JwAAAAAAAL52vQVuGQAAAP6+my1w ywAAAAAAAADwu14ATsEYtgBQAAA=
$ mount -t erofs -o cache_strategy=disabled foo.erofs /mnt $ dd if=/mnt/data of=/dev/null bs=4096 count=1
--- fs/erofs/decompressor.c | 1 + 1 file changed, 1 insertion(+)
fs/erofs/decompressor.c +1 -0
@@ -140,6 +140,7 @@ static void *z_erofs_handle_inplace_io(sif (rq->inplace_io) {if (rq->partial_decoding || !support_0padding || + nrpages_out < nrpages_in || ofull - oend <LZ4_DECOMPRESS_INPLACE_MARGIN (inputsize)) goto docopy;
Greg Kroah-Hartman
maintainerPATCH 294/411 ceph: only d_add() negative dentries when they are unhashed
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Max Kellermann <[email protected]>
[ Upstream commit 803447f93d75ab6e40c85e6d12b5630d281d70d6 ]
Ceph can call d_add(dentry, NULL) on a negative dentry that is already present in the primary dcache hash.
In the current VFS that is not safe. d_add() goes through __d_add() to __d_rehash(), which unconditionally reinserts dentry->d_hash into the hlist_bl bucket. If the dentry is already hashed, reinserting the same node can corrupt the bucket, including creating a self-loop. Once that happens, __d_lookup() can spin forever in the hlist_bl walk, typically looping only on the d_name.hash mismatch check and eventually triggering RCU stall reports like this one:
rcu: INFO: rcu_sched self-detected stall on CPU rcu: 87-....: (2100 ticks this GP) idle=3a4c/1/0x4000000000000000 softirq=25003319/25003319 fqs=829 rcu: (t=2101 jiffies g=79058445 q=698988 ncpus=192) CPU: 87 UID: 2952868916 PID: 3933303 Comm: php-cgi8.3 Not tainted 6.18.17-i1-amd #950 NONE Hardware name: Dell Inc. PowerEdge R7615/0G9DHV, BIOS 1.6.6 09/22/2023 RIP: 0010:__d_lookup+0x46/0xb0 Code: c1 e8 07 48 8d 04 c2 48 8b 00 49 89 fc 49 89 f5 48 89 c3 48 83 e3 fe 48 83 f8 01 77 0f eb 2d 0f 1f 44 00 00 48 8b 1b 48 85 db <74> 20 39 6b 18 75 f3 48 8d 7b 78 e8 ba 85 d0 00 4c 39 63 10 74 1f RSP: 0018:ff745a70c8253898 EFLAGS: 00000282 RAX: ff26e470054cb208 RBX: ff26e470054cb208 RCX: 000000006e958966 RDX: ff26e48267340000 RSI: ff745a70c82539b0 RDI: ff26e458f74655c0 RBP: 000000006e958966 R08: 0000000000000180 R09: 9cd08d909b919a89 R10: ff26e458f74655c0 R11: 0000000000000000 R12: ff26e458f74655c0 R13: ff745a70c82539b0 R14: d0d0d0d0d0d0d0d0 R15: 2f2f2f2f2f2f2f2f FS: 00007f5770896980(0000) GS:ff26e482c5d88000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f5764de50c0 CR3: 000000a72abb5001 CR4: 0000000000771ef0 PKRU: 55555554 Call Trace: <TASK> lookup_fast+0x9f/0x100 walk_component+0x1f/0x150 link_path_walk+0x20e/0x3d0 path_lookupat+0x68/0x180 filename_lookup+0xdc/0x1e0 vfs_statx+0x6c/0x140 vfs_fstatat+0x67/0xa0 __do_sys_newfstatat+0x24/0x60 do_syscall_64+0x6a/0x230 entry_SYSCALL_64_after_hwframe+0x76/0x7e
This is reachable with reused cached negative dentries. A Ceph lookup or atomic_open can be handed a negative dentry that is already hashed, and fs/ceph/dir.c then hits one of two paths that incorrectly assume "negative" also means "unhashed":
- ceph_finish_lookup():
MDS reply is -ENOENT with no trace
-> d_add(dentry, NULL)
- ceph_lookup():
local ENOENT fast path for a complete directory with shared caps -> d_add(dentry, NULL)
Both paths can therefore re-add an already-hashed negative dentry.
Ceph already uses the correct pattern elsewhere: ceph_fill_trace() only calls d_add(dn, NULL) for a negative null-dentry reply when d_unhashed(dn) is true.
Fix both fs/ceph/dir.c sites the same way: only call d_add() for a negative dentry when it is actually unhashed. If the negative dentry is already hashed, leave it in place and reuse it as-is.
This preserves the existing behavior for unhashed dentries while avoiding d_hash list corruption for reused hashed negatives.
--- fs/ceph/dir.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ceph/dir.c +4 -2
@@ -721,7 +721,8 @@ struct dentry *ceph_finish_lookup(structd_drop (dentry); err = -ENOENT ; }else { -d_add (dentry,NULL ); +if (d_unhashed (dentry)) +d_add (dentry,NULL ); } } }
@@ -777,7 +778,8 @@ static struct dentry *ceph_lookup(struct__ceph_touch_fmode (ci, mdsc,CEPH_FILE_MODE_RD );spin_unlock (&ci->i_ceph_lock);dout (" dir %p complete, -ENOENT\n" , dir); -d_add (dentry,NULL ); +if (d_unhashed (dentry)) +d_add (dentry,NULL ); di->lease_shared_gen =atomic_read (&ci->i_shared_gen);return NULL ; }
Greg Kroah-Hartman
maintainerPATCH 295/411 scsi: core: pm: Rely on the device driver core for async power management
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit a19a93e4c6a98c9c0f2f5a6db76846f10d7d1f85 ]
Instead of implementing asynchronous resume support in the SCSI core, rely on the device driver core for resuming SCSI devices asynchronously. Instead of only supporting asynchronous resumes, also support asynchronous suspends.
Stable-dep-of: 1e111c4b3a72 ("scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails")
--- drivers/scsi/hosts.c | 1 + drivers/scsi/scsi.c | 8 -------- drivers/scsi/scsi_pm.c | 44 ++------------------------------------------ drivers/scsi/scsi_priv.h | 4 +--- drivers/scsi/scsi_scan.c | 17 +++++++++++++++++ drivers/scsi/scsi_sysfs.c | 1 + drivers/scsi/sd.c | 1 - 7 files changed, 22 insertions(+), 54 deletions(-)
drivers/scsi/hosts.c +1 -0
@@ -487,6 +487,7 @@ struct Scsi_Host *scsi_host_alloc(structdev_set_name (&shost->shost_gendev,"host%d" , shost->host_no); shost->shost_gendev.bus = &scsi_bus_type; shost->shost_gendev.type = &scsi_host_type; +scsi_enable_async_suspend (&shost->shost_gendev);device_initialize (&shost->shost_dev); shost->shost_dev.parent = &shost->shost_gendev;
drivers/scsi/scsi.c +0 -8
@@ -86,14 +86,6 @@ unsigned int scsi_logging_level;EXPORT_SYMBOL (scsi_logging_level);#endif -/* -* Domain for asynchronous system resume operations. It is marked 'exclusive' -* to avoid being included in the async_synchronize_full() that is invoked by -* dpm_resume(). -*/ -ASYNC_DOMAIN_EXCLUSIVE (scsi_sd_pm_domain); -EXPORT_SYMBOL (scsi_sd_pm_domain); -#ifdef CONFIG_SCSI_LOGGING void scsi_log_send (struct scsi_cmnd *cmd) {
drivers/scsi/scsi_pm.c +2 -42
59 lines not on this page · raw message
drivers/scsi/scsi_priv.h +1 -3
@@ -117,7 +117,7 @@ extern void scsi_exit_procfs(void);#endif /* CONFIG_PROC_FS */ /* scsi_scan.c */ -extern char scsi_scan_type[]; +void scsi_enable_async_suspend (struct device *dev);extern int scsi_complete_async_scans (void );extern int scsi_scan_host_selected (struct Scsi_Host *,unsigned int ,unsigned int ,u64 ,enum scsi_scan_mode );
@@ -171,8 +171,6 @@ static inline int scsi_autopm_get_host(sstatic inline void scsi_autopm_put_host (struct Scsi_Host *h) {}#endif /* CONFIG_PM */ -extern struct async_domain scsi_sd_pm_domain; -/* scsi_dh.c */ #ifdef CONFIG_SCSI_DH void scsi_dh_add_device (struct scsi_device *sdev);
drivers/scsi/scsi_scan.c +17 -0
@@ -123,6 +123,22 @@ struct async_scan_data { };/** +* scsi_enable_async_suspend - Enable async suspend and resume +*/ +void scsi_enable_async_suspend (struct device *dev) +{ +/* +* If a user has disabled async probing a likely reason is due to a +* storage enclosure that does not inject staggered spin-ups. For +* safety, make resume synchronous as well in that case. +*/ +if (strncmp (scsi_scan_type,"async" ,5 ) !=0 ) +return ; +/* Enable asynchronous suspend and resume. */ +device_enable_async_suspend (dev); +} + +/** * scsi_complete_async_scans - Wait for asynchronous scans to complete * * When this function returns, any host which started scanning before
@@ -499,6 +515,7 @@ static struct scsi_target *scsi_alloc_tadev_set_name (dev,"target%d:%d:%d" , shost->host_no, channel, id); dev->bus = &scsi_bus_type; dev->type = &scsi_target_type; +scsi_enable_async_suspend (dev); starget->id = id; starget->channel = channel; starget->can_queue =0 ;
drivers/scsi/scsi_sysfs.c +1 -0
@@ -1643,6 +1643,7 @@ void scsi_sysfs_device_initialize(structdevice_initialize (&sdev->sdev_gendev); sdev->sdev_gendev.bus = &scsi_bus_type; sdev->sdev_gendev.type = &scsi_dev_type; +scsi_enable_async_suspend (&sdev->sdev_gendev);dev_set_name (&sdev->sdev_gendev,"%d:%d:%d:%llu" , sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
drivers/scsi/sd.c +0 -1
@@ -3505,7 +3505,6 @@ static int sd_remove(struct device *dev) sdkp =dev_get_drvdata (dev);scsi_autopm_get_device (sdkp->device); -async_synchronize_full_domain (&scsi_sd_pm_domain);device_del (&sdkp->dev);del_gendisk (sdkp->disk);sd_shutdown (dev);
Greg Kroah-Hartman
maintainerPATCH 296/411 scsi: sd: Add error handling support for add_disk()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luis Chamberlain <[email protected]>
[ Upstream commit 2a7a891f4c406822801ecd676b076c64de072c9e ]
We never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
As with the error handling for device_add() we follow the same logic and just put the device so that cleanup is done via the scsi_disk_release().
Stable-dep-of: 1e111c4b3a72 ("scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails")
--- drivers/scsi/sd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +7 -1
@@ -3458,7 +3458,13 @@ static int sd_probe(struct device *dev)pm_runtime_set_autosuspend_delay (dev, sdp->host->hostt->rpm_autosuspend_delay); } -device_add_disk (dev, gd,NULL ); + + error =device_add_disk (dev, gd,NULL ); +if (error) { +put_device (&sdkp->dev); + goto out; + } +if (sdkp->capacity)sd_dif_config_host (sdkp);
Greg Kroah-Hartman
maintainerPATCH 297/411 sd: rename the scsi_disk.dev field
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit fad45c3007a18064da759b4dba35eb722bc64e97 ]
dev is very hard to grep for. Give the field a more descriptive name and documents its purpose.
Stable-dep-of: 1e111c4b3a72 ("scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails")
--- drivers/scsi/sd.c | 22 +++++++++++----------- drivers/scsi/sd.h | 9 +++++++-- 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/scsi/sd.c +11 -11
@@ -674,7 +674,7 @@ static struct scsi_disk *scsi_disk_get(sif (disk->private_data) { sdkp =scsi_disk (disk);if (scsi_device_get (sdkp->device) ==0 ) -get_device (&sdkp->dev); +get_device (&sdkp->disk_dev);else sdkp =NULL ; }
@@ -687,7 +687,7 @@ static void scsi_disk_put(struct scsi_distruct scsi_device *sdev = sdkp->device;mutex_lock (&sd_ref_mutex); -put_device (&sdkp->dev); +put_device (&sdkp->disk_dev);scsi_device_put (sdev);mutex_unlock (&sd_ref_mutex); }
@@ -3412,14 +3412,14 @@ static int sd_probe(struct device *dev) SD_MOD_TIMEOUT); } -device_initialize (&sdkp->dev); - sdkp->dev.parent =get_device (dev); - sdkp->dev.class = &sd_disk_class; -dev_set_name (&sdkp->dev,"%s" ,dev_name (dev)); +device_initialize (&sdkp->disk_dev); + sdkp->disk_dev.parent =get_device (dev); + sdkp->disk_dev.class = &sd_disk_class; +dev_set_name (&sdkp->disk_dev,"%s" ,dev_name (dev)); - error =device_add (&sdkp->dev); + error =device_add (&sdkp->disk_dev);if (error) { -put_device (&sdkp->dev); +put_device (&sdkp->disk_dev); goto out; }
@@ -3461,7 +3461,7 @@ static int sd_probe(struct device *dev) error =device_add_disk (dev, gd,NULL );if (error) { -put_device (&sdkp->dev); +put_device (&sdkp->disk_dev); goto out; }
@@ -3511,7 +3511,7 @@ static int sd_remove(struct device *dev) sdkp =dev_get_drvdata (dev);scsi_autopm_get_device (sdkp->device); -device_del (&sdkp->dev); +device_del (&sdkp->disk_dev);del_gendisk (sdkp->disk);sd_shutdown (dev);
@@ -3519,7 +3519,7 @@ static int sd_remove(struct device *dev)mutex_lock (&sd_ref_mutex);dev_set_drvdata (dev,NULL ); -put_device (&sdkp->dev); +put_device (&sdkp->disk_dev);mutex_unlock (&sd_ref_mutex);return 0 ;
drivers/scsi/sd.h +7 -2
@@ -70,7 +70,12 @@ enum {struct scsi_disk {struct scsi_driver *driver;/* always &sd_template */ struct scsi_device *device; -struct device dev; + +/* +* disk_dev is used to show attributes in /sys/class/scsi_disk/, +* but otherwise not really needed. Do not use for refcounting. +*/ +struct device disk_dev;struct gendisk *disk;struct opal_dev *opal_dev;#ifdef CONFIG_BLK_DEV_ZONED
@@ -126,7 +131,7 @@ struct scsi_disk { unsigned security : 1; unsigned ignore_medium_access_errors : 1; }; -#define to_scsi_disk (obj) container_of(obj,struct scsi_disk,dev) +#define to_scsi_disk (obj) container_of(obj, struct scsi_disk, disk_dev)static inline struct scsi_disk *scsi_disk (struct gendisk *disk) {
Greg Kroah-Hartman
maintainerPATCH 298/411 scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit 1e111c4b3a726df1254670a5cc4868cedb946d37 ]
If device_add(&sdkp->disk_dev) fails, put_device() runs scsi_disk_release(), which frees the scsi_disk but leaves the gendisk referenced. The device_add_disk() error path in sd_probe() calls put_disk(gd); call put_disk(gd) here to mirror that cleanup.
--- drivers/scsi/sd.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/sd.c +1 -0
@@ -3420,6 +3420,7 @@ static int sd_probe(struct device *dev) error =device_add (&sdkp->disk_dev);if (error) {put_device (&sdkp->disk_dev); +put_disk (gd); goto out; }
Greg Kroah-Hartman
maintainerPATCH 299/411 ALSA: aloop: Fix peer runtime UAF during format-change stop
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
[ Upstream commit e5c33cdc6f402eab8abd36ecf436b22c9d3a8aff ]
loopback_check_format() may stop the capture side when playback starts with parameters that no longer match a running capture stream. Commit 826af7fa62e3 ("ALSA: aloop: Fix racy access at PCM trigger") moved the peer lookup under cable->lock, but the actual snd_pcm_stop() still runs after dropping that lock.
A concurrent close can clear the capture entry from cable->streams[] and detach or free its runtime while the playback trigger path still holds a stale peer substream pointer.
Keep a per-cable count of in-flight peer stops before dropping cable->lock, and make free_cable() wait for those stops before detaching the runtime. This preserves the existing behavior while making the peer runtime lifetime explicit.
--- sound/drivers/aloop.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
sound/drivers/aloop.c +27 -13
@@ -98,6 +98,9 @@ struct loopback_ops {struct loopback_cable {spinlock_t lock;struct loopback_pcm *streams[2 ]; +/* in-flight peer stops running outside cable->lock */ +atomic_t stop_count; +wait_queue_head_t stop_wait;struct snd_pcm_hardware hw;/* flags */ unsigned int valid;
@@ -341,8 +344,12 @@ static int loopback_check_format(structif (stream ==SNDRV_PCM_STREAM_CAPTURE ) {return -EIO ; }else { +/* close must not free the peer runtime below */ +atomic_inc (&cable->stop_count);snd_pcm_stop (cable->streams[SNDRV_PCM_STREAM_CAPTURE ]-> substream,SNDRV_PCM_STATE_DRAINING ); +if (atomic_dec_and_test (&cable->stop_count)) +wake_up (&cable->stop_wait); __notify: runtime = cable->streams[SNDRV_PCM_STREAM_PLAYBACK ]-> substream->runtime;
@@ -994,24 +1001,29 @@ static void free_cable(struct snd_pcm_sustruct loopback *loopback = substream->private_data;int dev =get_cable_index (substream);struct loopback_cable *cable; +struct loopback_pcm *dpcm; +bool other_alive; cable = loopback->cables[substream->number][dev];if (!cable)return ; -if (cable->streams[!substream->stream]) { -/* other stream is still alive */ -spin_lock_irq (&cable->lock); - cable->streams[substream->stream] =NULL ; -spin_unlock_irq (&cable->lock); - }else { -struct loopback_pcm *dpcm = substream->runtime->private_data; -if (cable->ops && cable->ops->close_cable && dpcm) - cable->ops->close_cable (dpcm); -/* free the cable */ - loopback->cables[substream->number][dev] =NULL ; -kfree (cable); - } +spin_lock_irq (&cable->lock); + cable->streams[substream->stream] =NULL ; + other_alive = cable->streams[!substream->stream] !=NULL ; +spin_unlock_irq (&cable->lock); + +/* Pair with the stop_count increment in loopback_check_format(). */ +wait_event (cable->stop_wait, !atomic_read (&cable->stop_count)); +if (other_alive) +return ; + + dpcm = substream->runtime->private_data; +if (cable->ops && cable->ops->close_cable && dpcm) + cable->ops->close_cable (dpcm); +/* free the cable */ + loopback->cables[substream->number][dev] =NULL ; +kfree (cable); }static int loopback_jiffies_timer_open (struct loopback_pcm *dpcm)
@@ -1206,6 +1218,8 @@ static int loopback_open(struct snd_pcm_ goto unlock; }spin_lock_init (&cable->lock); +atomic_set (&cable->stop_count,0 ); +init_waitqueue_head (&cable->stop_wait); cable->hw = loopback_pcm_hardware;if (loopback->timer_source) cable->ops = &loopback_snd_timer_ops;
Re: [PATCH 5.15 299/411] ALSA: aloop: Fix peer runtime UAF during format-change stop
Quoted 7 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
[ Upstream commit
e5c33cdc6f402eab8abd36ecf436b22c9d3a8aff]
[...]
No objection, but this is missing from the 6.1 and 6.6 branches.
Ben.
Signature · 2 lines
Ben Hutchings Anthony's Law of Force: Don't force it, get a larger hammer.
Greg Kroah-Hartman
maintainerPATCH 300/411 printk: add print_hex_dump_devel()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit d134feeb5df33fbf77f482f52a366a44642dba09 ]
Add print_hex_dump_devel() as the hex dump equivalent of pr_devel(), which emits output only when DEBUG is enabled, but keeps call sites compiled otherwise.
Stable-dep-of: 177730a273b1 ("crypto: caam - guard HMAC key hex dumps in hash_digest_key")
--- include/linux/printk.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/printk.h +13 -0
@@ -740,6 +740,19 @@ static inline void print_hex_dump_debug( }#endif +#if defined(DEBUG ) +#define print_hex_dump_devel (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) +#else +static inline void print_hex_dump_devel (const char *prefix_str,int prefix_type, +int rowsize,int groupsize, +const void *buf,size_t len,bool ascii) +{ +} +#endif +/** * print_hex_dump_bytes - shorthand form of print_hex_dump_debug() with default * params
Greg Kroah-Hartman
maintainerPATCH 301/411 crypto: caam - guard HMAC key hex dumps in hash_digest_key
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 177730a273b18e195263ed953853273e901b5064 ]
Use print_hex_dump_devel() for dumping sensitive HMAC key bytes in hash_digest_key() to avoid leaking secrets at runtime when CONFIG_DYNAMIC_DEBUG is enabled.
--- drivers/crypto/caam/caamalg_qi2.c | 4 ++-- drivers/crypto/caam/caamhash.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/caam/caamalg_qi2.c +2 -2
@@ -3264,7 +3264,7 @@ static int hash_digest_key(struct caam_hdpaa2_fl_set_addr (out_fle, key_dma);dpaa2_fl_set_len (out_fle, digestsize); - print_hex_dump_debug("key_in@" __stringify(__LINE__)": ", + print_hex_dump_devel("key_in@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); print_hex_dump_debug("shdesc@" __stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
@@ -3284,7 +3284,7 @@ static int hash_digest_key(struct caam_h/* in progress */ wait_for_completion (&result.completion); ret = result.err; - print_hex_dump_debug("digested key@" __stringify(__LINE__)": ", + print_hex_dump_devel("digested key@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, digestsize,1 ); }
drivers/crypto/caam/caamhash.c +2 -2
@@ -390,7 +390,7 @@ static int hash_digest_key(struct caam_happend_seq_store (desc, digestsize,LDST_CLASS_2_CCB |LDST_SRCDST_BYTE_CONTEXT ); - print_hex_dump_debug("key_in@"__stringify(__LINE__)": ", + print_hex_dump_devel("key_in@"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); print_hex_dump_debug("jobdesc@"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
@@ -405,7 +405,7 @@ static int hash_digest_key(struct caam_hwait_for_completion (&result.completion); ret = result.err; - print_hex_dump_debug("digested key@"__stringify(__LINE__)": ", + print_hex_dump_devel("digested key@"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, digestsize,1 ); }
Greg Kroah-Hartman
maintainerPATCH 302/411 tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
[ Upstream commit fad217e16fded7f3c09f8637b0f6a224d58b5f2e ]
When a tracepoint goes through the 0 -> 1 transition, tracepoint_add_func() invokes the subsystem's ext->regfunc() before attempting to install the new probe via func_add(). If func_add() then fails (for example, when allocate_probes() cannot allocate a new probe array under memory pressure and returns -ENOMEM), the function returns the error without calling the matching ext->unregfunc(), leaving the side effects of regfunc() behind with no installed probe to justify them.
For syscall tracepoints this is particularly unpleasant: syscall_regfunc() bumps sys_tracepoint_refcount and sets SYSCALL_TRACEPOINT on every task. After a leaked failure, the refcount is stuck at a non-zero value with no consumer, and every task continues paying the syscall trace entry/exit overhead until reboot. Other subsystems providing regfunc()/unregfunc() pairs exhibit similarly scoped persistent state.
Mirror the existing 1 -> 0 cleanup and call ext->unregfunc() in the func_add() error path, gated on the same condition used there so the unwind is symmetric with the registration.
--- kernel/tracepoint.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/tracepoint.c +2 -0
@@ -337,6 +337,8 @@ static int tracepoint_add_func(struct tr lockdep_is_held(&tracepoints_mutex)); old =func_add (&tp_funcs, func, prio);if (IS_ERR (old)) { +if (tp->unregfunc && !static_key_enabled (&tp->key)) + tp->unregfunc ();WARN_ON_ONCE (warn &&PTR_ERR (old) != -ENOMEM );return PTR_ERR (old); }
Greg Kroah-Hartman
maintainerPATCH 303/411 smb: client: validate the whole DACL before rewriting it in cifsacl
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 0a8cf165566ba55a39fd0f4de172119dd646d39a upstream.
build_sec_desc() and id_mode_to_cifs_acl() derive a DACL pointer from a server-supplied dacloffset and then use the incoming ACL to rebuild the chmod/chown security descriptor.
The original fix only checked that the struct smb_acl header fits before reading dacl_ptr->size or dacl_ptr->num_aces. That avoids the immediate header-field OOB read, but the rewrite helpers still walk ACEs based on pdacl->num_aces with no structural validation of the incoming DACL body.
A malicious server can return a truncated DACL that still contains a header, claims one or more ACEs, and then drive replace_sids_and_copy_aces() or set_chmod_dacl() past the validated extent while they compare or copy attacker-controlled ACEs.
Factor the DACL structural checks into validate_dacl(), extend them to validate each ACE against the DACL bounds, and use the shared validator before the chmod/chown rebuild paths. parse_dacl() reuses the same validator so the read-side parser and write-side rewrite paths agree on what constitutes a well-formed incoming DACL.
--- fs/cifs/cifsacl.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 10 deletions(-)
fs/cifs/cifsacl.c +85 -10
@@ -753,6 +753,78 @@ static void dump_ace(struct cifs_ace *pa }#endif +static int validate_dacl (struct cifs_acl *pdacl,char *end_of_acl) +{ +int i, ace_hdr_size, ace_size, min_ace_size; +u16 dacl_size; +u32 num_aces; +char *acl_base, *end_of_dacl; +struct cifs_ace *pace; + +if (!pdacl) +return 0 ; + +if (end_of_acl < (char *)pdacl +sizeof (struct cifs_acl )) { +cifs_dbg (VFS ,"ACL too small to parse DACL\n" ); +return -EINVAL ; + } + + dacl_size =le16_to_cpu (pdacl->size); +if (dacl_size <sizeof (struct cifs_acl ) || + end_of_acl < (char *)pdacl + dacl_size) { +cifs_dbg (VFS ,"ACL too small to parse DACL\n" ); +return -EINVAL ; + } + + num_aces =le32_to_cpu (pdacl->num_aces); +if (!num_aces) +return 0 ; + + ace_hdr_size = offsetof(struct cifs_ace , sid) + + offsetof(struct cifs_sid , sub_auth); + min_ace_size = ace_hdr_size +sizeof (__le32); +if (num_aces > (dacl_size -sizeof (struct cifs_acl )) / min_ace_size) { +cifs_dbg (VFS ,"ACL too small to parse DACL\n" ); +return -EINVAL ; + } + + end_of_dacl = (char *)pdacl + dacl_size; + acl_base = (char *)pdacl; + ace_size =sizeof (struct cifs_acl ); + +for (i =0 ; i < num_aces; ++i) { +if (end_of_dacl - acl_base < ace_size) { +cifs_dbg (VFS ,"ACL too small to parse ACE\n" ); +return -EINVAL ; + } + + pace = (struct cifs_ace *)(acl_base + ace_size); + acl_base = (char *)pace; + +if (end_of_dacl - acl_base < ace_hdr_size || + pace->sid.num_subauth ==0 || + pace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES ) { +cifs_dbg (VFS ,"ACL too small to parse ACE\n" ); +return -EINVAL ; + } + + ace_size = ace_hdr_size +sizeof (__le32) * pace->sid.num_subauth; +if (end_of_dacl - acl_base < ace_size || +le16_to_cpu (pace->size) < ace_size) { +cifs_dbg (VFS ,"ACL too small to parse ACE\n" ); +return -EINVAL ; + } + + ace_size =le16_to_cpu (pace->size); +if (end_of_dacl - acl_base < ace_size) { +cifs_dbg (VFS ,"ACL too small to parse ACE\n" ); +return -EINVAL ; + } + } + +return 0 ; +} +static void parse_dacl (struct cifs_acl *pdacl,char *end_of_acl,struct cifs_sid *pownersid,struct cifs_sid *pgrpsid,struct cifs_fattr *fattr,bool mode_from_special_sid)
@@ -760,7 +832,7 @@ static void parse_dacl(struct cifs_acl *int i;int num_aces =0 ;int acl_size; -char *acl_base; +char *acl_base, *end_of_dacl;struct cifs_ace **ppace;/* BB need to add parm so we can store the SID BB */
@@ -772,11 +844,8 @@ static void parse_dacl(struct cifs_acl *return ; } -/* validate that we do not go past end of acl */ -if (end_of_acl < (char *)pdacl +le16_to_cpu (pdacl->size)) { -cifs_dbg (VFS ,"ACL too small to parse DACL\n" ); +if (validate_dacl (pdacl, end_of_acl))return ; - } cifs_dbg(NOISY, "DACL revision %d size %d num aces %d\n", le16_to_cpu(pdacl->revision), le16_to_cpu(pdacl->size),
@@ -787,6 +856,7 @@ static void parse_dacl(struct cifs_acl *user/group/other have no permissions */ fattr->cf_mode &= ~(0777 ); + end_of_dacl = (char *)pdacl +le16_to_cpu (pdacl->size); acl_base = (char *)pdacl; acl_size =sizeof (struct cifs_acl );
@@ -804,7 +874,7 @@ static void parse_dacl(struct cifs_acl *for (i =0 ; i < num_aces; ++i) { ppace[i] = (struct cifs_ace *) (acl_base + acl_size);#ifdef CONFIG_CIFS_DEBUG2 -dump_ace (ppace[i], end_of_acl); +dump_ace (ppace[i], end_of_dacl);#endif if (mode_from_special_sid && ppace[i]->sid.num_subauth >= 3 &&
@@ -1263,10 +1333,9 @@ static int build_sec_desc(struct cifs_nt dacloffset =le32_to_cpu (pntsd->dacloffset);if (dacloffset) { dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); -if (end_of_acl < (char *)dacl_ptr +le16_to_cpu (dacl_ptr->size)) { -cifs_dbg (VFS ,"Server returned illegal ACL size\n" ); -return -EINVAL ; - } + rc =validate_dacl (dacl_ptr, end_of_acl); +if (rc) +return rc; } owner_sid_ptr = (struct cifs_sid *)((char *)pntsd +
@@ -1626,6 +1695,12 @@ id_mode_to_cifs_acl(struct inode *inode, dacloffset =le32_to_cpu (pntsd->dacloffset);if (dacloffset) { dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); + rc =validate_dacl (dacl_ptr, (char *)pntsd + secdesclen); +if (rc) { +kfree (pntsd); +cifs_put_tlink (tlink); +return rc; + }if (mode_from_sid) nsecdesclen +=le32_to_cpu (dacl_ptr->num_aces) *sizeof (struct cifs_ace );
Greg Kroah-Hartman
maintainerPATCH 304/411 usb: typec: tcpm: reset internal port states on soft reset AMS
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amit Sunil Dhamne <[email protected]>
[ Upstream commit 2909f0d4994fb4306bf116df5ccee797791fce2c ]
Reset internal port states (such as vdm_sm_running and explicit_contract) on soft reset AMS as the port needs to negotiate a new contract. The consequence of leaving the states in as-is cond are as follows:
* port is in SRC power role and an explicit contract is negotiated with the port partner (in sink role)
* port partner sends a Soft Reset AMS while VDM State Machine is running
* port accepts the Soft Reset request and the port advertises src caps
* port partner sends a Request message but since the explicit_contract and vdm_sm_running are true from previous negotiation, the port ends up sending Soft Reset instead of Accept msg.
Stub Log:
[ 203.653942] AMS DISCOVER_IDENTITY start [ 203.653947] PD TX, header: 0x176f [ 203.655901] PD TX complete, status: 0 [ 203.657470] PD RX, header: 0x124f [1] [ 203.657477] Rx VDM cmd 0xff008081 type 2 cmd 1 len 1 [ 203.657482] AMS DISCOVER_IDENTITY finished [ 203.657484] cc:=4 [ 204.155698] PD RX, header: 0x144f [1] [ 204.155718] Rx VDM cmd 0xeeee8001 type 0 cmd 1 len 1 [ 204.155741] PD TX, header: 0x196f [ 204.157622] PD TX complete, status: 0 [ 204.160060] PD RX, header: 0x4d [1] [ 204.160066] state change SRC_READY -> SOFT_RESET [rev2 SOFT_RESET_AMS] [ 204.160076] PD TX, header: 0x163 [ 204.162486] PD TX complete, status: 0 [ 204.162832] AMS SOFT_RESET_AMS finished [ 204.162840] cc:=4 [ 204.162891] AMS POWER_NEGOTIATION start [ 204.162896] state change SOFT_RESET -> AMS_START [rev2 POWER_NEGOTIATION] [ 204.162908] state change AMS_START -> SRC_SEND_CAPABILITIES [rev2 POWER_NEGOTIATION] [ 204.162913] PD TX, header: 0x1361 [ 204.165529] PD TX complete, status: 0 [ 204.165571] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES_TIMEOUT @ 60 ms [rev2 POWER_NEGOTIATION] [ 204.166996] PD RX, header: 0x1242 [1] [ 204.167009] state change SRC_SEND_CAPABILITIES -> SRC_SOFT_RESET_WAIT_SNK_TX [rev2 POWER_NEGOTIATION] [ 204.167019] AMS POWER_NEGOTIATION finished [ 204.167020] cc:=4 [ 204.167083] AMS SOFT_RESET_AMS start [ 204.167086] state change SRC_SOFT_RESET_WAIT_SNK_TX -> SOFT_RESET_SEND [rev2 SOFT_RESET_AMS] [ 204.167092] PD TX, header: 0x16d [ 204.168824] PD TX complete, status: 0 [ 204.168854] pending state change SOFT_RESET_SEND -> HARD_RESET_SEND @ 60 ms [rev2 SOFT_RESET_AMS] [ 204.171876] PD RX, header: 0x43 [1] [ 204.171879] AMS SOFT_RESET_AMS finished
This causes COMMON.PROC.PD.11.2 check failure for TEST.PD.VDM.SRC.2_Rev2Src test on the PD compliance tester.
--- drivers/usb/typec/tcpm/tcpm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +2 -0
@@ -4576,6 +4576,8 @@ static void run_state_machine(struct tcp port->message_id =0 ; port->rx_msgid =-1 ;tcpm_pd_send_control (port,PD_CTRL_ACCEPT ); + port->vdm_sm_running = false; + port->explicit_contract = false;tcpm_ams_finish (port);if (port->pwr_role ==TYPEC_SOURCE ) { port->upcoming_state =SRC_SEND_CAPABILITIES ;
Greg Kroah-Hartman
maintainerPATCH 305/411 wifi: brcmfmac: Fix potential use-after-free issue when stopping watchdog task
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Szyprowski <[email protected]>
[ Upstream commit c623b63580880cc742255eaed3d79804c1b91143 ]
Watchdog task might end between send_sig() and kthread_stop() calls, what results in the use-after-free issue. Fix this by increasing watchdog task reference count before calling send_sig() and dropping it by switching to kthread_stop_put().
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c +4 -0
@@ -2474,8 +2474,10 @@ static void brcmf_sdio_bus_stop(struct dbrcmf_dbg (TRACE ,"Enter\n" );if (bus->watchdog_tsk) { +get_task_struct (bus->watchdog_tsk);send_sig (SIGTERM , bus->watchdog_tsk,1 );kthread_stop (bus->watchdog_tsk); +put_task_struct (bus->watchdog_tsk); bus->watchdog_tsk =NULL ; }
@@ -4549,8 +4551,10 @@ void brcmf_sdio_remove(struct brcmf_sdioif (bus) {/* Stop watchdog task */ if (bus->watchdog_tsk) { +get_task_struct (bus->watchdog_tsk);send_sig (SIGTERM , bus->watchdog_tsk,1 );kthread_stop (bus->watchdog_tsk); +put_task_struct (bus->watchdog_tsk); bus->watchdog_tsk =NULL ; }
Greg Kroah-Hartman
maintainerPATCH 306/411 usb: dwc3: Move GUID programming after PHY initialization
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Selvarasu Ganesan <[email protected]>
[ Upstream commit aad35f9c926ec220b0742af1ada45666ae667956 ]
The Linux Version Code is currently written to the GUID register before PHY initialization. Certain PHY implementations (such as Synopsys eUSB PHY performing link_sw_reset) clear the GUID register to its default value during initialization, causing the kernel version information to be lost.
Move the GUID register programming to occur after PHY initialization completes to ensure the Linux version information persists.
--- drivers/usb/dwc3/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/dwc3/core.c +6 -6
@@ -978,12 +978,6 @@ static int dwc3_core_init(struct dwc3 *d hw_mode =DWC3_GHWPARAMS0_MODE (dwc->hwparams.hwparams0); -/* -* Write Linux Version Code to our GUID register so it's easy to figure -* out which kernel version a bug was found. -*/ -dwc3_writel (dwc->regs,DWC3_GUID ,LINUX_VERSION_CODE ); - ret =dwc3_phy_setup (dwc);if (ret) goto err0;
@@ -1023,6 +1017,12 @@ static int dwc3_core_init(struct dwc3 *dif (ret) goto err1; +/* +* Write Linux Version Code to our GUID register so it's easy to figure +* out which kernel version a bug was found. +*/ +dwc3_writel (dwc->regs,DWC3_GUID ,LINUX_VERSION_CODE ); +dwc3_core_setup_global_control (dwc);dwc3_core_num_eps (dwc);
Greg Kroah-Hartman
maintainerPATCH 307/411 net: ipv4: stop checking crypto_ahash_alignmask
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
[ Upstream commit e77f5dd701381cef35b9ea8b6dea6e62c8a7f9f3 ]
Now that the alignmask for ahash and shash algorithms is always 0, crypto_ahash_alignmask() always returns 0 and will be removed. In preparation for this, stop checking crypto_ahash_alignmask() in ah4.c.
Stable-dep-of: ec54093e6a8f ("xfrm: ah: account for ESN high bits in async callbacks")
--- net/ipv4/ah4.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
net/ipv4/ah4.c +7 -10
@@ -27,9 +27,7 @@ static void *ah_alloc_tmp(struct crypto_ {unsigned int len; - len = size +crypto_ahash_digestsize (ahash) + - (crypto_ahash_alignmask (ahash) & - ~(crypto_tfm_ctx_alignment () -1 )); + len = size +crypto_ahash_digestsize (ahash); len =ALIGN (len,crypto_tfm_ctx_alignment ());
@@ -46,10 +44,9 @@ static inline u8 *ah_tmp_auth(void *tmp,return tmp + offset; } -static inline u8 *ah_tmp_icv (struct crypto_ahash *ahash,void *tmp, -unsigned int offset) +static inline u8 *ah_tmp_icv (void *tmp,unsigned int offset) { -return PTR_ALIGN ((u8 *)tmp + offset,crypto_ahash_alignmask (ahash) +1 ); +return tmp + offset; } static inline struct ahash_request *ah_tmp_req(struct crypto_ahash *ahash,
@@ -129,7 +126,7 @@ static void ah_output_done(struct cryptoint ihl =ip_hdrlen (skb); iph =AH_SKB_CB (skb)->tmp; - icv =ah_tmp_icv (ahp->ahash, iph, ihl); + icv =ah_tmp_icv (iph, ihl);memcpy (ah->auth_data, icv, ahp->icv_trunc_len); top_iph->tos = iph->tos;
@@ -182,7 +179,7 @@ static int ah_output(struct xfrm_state *if (!iph) goto out; seqhi = (__be32 *)((char *)iph + ihl); - icv =ah_tmp_icv (ahash, seqhi, seqhi_len); + icv =ah_tmp_icv (seqhi, seqhi_len); req =ah_tmp_req (ahash, icv); sg =ah_req_sg (ahash, req); seqhisg = sg + nfrags;
@@ -279,7 +276,7 @@ static void ah_input_done(struct crypto_ work_iph =AH_SKB_CB (skb)->tmp; auth_data =ah_tmp_auth (work_iph, ihl); - icv =ah_tmp_icv (ahp->ahash, auth_data, ahp->icv_trunc_len); + icv =ah_tmp_icv (auth_data, ahp->icv_trunc_len); err =crypto_memneq (icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG :0 ;if (err)
@@ -374,7 +371,7 @@ static int ah_input(struct xfrm_state *x seqhi = (__be32 *)((char *)work_iph + ihl); auth_data =ah_tmp_auth (seqhi, seqhi_len); - icv =ah_tmp_icv (ahash, auth_data, ahp->icv_trunc_len); + icv =ah_tmp_icv (auth_data, ahp->icv_trunc_len); req =ah_tmp_req (ahash, icv); sg =ah_req_sg (ahash, req); seqhisg = sg + nfrags;
Greg Kroah-Hartman
maintainerPATCH 308/411 net: ipv6: stop checking crypto_ahash_alignmask
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
[ Upstream commit 0a6bfaa0e695facb072f2fedfb55df37c4483b50 ]
Now that the alignmask for ahash and shash algorithms is always 0, crypto_ahash_alignmask() always returns 0 and will be removed. In preparation for this, stop checking crypto_ahash_alignmask() in ah6.c.
Stable-dep-of: ec54093e6a8f ("xfrm: ah: account for ESN high bits in async callbacks")
--- net/ipv6/ah6.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
net/ipv6/ah6.c +7 -10
@@ -79,9 +79,7 @@ static void *ah_alloc_tmp(struct crypto_ {unsigned int len; - len = size +crypto_ahash_digestsize (ahash) + - (crypto_ahash_alignmask (ahash) & - ~(crypto_tfm_ctx_alignment () -1 )); + len = size +crypto_ahash_digestsize (ahash); len =ALIGN (len,crypto_tfm_ctx_alignment ());
@@ -103,10 +101,9 @@ static inline u8 *ah_tmp_auth(u8 *tmp, ureturn tmp + offset; } -static inline u8 *ah_tmp_icv (struct crypto_ahash *ahash,void *tmp, -unsigned int offset) +static inline u8 *ah_tmp_icv (void *tmp,unsigned int offset) { -return PTR_ALIGN ((u8 *)tmp + offset,crypto_ahash_alignmask (ahash) +1 ); +return tmp + offset; } static inline struct ahash_request *ah_tmp_req(struct crypto_ahash *ahash,
@@ -330,7 +327,7 @@ static void ah6_output_done(struct crypt iph_base =AH_SKB_CB (skb)->tmp; iph_ext =ah_tmp_ext (iph_base); - icv =ah_tmp_icv (ahp->ahash, iph_ext, extlen); + icv =ah_tmp_icv (iph_ext, extlen);memcpy (ah->auth_data, icv, ahp->icv_trunc_len);memcpy (top_iph, iph_base,IPV6HDR_BASELEN );
@@ -387,7 +384,7 @@ static int ah6_output(struct xfrm_state iph_ext =ah_tmp_ext (iph_base); seqhi = (__be32 *)((char *)iph_ext + extlen); - icv =ah_tmp_icv (ahash, seqhi, seqhi_len); + icv =ah_tmp_icv (seqhi, seqhi_len); req =ah_tmp_req (ahash, icv); sg =ah_req_sg (ahash, req); seqhisg = sg + nfrags;
@@ -483,7 +480,7 @@ static void ah6_input_done(struct crypto work_iph =AH_SKB_CB (skb)->tmp; auth_data =ah_tmp_auth (work_iph, hdr_len); - icv =ah_tmp_icv (ahp->ahash, auth_data, ahp->icv_trunc_len); + icv =ah_tmp_icv (auth_data, ahp->icv_trunc_len); err =crypto_memneq (icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG :0 ;if (err)
@@ -591,7 +588,7 @@ static int ah6_input(struct xfrm_state * auth_data =ah_tmp_auth ((u8 *)work_iph, hdr_len); seqhi = (__be32 *)(auth_data + ahp->icv_trunc_len); - icv =ah_tmp_icv (ahash, seqhi, seqhi_len); + icv =ah_tmp_icv (seqhi, seqhi_len); req =ah_tmp_req (ahash, icv); sg =ah_req_sg (ahash, req); seqhisg = sg + nfrags;
Greg Kroah-Hartman
maintainerPATCH 309/411 xfrm: ah: account for ESN high bits in async callbacks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit ec54093e6a8f87e800bb6aa15eb7fc1e33faa524 ]
AH allocates its temporary auth/ICV layout differently when ESN is enabled:
the async ahash setup appends a 4-byte seqhi slot before the ICV or auth_data area, but the async completion callbacks still reconstruct the temporary layout as if seqhi were absent.
With an async AH implementation selected, that makes AH copy or compare the wrong bytes on both the IPv4 and IPv6 paths. In UML repro on IPv4 AH with ESN and forced async hmac(sha1), ping fails with 100% packet loss, and the callback logs show the pre-fix drift:
ah4 output_done: esn=1 err=0 icv_off=20 expected_off=24
ah4 input_done: esn=1 auth_off=20 expected_auth_off=24 icv_off=32 expected_icv_off=36
Reconstruct the callback-side layout the same way the setup path built it by skipping the ESN seqhi slot before locating the saved auth_data or ICV. Per RFC 4302, the ESN high-order 32 bits participate in the AH ICV computation, so the async callbacks must account for the seqhi slot.
Post-fix, the same IPv4 AH+ESN+forced-async-hmac(sha1) UML repro shows the corrected offset (ah4 output_done: esn=1 err=0 icv_off=24 expected_off=24) and ping succeeds; net/ipv4/ah4.o and net/ipv6/ah6.o build clean at W=1. IPv6 AH+ESN was not exercised at runtime, and the change has not been tested against a real async hardware AH engine.
--- net/ipv4/ah4.c | 14 ++++++++++++-- net/ipv6/ah6.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-)
net/ipv4/ah4.c +12 -2
@@ -124,9 +124,14 @@ static void ah_output_done(struct cryptostruct iphdr *top_iph =ip_hdr (skb);struct ip_auth_hdr *ah =ip_auth_hdr (skb);int ihl =ip_hdrlen (skb); +int seqhi_len =0 ; +__be32 *seqhi; +if (x->props.flags &XFRM_STATE_ESN ) + seqhi_len =sizeof (*seqhi); iph =AH_SKB_CB (skb)->tmp; - icv =ah_tmp_icv (iph, ihl); + seqhi = (__be32 *)((char *)iph + ihl); + icv =ah_tmp_icv (seqhi, seqhi_len);memcpy (ah->auth_data, icv, ahp->icv_trunc_len); top_iph->tos = iph->tos;
@@ -270,12 +275,17 @@ static void ah_input_done(struct crypto_struct ip_auth_hdr *ah =ip_auth_hdr (skb);int ihl =ip_hdrlen (skb);int ah_hlen = (ah->hdrlen +2 ) <<2 ; +int seqhi_len =0 ; +__be32 *seqhi;if (err) goto out; +if (x->props.flags &XFRM_STATE_ESN ) + seqhi_len =sizeof (*seqhi); work_iph =AH_SKB_CB (skb)->tmp; - auth_data =ah_tmp_auth (work_iph, ihl); + seqhi = (__be32 *)((char *)work_iph + ihl); + auth_data =ah_tmp_auth (seqhi, seqhi_len); icv =ah_tmp_icv (auth_data, ahp->icv_trunc_len); err =crypto_memneq (icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG :0 ;
net/ipv6/ah6.c +12 -2
@@ -320,14 +320,19 @@ static void ah6_output_done(struct cryptstruct ipv6hdr *top_iph =ipv6_hdr (skb);struct ip_auth_hdr *ah =ip_auth_hdr (skb);struct tmp_ext *iph_ext; +int seqhi_len =0 ; +__be32 *seqhi; extlen =skb_network_header_len (skb) -sizeof (struct ipv6hdr );if (extlen) extlen +=sizeof (*iph_ext); +if (x->props.flags &XFRM_STATE_ESN ) + seqhi_len =sizeof (*seqhi); iph_base =AH_SKB_CB (skb)->tmp; iph_ext =ah_tmp_ext (iph_base); - icv =ah_tmp_icv (iph_ext, extlen); + seqhi = (__be32 *)((char *)iph_ext + extlen); + icv =ah_tmp_icv (seqhi, seqhi_len);memcpy (ah->auth_data, icv, ahp->icv_trunc_len);memcpy (top_iph, iph_base,IPV6HDR_BASELEN );
@@ -474,13 +479,18 @@ static void ah6_input_done(struct cryptostruct ip_auth_hdr *ah =ip_auth_hdr (skb);int hdr_len =skb_network_header_len (skb);int ah_hlen =ipv6_authlen (ah); +int seqhi_len =0 ; +__be32 *seqhi;if (err) goto out; +if (x->props.flags &XFRM_STATE_ESN ) + seqhi_len =sizeof (*seqhi); work_iph =AH_SKB_CB (skb)->tmp; auth_data =ah_tmp_auth (work_iph, hdr_len); - icv =ah_tmp_icv (auth_data, ahp->icv_trunc_len); + seqhi = (__be32 *)(auth_data + ahp->icv_trunc_len); + icv =ah_tmp_icv (seqhi, seqhi_len); err =crypto_memneq (icv, auth_data, ahp->icv_trunc_len) ? -EBADMSG :0 ;if (err)
Greg Kroah-Hartman
maintainerPATCH 310/411 xfrm: defensively unhash xfrm_state lists in __xfrm_state_delete
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Kosiorek <[email protected]>
[ Upstream commit 14acf9652e5690de3c7486c6db5fb8dafd0a32a3 ]
KASAN reproduces a slab-use-after-free in __xfrm_state_delete()'s hlist_del_rcu calls under syzkaller load on linux-6.12.y stable (reproduced on 6.12.47, also reachable via the same code path on torvalds/master and on the ipsec tree). Nine unique signatures cluster in the xfrm_state lifecycle, the load-bearing one being:
BUG: KASAN: slab-use-after-free in __hlist_del include/linux/list.h:990 [inline] BUG: KASAN: slab-use-after-free in hlist_del_rcu include/linux/rculist.h:516 [inline] BUG: KASAN: slab-use-after-free in __xfrm_state_delete net/xfrm/xfrm_state.c Write of size 8 at addr ffff8881198bcb70 by task kworker/u8:9/435 Workqueue: netns cleanup_net Call Trace: __hlist_del / hlist_del_rcu __xfrm_state_delete xfrm_state_delete xfrm_state_flush xfrm_state_fini ops_exit_list cleanup_net
The other observed signatures hit the same slab object from __xfrm_state_lookup, xfrm_alloc_spi, __xfrm_state_insert and an OOB write variant of __xfrm_state_delete, all on the byseq/byspi hash chains.
__xfrm_state_delete() guards its byseq and byspi unhashes with value-based predicates:
if (x->km.seq) hlist_del_rcu(&x->byseq); if (x->id.spi) hlist_del_rcu(&x->byspi);
while everywhere else in the file (e.g. state_cache, state_cache_input) the safer hlist_unhashed() check is used. xfrm_alloc_spi() sets x->id.spi = newspi inside xfrm_state_lock and then immediately inserts into byspi, but a path that observes x->id.spi != 0 outside of xfrm_state_lock can still skip-or-hit the byspi unhash inconsistently with whether x is actually on the list. The same holds for x->km.seq versus byseq, and the bydst/bysrc unhashes have no predicate at all, so a second __xfrm_state_delete() on the same object writes through LIST_POISON pprev.
The defensive change here:
- Use hlist_del_init_rcu() instead of hlist_del_rcu() on bydst, bysrc, byseq and byspi so a second deletion is a no-op rather than a write through LIST_POISON pprev. The byseq/byspi nodes are already initialised in xfrm_state_alloc().
- Test hlist_unhashed() rather than the value predicate for byseq/byspi, so the unhash decision tracks list state rather than mutable scalar fields.
Empirical verification: applied this patch on top of v6.12.47, rebuilt, and re-ran the same syzkaller harness for 1h16m on a previously-crashy configuration that produced ~100 hits each of slab-use-after-free Read in xfrm_alloc_spi / Read in __xfrm_state_lookup / Write in __xfrm_state_delete. After the patch, 7.1M execs across 32 VMs at ~1550 exec/sec produced zero xfrm_state UAF/OOB hits. /proc/slabinfo confirms the xfrm_state slab is actively allocated and freed during the run (~143 KiB resident), so the fuzzer is still exercising those code paths -- they just no longer crash.
Reproduction:
- Linux 6.12.47 x86_64 + KASAN_GENERIC + KASAN_INLINE + KCOV
- syzkaller @ 746545b8b1e4c3a128db8652b340d3df90ce61db
- 32 QEMU/KVM VMs x 2 vCPU on AWS c5.metal bare metal
- 9 unique signatures collected in ~9h, all within xfrm_state lifecycle
--- net/xfrm/xfrm_state.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/xfrm/xfrm_state.c +6 -6
@@ -681,12 +681,12 @@ int __xfrm_state_delete(struct xfrm_stat x->km.state =XFRM_STATE_DEAD ;spin_lock (&net->xfrm.xfrm_state_lock);list_del (&x->km.all); -hlist_del_rcu (&x->bydst); -hlist_del_rcu (&x->bysrc); -if (x->km.seq) -hlist_del_rcu (&x->byseq); -if (x->id.spi) -hlist_del_rcu (&x->byspi); +hlist_del_init_rcu (&x->bydst); +hlist_del_init_rcu (&x->bysrc); +if (!hlist_unhashed (&x->byseq)) +hlist_del_init_rcu (&x->byseq); +if (!hlist_unhashed (&x->byspi)) +hlist_del_init_rcu (&x->byspi); net->xfrm.state_num--;spin_unlock (&net->xfrm.xfrm_state_lock);
Greg Kroah-Hartman
maintainerPATCH 311/411 spi: syncuacer: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 75d849c3452e9611de031db45b3149ba9a99035f ]
Make sure to deregister the controller before disabling underlying resources like clocks during driver unbind.
--- drivers/spi/spi-synquacer.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-synquacer.c +7 -1
@@ -719,7 +719,7 @@ static int synquacer_spi_probe(struct plpm_runtime_set_active (sspi->dev);pm_runtime_enable (sspi->dev); - ret =devm_spi_register_master (sspi->dev, master); + ret =spi_register_master (master);if (ret) goto disable_pm;
@@ -740,10 +740,16 @@ static int synquacer_spi_remove(struct pstruct spi_master *master =platform_get_drvdata (pdev);struct synquacer_spi *sspi =spi_master_get_devdata (master); +spi_master_get (master); + +spi_unregister_master (master); +pm_runtime_disable (sspi->dev);clk_disable_unprepare (sspi->clk); +spi_master_put (master); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 312/411 spi: sun4i: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 42108a2f03e0fdeabe9d02d085bdb058baa1189f ]
Make sure to deregister the controller before disabling underlying resources like clocks during driver unbind.
--- drivers/spi/spi-sun4i.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/spi/spi-sun4i.c +9 -1
@@ -503,7 +503,7 @@ static int sun4i_spi_probe(struct platfopm_runtime_enable (&pdev->dev);pm_runtime_idle (&pdev->dev); - ret =devm_spi_register_master (&pdev->dev, master); + ret =spi_register_master (master);if (ret) {dev_err (&pdev->dev,"cannot register SPI master\n" ); goto err_pm_disable;
@@ -521,8 +521,16 @@ err_free_master:static int sun4i_spi_remove (struct platform_device *pdev) { +struct spi_master *master =platform_get_drvdata (pdev); + +spi_master_get (master); + +spi_unregister_master (master); +pm_runtime_force_suspend (&pdev->dev); +spi_master_put (master); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 313/411 spi: spi-ti-qspi: Convert to platform remove callback returning void
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 2f2802d1a59d79a3d00cb429841db502c2bbc3df ]
The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks.
To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove().
Add an error message to the error path that returned an error before to replace the core's error message with more information. Apart from the different wording of the error message, this patch doesn't introduce a semantic difference.
Stable-dep-of: 0c18a1bacbb1 ("spi: ti-qspi: fix controller deregistration")
--- drivers/spi/spi-ti-qspi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/spi/spi-ti-qspi.c +7 -6
@@ -907,21 +907,22 @@ free_master:return ret; } -static int ti_qspi_remove (struct platform_device *pdev) +static void ti_qspi_remove (struct platform_device *pdev) {struct ti_qspi *qspi =platform_get_drvdata (pdev);int rc; rc =spi_master_suspend (qspi->master); -if (rc) -return rc; +if (rc) { +dev_alert (&pdev->dev,"spi_master_suspend() failed (%pe)\n" , +ERR_PTR (rc)); +return ; + }pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);ti_qspi_dma_cleanup (qspi); - -return 0 ; }static const struct dev_pm_ops ti_qspi_pm_ops = {
@@ -930,7 +931,7 @@ static const struct dev_pm_ops ti_qspi_pstatic struct platform_driver ti_qspi_driver = { .probe = ti_qspi_probe, - .remove = ti_qspi_remove, + .remove_new = ti_qspi_remove, .driver = { .name ="ti-qspi" , .pm = &ti_qspi_pm_ops,
Greg Kroah-Hartman
maintainerPATCH 314/411 spi: ti-qspi: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 0c18a1bacbb1d8b8aa34d3d004a2cb8226c8b1ea ]
Make sure to deregister the controller before disabling underlying resources like clocks during driver unbind.
Note that the controller is suspended before disabling and releasing resources since commit 3ac066e2227c ("spi: spi-ti-qspi: Suspend the queue before removing the device") which avoids issues like unclocked accesses but prevents SPI device drivers from doing I/O during deregistration.
--- drivers/spi/spi-ti-qspi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/spi/spi-ti-qspi.c +6 -8
@@ -895,7 +895,7 @@ no_dma: qspi->mmap_enabled = false; qspi->current_cs =-1 ; - ret =devm_spi_register_master (&pdev->dev, master); + ret =spi_register_master (master);if (!ret)return 0 ;
@@ -910,19 +910,17 @@ free_master:static void ti_qspi_remove (struct platform_device *pdev) {struct ti_qspi *qspi =platform_get_drvdata (pdev); -int rc; - rc =spi_master_suspend (qspi->master); -if (rc) { -dev_alert (&pdev->dev,"spi_master_suspend() failed (%pe)\n" , -ERR_PTR (rc)); -return ; - } +spi_master_get (qspi->master); + +spi_unregister_master (qspi->master);pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);ti_qspi_dma_cleanup (qspi); + +spi_master_put (qspi->master); }static const struct dev_pm_ops ti_qspi_pm_ops = {
Greg Kroah-Hartman
maintainerPATCH 315/411 spi: zynq-qspi: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit c9c012706c9fa8ca6d129a9161caf92ab625a3fd ]
Make sure to deregister the controller before disabling it during driver unbind.
Note that clocks were also disabled before the recent commit 1f8fd9490e31 ("spi: zynq-qspi: Simplify clock handling with devm_clk_get_enabled()").
--- drivers/spi/spi-zynq-qspi.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/spi/spi-zynq-qspi.c +11 -4
@@ -652,7 +652,7 @@ static int zynq_qspi_probe(struct platfo xqspi =spi_controller_get_devdata (ctlr); xqspi->dev = dev; -platform_set_drvdata (pdev, xqspi); +platform_set_drvdata (pdev, ctlr); xqspi->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (xqspi->regs)) { ret =PTR_ERR (xqspi->regs);
@@ -722,9 +722,9 @@ static int zynq_qspi_probe(struct platfo/* QSPI controller initializations */ zynq_qspi_init_hw (xqspi, ctlr->num_chipselect); - ret =devm_spi_register_controller (&pdev->dev, ctlr); + ret =spi_register_controller (ctlr);if (ret) { -dev_err (&pdev->dev,"spi_register_master failed\n" ); +dev_err (&pdev->dev,"failed to register controller\n" ); goto clk_dis_all; }
@@ -752,13 +752,20 @@ remove_master:*/ static int zynq_qspi_remove (struct platform_device *pdev) { -struct zynq_qspi *xqspi =platform_get_drvdata (pdev); +struct spi_controller *ctlr =platform_get_drvdata (pdev); +struct zynq_qspi *xqspi =spi_controller_get_devdata (ctlr); + +spi_controller_get (ctlr); + +spi_unregister_controller (ctlr);zynq_qspi_write (xqspi,ZYNQ_QSPI_ENABLE_OFFSET ,0 );clk_disable_unprepare (xqspi->refclk);clk_disable_unprepare (xqspi->pclk); +spi_controller_put (ctlr); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 316/411 spi: sun6i: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit d874a1c33aee0d88fb4ba2f8aeadaa9f1965209a ]
Make sure to deregister the controller before disabling underlying resources like clocks during driver unbind.
--- drivers/spi/spi-sun6i.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/spi/spi-sun6i.c +8 -1
@@ -688,7 +688,7 @@ static int sun6i_spi_probe(struct platfopm_runtime_set_active (&pdev->dev);pm_runtime_enable (&pdev->dev); - ret =devm_spi_register_master (&pdev->dev, master); + ret =spi_register_master (master);if (ret) {dev_err (&pdev->dev,"cannot register SPI master\n" ); goto err_pm_disable;
@@ -714,12 +714,19 @@ static int sun6i_spi_remove(struct platf {struct spi_master *master =platform_get_drvdata (pdev); +spi_master_get (master); + +spi_unregister_master (master); +pm_runtime_force_suspend (&pdev->dev);if (master->dma_tx)dma_release_channel (master->dma_tx);if (master->dma_rx)dma_release_channel (master->dma_rx); + +spi_master_put (master); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 317/411 spi: tegra114: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 9c9c27ff2058142d8f800de3186d6864184958de ]
Make sure to deregister the controller before disabling underlying resources like clocks during driver unbind.
--- drivers/spi/spi-tegra114.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-tegra114.c +7 -1
@@ -1417,7 +1417,7 @@ static int tegra_spi_probe(struct platfo } master->dev.of_node = pdev->dev.of_node; - ret =devm_spi_register_master (&pdev->dev, master); + ret =spi_register_master (master);if (ret <0 ) {dev_err (&pdev->dev,"can not register to master err %d\n" , ret); goto exit_free_irq;
@@ -1443,6 +1443,10 @@ static int tegra_spi_remove(struct platfstruct spi_master *master =platform_get_drvdata (pdev);struct tegra_spi_data *tspi =spi_master_get_devdata (master); +spi_master_get (master); + +spi_unregister_master (master); +free_irq (tspi->irq, tspi);if (tspi->tx_dma_chan)
@@ -1455,6 +1459,8 @@ static int tegra_spi_remove(struct platfif (!pm_runtime_status_suspended (&pdev->dev))tegra_spi_runtime_suspend (&pdev->dev); +spi_master_put (master); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 318/411 spi: tegra20-sflash: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit ad7310e983327f939dd6c4e801eab13238992572 ]
Make sure to deregister the controller before disabling underlying resources like clocks during driver unbind.
--- drivers/spi/spi-tegra20-sflash.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-tegra20-sflash.c +7 -1
@@ -507,7 +507,7 @@ static int tegra_sflash_probe(struct plapm_runtime_put (&pdev->dev); master->dev.of_node = pdev->dev.of_node; - ret =devm_spi_register_master (&pdev->dev, master); + ret =spi_register_master (master);if (ret <0 ) {dev_err (&pdev->dev,"can not register to master err %d\n" , ret); goto exit_pm_disable;
@@ -530,12 +530,18 @@ static int tegra_sflash_remove(struct plstruct spi_master *master =platform_get_drvdata (pdev);struct tegra_sflash_data *tsd =spi_master_get_devdata (master); +spi_master_get (master); + +spi_unregister_master (master); +free_irq (tsd->irq, tsd);pm_runtime_disable (&pdev->dev);if (!pm_runtime_status_suspended (&pdev->dev))tegra_sflash_runtime_suspend (&pdev->dev); +spi_master_put (master); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 319/411 spi: uniphier: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 0245435f777264ac45945ed2f325dd095a41d1af ]
Make sure to deregister the controller before releasing underlying resources like DMA during driver unbind.
Note that clocks were also disabled before the recent commit fdca270f8f87 ("spi: uniphier: Simplify clock handling with devm_clk_get_enabled()").
--- drivers/spi/spi-uniphier.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-uniphier.c +7 -1
@@ -751,7 +751,7 @@ static int uniphier_spi_probe(struct pla master->max_dma_len =min (dma_tx_burst, dma_rx_burst); - ret =devm_spi_register_master (&pdev->dev, master); + ret =spi_register_master (master);if (ret) goto out_release_dma;
@@ -780,6 +780,10 @@ static int uniphier_spi_remove(struct plstruct spi_master *master =platform_get_drvdata (pdev);struct uniphier_spi_priv *priv =spi_master_get_devdata (master); +spi_master_get (master); + +spi_unregister_master (master); +if (master->dma_tx)dma_release_channel (master->dma_tx);if (master->dma_rx)
@@ -787,6 +791,8 @@ static int uniphier_spi_remove(struct plclk_disable_unprepare (priv->clk); +spi_master_put (master); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 320/411 mm/hugetlb_cma: round up per_node before logging it
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Heon Jeon <[email protected]>
[ Upstream commit 8f5ce56b76303c55b78a87af996e2e0f8535f979 ]
When the user requests a total hugetlb CMA size without per-node specification, hugetlb_cma_reserve() computes per_node from hugetlb_cma_size and the number of nodes that have memory
per_node = DIV_ROUND_UP(hugetlb_cma_size,
nodes_weight(hugetlb_bootmem_nodes));
The reservation loop later computes
size = round_up(min(per_node, hugetlb_cma_size - reserved),
PAGE_SIZE << order);
So the actually reserved per_node size is multiple of (PAGE_SIZE << order), but the logged per_node is not rounded up, so it may be smaller than the actual reserved size.
For example, as the existing comment describes, if a 3 GB area is requested on a machine with 4 NUMA nodes that have memory, 1 GB is allocated on the first three nodes, but the printed log is
hugetlb_cma: reserve 3072 MiB, up to 768 MiB per node
Round per_node up to (PAGE_SIZE << order) before logging so that the printed log always matches the actual reserved size. No functional change to the actual reservation size, as the following case analysis shows
1. remaining (hugetlb_cma_size - reserved) >= rounded per_node
- AS-IS: min() picks unrounded per_node;
round_up() returns rounded per_node
- TO-BE: min() picks rounded per_node;
round_up() returns rounded per_node (no-op)
2. remaining < unrounded per_node
- AS-IS: min() picks remaining;
round_up() returns round_up(remaining)
- TO-BE: min() picks remaining;
round_up() returns round_up(remaining)
3. unrounded per_node <= remaining < rounded per_node
- AS-IS: min() picks unrounded per_node;
round_up() returns rounded per_node
- TO-BE: min() picks remaining;
round_up() returns round_up(remaining) equals rounded per_node
--- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+)
mm/hugetlb.c +1 -0
@@ -6493,6 +6493,7 @@ void __init hugetlb_cma_reserve(int orde* let's allocate 1 GB on first three nodes and ignore the last one. */ per_node =DIV_ROUND_UP (hugetlb_cma_size, nr_online_nodes); + per_node =round_up (per_node,PAGE_SIZE << order);pr_info ("hugetlb_cma: reserve %lu MiB, up to %lu MiB per node\n" , hugetlb_cma_size /SZ_1M , per_node /SZ_1M );
Greg Kroah-Hartman
maintainerPATCH 321/411 fbcon: Avoid OOB font access if console rotation fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
[ Upstream commit e4ef723d8975a2694cc90733a6b888a5e2841842 ]
Clear the font buffer if the reallocation during console rotation fails in fbcon_rotate_font(). The putcs implementations for the rotated buffer will return early in this case. See [1] for an example.
Currently, fbcon_rotate_font() keeps the old buffer, which is too small for the rotated font. Printing to the rotated console with a high-enough character code will overflow the font buffer.
v2:
- fix typos in commit message
--- drivers/video/fbdev/core/fbcon_rotate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/fbdev/core/fbcon_rotate.c +4 -1
@@ -46,6 +46,10 @@ static int fbcon_rotate_font(struct fb_i info->fbops->fb_sync (info);if (ops->fd_size < d_cellsize * len) { +kfree (ops->fontbuffer); + ops->fontbuffer =NULL ; + ops->fd_size =0 ; + dst =kmalloc_array (len, d_cellsize,GFP_KERNEL );if (dst ==NULL ) {
@@ -54,7 +58,6 @@ static int fbcon_rotate_font(struct fb_i } ops->fd_size = d_cellsize * len; -kfree (ops->fontbuffer); ops->fontbuffer = dst; }
Greg Kroah-Hartman
maintainerPATCH 322/411 spi: topcliff-pch: Convert to platform remove callback returning void
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit b082694f18bdff807b42a3bccc62c3a524168f23 ]
The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is (mostly) ignored and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new() which already returns void.
Trivially convert this driver from always returning zero in the remove callback to the void returning variant.
Stable-dep-of: 5d6f477d6fc0 ("spi: topcliff-pch: fix controller deregistration")
--- drivers/spi/spi-topcliff-pch.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/spi/spi-topcliff-pch.c +2 -4
@@ -1417,7 +1417,7 @@ err_pci_iomap:return ret; } -static int pch_spi_pd_remove (struct platform_device *plat_dev) +static void pch_spi_pd_remove (struct platform_device *plat_dev) {struct pch_spi_board_data *board_dat =dev_get_platdata (&plat_dev->dev);struct pch_spi_data *data =platform_get_drvdata (plat_dev);
@@ -1455,8 +1455,6 @@ static int pch_spi_pd_remove(struct platpci_iounmap (board_dat->pdev, data->io_remap_addr);spi_unregister_master (data->master); - -return 0 ; }#ifdef CONFIG_PM static int pch_spi_pd_suspend(struct platform_device *pd_dev,
@@ -1537,7 +1535,7 @@ static struct platform_driver pch_spi_pd .name = "pch-spi", }, .probe = pch_spi_pd_probe, - .remove = pch_spi_pd_remove, + .remove_new = pch_spi_pd_remove, .suspend = pch_spi_pd_suspend, .resume = pch_spi_pd_resume };
Greg Kroah-Hartman
maintainerPATCH 323/411 spi: topcliff-pch: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 5d6f477d6fc0767c57c5e1e6f55a1662820eef87 ]
Make sure to deregister the controller before disabling and releasing underlying resources like interrupts and DMA during driver unbind.
--- drivers/spi/spi-topcliff-pch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/spi/spi-topcliff-pch.c +6 -1
@@ -1450,11 +1450,16 @@ static void pch_spi_pd_remove(struct plafree_irq (board_dat->pdev->irq, data); } +spi_master_get (data->master); + +spi_unregister_master (data->master); +if (use_dma)pch_free_dma_buf (board_dat, data);pci_iounmap (board_dat->pdev, data->io_remap_addr); -spi_unregister_master (data->master); + +spi_master_put (data->master); }#ifdef CONFIG_PM static int pch_spi_pd_suspend(struct platform_device *pd_dev,
Re: [PATCH 5.15 323/411] spi: topcliff-pch: fix controller deregistration
Hi Greg/Sasha,
Quoted 11 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit
5d6f477d6fc0767c57c5e1e6f55a1662820eef87]Make sure to deregister the controller before disabling and releasing underlying resources like interrupts and DMA during driver unbind.
^^ let us remember this -- deregister before releasing irqs.
Quoted 16 lines
Fixes e8b17b5b3f30 ("spi/topcliff: Add topcliff platform controller hub (PCH) spi bus driver")Cc [email protected] # 2.6.37Cc Masayuki Ohtake <[email protected]>Signed-off-by Johan Hovold <[email protected]>Signed-off-by Mark Brown <[email protected]>[ renamed spi_controller_*(data->host) calls to spi_master_*(data->master) ]Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/spi/spi-topcliff-pch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/spi/spi-topcliff-pch.c static void pch_spi_pd_remove(struct pla · line 1451
Quoted 2 lines
drivers/spi/spi-topcliff-pch.c +0
-0@@ -1450,11 +1450,16 @@ static void pch_spi_pd_remove(struct plafree_irq (board_dat->pdev->irq, data); }
^^^ let us remember this.
drivers/spi/spi-topcliff-pch.c static void pch_spi_pd_remove(struct pla · line 1463
Quoted 13 lines
drivers/spi/spi-topcliff-pch.c +6
-1+spi_master_get (data->master); + +spi_unregister_master (data->master); +if (use_dma)pch_free_dma_buf (board_dat, data);pci_iounmap (board_dat->pdev, data->io_remap_addr); -spi_unregister_master (data->master); + +spi_master_put (data->master); }
I ran an AI assisted backport review over the 5.15.210 queue and then
checked this one manually. I think the 5.15.y backport keeps the API mapping, but not the upstream teardown ordering.
Upstream 5d6f477d6fc0 unregisters the controller before the local teardown:
spi_controller_get(data->host);
spi_unregister_controller(data->host);
if (use_dma)
pch_free_dma_buf(board_dat, data);
...
pch_spi_free_resources(board_dat, data);
/* disable interrupts & free IRQ */
if (data->irq_reg_sts) {
/* disable interrupts */
pch_spi_setclr_reg(data->host, PCH_SPCR, 0, PCH_ALL);
data->irq_reg_sts = false;
free_irq(board_dat->pdev->irq, data);
}In final 5.15.y, the equivalent spi_master_get()/spi_unregister_master() still happens after queue/status teardown, pch_spi_free_resources(), IRQ disable, and free_irq():
pch_spi_free_resources(board_dat, data);
if (data->irq_reg_sts) {
pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL);
data->irq_reg_sts = false;
free_irq(board_dat->pdev->irq, data);
}
spi_master_get(data->master);
spi_unregister_master(data->master);The spi_master_* names are equivalent wrappers for the controller APIs in 5.15.y, but the call placement is still the old ordering. That leaves child SPI devices registered while the driver has already started tearing down controller resources.
I think for 5.15.y we should fix the backport by moving spi_master_get() and spi_unregister_master() before the local queue/resource/IRQ teardown in pch_spi_pd_remove(), thoughts?
Thanks,
Harshit
Quoted 5 lines
drivers/spi/spi-topcliff-pch.c +0
-0#ifdef CONFIG_PM static int pch_spi_pd_suspend(struct platform_device *pd_dev,
Re: [PATCH 5.15 323/411] spi: topcliff-pch: fix controller deregistration
Quoted 90 lines · Harshit Mogalapalli
Hi Greg/Sasha,
Quoted 11 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit
5d6f477d6fc0767c57c5e1e6f55a1662820eef87]Make sure to deregister the controller before disabling and releasing underlying resources like interrupts and DMA during driver unbind.
^^ let us remember this -- deregister before releasing irqs.
Quoted 16 lines
Fixes e8b17b5b3f30 ("spi/topcliff: Add topcliff platform controller hub (PCH) spi bus driver")Cc [email protected] # 2.6.37Cc Masayuki Ohtake <[email protected]>Signed-off-by Johan Hovold <[email protected]>Signed-off-by Mark Brown <[email protected]>[ renamed spi_controller_*(data->host) calls to spi_master_*(data->master) ]Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/spi/spi-topcliff-pch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/spi/spi-topcliff-pch.c static void pch_spi_pd_remove(struct pla · line 1451
Quoted 2 lines
drivers/spi/spi-topcliff-pch.c +0
-0@@ -1450,11 +1450,16 @@ static void pch_spi_pd_remove(struct plafree_irq (board_dat->pdev->irq, data); }^^^ let us remember this.
drivers/spi/spi-topcliff-pch.c static void pch_spi_pd_remove(struct pla · line 1463
Quoted 13 lines
drivers/spi/spi-topcliff-pch.c +6
-1+spi_master_get (data->master); + +spi_unregister_master (data->master); +if (use_dma)pch_free_dma_buf (board_dat, data);pci_iounmap (board_dat->pdev, data->io_remap_addr); -spi_unregister_master (data->master); + +spi_master_put (data->master); }I ran an AI assisted backport review over the 5.15.210 queue and then checked this one manually. I think the 5.15.y backport keeps the API mapping, but not the upstream teardown ordering.
Upstream
5d6f477d6fc0unregisters the controller before the local teardown:spi_controller_get(data->host); spi_unregister_controller(data->host); if (use_dma) pch_free_dma_buf(board_dat, data); ... pch_spi_free_resources(board_dat, data); /* disable interrupts & free IRQ */ if (data->irq_reg_sts) { /* disable interrupts */ pch_spi_setclr_reg(data->host, PCH_SPCR, 0, PCH_ALL); data->irq_reg_sts = false; free_irq(board_dat->pdev->irq, data); }In final 5.15.y, the equivalent spi_master_get()/spi_unregister_master() still happens after queue/status teardown,
pch_spi_free_resources(), IRQ disable, andfree_irq():pch_spi_free_resources(board_dat, data); if (data->irq_reg_sts) { pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL); data->irq_reg_sts = false; free_irq(board_dat->pdev->irq, data); } spi_master_get(data->master); spi_unregister_master(data->master);
Quoted 8 lines
The spi_master_* names are equivalent wrappers for the controller APIs in 5.15.y, but the call placement is still the old ordering. That leaves child SPI devices registered while the driver has already started tearing down controller resources.
I think for 5.15.y we should fix the backport by moving
spi_master_get()andspi_unregister_master()before the local queue/resource/IRQ teardown inpch_spi_pd_remove(), thoughts?
I agree, this backport looks wrong.
This is probably an effect of
9d72732fe70c ("spi: topcliff-pch: fix use-after-free on unbind")being backported before
9d72732fe70c ("spi: topcliff-pch: fix use-after-free on unbind")due to the latter first failing to apply because of the SPI API rename.
Johan
Re: [PATCH 5.15 323/411] spi: topcliff-pch: fix controller deregistration
Quoted 19 lines · Johan Hovold
Quoted 7 lines · Harshit Mogalapalli
Quoted 6 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
Quoted 8 lines
Quoted 4 lines
[ Upstream commit
5d6f477d6fc0767c57c5e1e6f55a1662820eef87]Make sure to deregister the controller before disabling and releasing underlying resources like interrupts and DMA during driver unbind.
I think for 5.15.y we should fix the backport by moving
spi_master_get()andspi_unregister_master()before the local queue/resource/IRQ teardown inpch_spi_pd_remove(), thoughts?I agree, this backport looks wrong.
Quoted 7 lines
This is probably an effect of
9d72732fe70c ("spi: topcliff-pch: fix use-after-free on unbind")being backported before
9d72732fe70c ("spi: topcliff-pch: fix use-after-free on unbind")
This was supposed to say
5d6f477d6fc0 ("spi: topcliff-pch: fix controller deregistration")
of course...
Quoted 1 line
due to the latter first failing to apply because of the SPI API rename.
Johan
Re: [PATCH 5.15 323/411] spi: topcliff-pch: fix controller deregistration
In reply to Greg Kroah-HartmanQuoted 7 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit
5d6f477d6fc0767c57c5e1e6f55a1662820eef87]
[...]
Aside from the issue already pointed out with this backport, the fix is also missing from the 6.1 and 6.6 branches.
Ben.
Signature · 2 lines
Ben Hutchings Anthony's Law of Force: Don't force it, get a larger hammer.
Greg Kroah-Hartman
maintainerPATCH 324/411 btrfs: fix btrfs_ioctl_space_info() slot_count TOCTOU which can lead to info-leak
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yochai Eisenrich <[email protected]>
[ Upstream commit 973e57c726c1f8e77259d1c8e519519f1e9aea77 ]
btrfs_ioctl_space_info() has a TOCTOU race between two passes over the block group RAID type lists. The first pass counts entries to determine the allocation size, then the second pass fills the buffer. The groups_sem rwlock is released between passes, allowing concurrent block group removal to reduce the entry count.
When the second pass fills fewer entries than the first pass counted, copy_to_user() copies the full alloc_size bytes including trailing uninitialized kmalloc bytes to userspace.
Fix by copying only total_spaces entries (the actually-filled count from the second pass) instead of alloc_size bytes, and switch to kzalloc so any future copy size mismatch cannot leak heap data.
--- fs/btrfs/ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.c +3 -2
@@ -3612,7 +3612,7 @@ static long btrfs_ioctl_space_info(strucreturn -ENOMEM ; space_args.total_spaces =0 ; - dest =kmalloc (alloc_size,GFP_KERNEL ); + dest =kzalloc (alloc_size,GFP_KERNEL );if (!dest)return -ENOMEM ; dest_orig = dest;
@@ -3668,7 +3668,8 @@ static long btrfs_ioctl_space_info(struc user_dest = (struct btrfs_ioctl_space_info __user *) (arg +sizeof (struct btrfs_ioctl_space_args )); -if (copy_to_user (user_dest, dest_orig, alloc_size)) +if (copy_to_user (user_dest, dest_orig, + space_args.total_spaces *sizeof (*dest_orig))) ret = -EFAULT ;kfree (dest_orig);
Greg Kroah-Hartman
maintainerPATCH 325/411 tracing/probes: Limit size of event probe to 3K
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit b2aa3b4d64e460ac606f386c24e7d8a873ce6f1a ]
There currently isn't a max limit an event probe can be. One could make an event greater than PAGE_SIZE, which makes the event useless because if it's bigger than the max event that can be recorded into the ring buffer, then it will never be recorded.
A event probe should never need to be greater than 3K, so make that the max size. As long as the max is less than the max that can be recorded onto the ring buffer, it should be fine.
--- kernel/trace/trace_probe.c | 6 ++++++ kernel/trace/trace_probe.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-)
kernel/trace/trace_probe.c +6 -0
@@ -647,6 +647,12 @@ static int traceprobe_parse_probe_arg_bo parg->offset = *size; *size += parg->type->size * (parg->count ?:1 ); +if (*size >MAX_PROBE_EVENT_SIZE ) { + ret = -E2BIG ; +trace_probe_log_err (offset,EVENT_TOO_BIG ); + goto out; + } + ret = -ENOMEM ;if (parg->count) { len =strlen (parg->type->fmttype) +6 ;
kernel/trace/trace_probe.h +3 -1
@@ -33,6 +33,7 @@#define MAX_ARRAY_LEN 64#define MAX_ARG_NAME_LEN 32#define MAX_STRING_SIZE PATH_MAX +#define MAX_PROBE_EVENT_SIZE 3072/* Reserved field names */ #define FIELD_STRING_IP "__probe_ip"
@@ -455,7 +456,8 @@ extern int traceprobe_define_arg_fields(C (FAIL_REG_PROBE ,"Failed to register probe event" ),\C (DIFF_PROBE_TYPE ,"Probe type is different from existing probe" ),\C (DIFF_ARG_TYPE ,"Argument type or name is different from existing probe" ),\ -C (SAME_PROBE ,"There is already the exact same probe event" ), +C (SAME_PROBE ,"There is already the exact same probe event" ),\ +C (EVENT_TOO_BIG ,"Event too big (too many fields?)" ), #undef C #define C(a, b) TP_ERR_##a
Greg Kroah-Hartman
maintainerPATCH 326/411 pmdomain: core: Fix detach procedure for virtual devices in genpd
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Hansson <[email protected]>
[ Upstream commit 26735dfdd8930d9ef1fa92e590a9bf77726efdf6 ]
If a device is attached to a PM domain through genpd_dev_pm_attach_by_id(), genpd calls pm_runtime_enable() for the corresponding virtual device that it registers. While this avoids boilerplate code in drivers, there is no corresponding call to pm_runtime_disable() in genpd_dev_pm_detach().
This means these virtual devices are typically detached from its genpd, while runtime PM remains enabled for them, which is not how things are designed to work. In worst cases it may lead to critical errors, like a NULL pointer dereference bug in genpd_runtime_suspend(), which was recently reported. For another case, we may end up keeping an unnecessary vote for a performance state for the device.
To fix these problems, let's add this missing call to pm_runtime_disable() in genpd_dev_pm_detach().
--- drivers/base/power/domain.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/base/power/domain.c +9 -1
@@ -2596,6 +2596,7 @@ static struct bus_type genpd_bus_type =static void genpd_dev_pm_detach (struct device *dev,bool power_off) {struct generic_pm_domain *pd; +bool is_virt_dev;unsigned int i;int ret =0 ;
@@ -2605,6 +2606,13 @@ static void genpd_dev_pm_detach(struct ddev_dbg (dev,"removing from PM domain %s\n" , pd->name); +/* Check if the device was created by genpd at attach. */ + is_virt_dev = dev->bus == &genpd_bus_type; + +/* Disable runtime PM if we enabled it at attach. */ +if (is_virt_dev) +pm_runtime_disable (dev); +/* Drop the default performance state */ if (dev_gpd_data (dev)->default_pstate) {dev_pm_genpd_set_performance_state (dev,0 );
@@ -2630,7 +2638,7 @@ static void genpd_dev_pm_detach(struct dgenpd_queue_power_off_work (pd);/* Unregister the device if it was created by genpd. */ -if (dev->bus == &genpd_bus_type) +if (is_virt_dev)device_unregister (dev); }
Greg Kroah-Hartman
maintainerPATCH 327/411 smb: client: validate dacloffset before building DACL pointers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit f98b48151cc502ada59d9778f0112d21f2586ca3 ]
parse_sec_desc(), build_sec_desc(), and the chown path in id_mode_to_cifs_acl() all add the server-supplied dacloffset to pntsd before proving a DACL header fits inside the returned security descriptor.
On 32-bit builds a malicious server can return dacloffset near U32_MAX, wrap the derived DACL pointer below end_of_acl, and then slip past the later pointer-based bounds checks. build_sec_desc() and id_mode_to_cifs_acl() can then dereference DACL fields from the wrapped pointer in the chmod/chown rewrite paths.
Validate dacloffset numerically before building any DACL pointer and reuse the same helper at the three DACL entry points.
--- fs/cifs/cifsacl.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
fs/cifs/cifsacl.c +32 -3
@@ -1254,6 +1254,17 @@ static int parse_sid(struct cifs_sid *psreturn 0 ; } +static bool dacl_offset_valid (unsigned int acl_len,__u32 dacloffset) +{ +if (acl_len <sizeof (struct cifs_acl )) +return false; + +if (dacloffset <sizeof (struct cifs_ntsd )) +return false; + +return dacloffset <= acl_len -sizeof (struct cifs_acl ); +} +/* Convert CIFS ACL to POSIX form */ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
@@ -1274,7 +1285,6 @@ static int parse_sec_desc(struct cifs_sb group_sid_ptr = (struct cifs_sid *)((char *)pntsd +le32_to_cpu (pntsd->gsidoffset)); dacloffset =le32_to_cpu (pntsd->dacloffset); - dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); cifs_dbg(NOISY, "revision %d type 0x%x ooffset 0x%x goffset 0x%x sacloffset 0x%x dacloffset 0x%x\n", pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset), le32_to_cpu(pntsd->gsidoffset),
@@ -1305,11 +1315,18 @@ static int parse_sec_desc(struct cifs_sbreturn rc; } -if (dacloffset) +if (dacloffset) { +if (!dacl_offset_valid (acl_len, dacloffset)) { +cifs_dbg (VFS ,"Server returned illegal DACL offset\n" ); +return -EINVAL ; + } + + dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset);parse_dacl (dacl_ptr, end_of_acl, owner_sid_ptr, group_sid_ptr, fattr, get_mode_from_special_sid); -else + }else {cifs_dbg (FYI ,"no ACL\n" );/* BB grant all or default perms? */ + }return rc; }
@@ -1332,6 +1349,11 @@ static int build_sec_desc(struct cifs_nt dacloffset =le32_to_cpu (pntsd->dacloffset);if (dacloffset) { +if (!dacl_offset_valid (secdesclen, dacloffset)) { +cifs_dbg (VFS ,"Server returned illegal DACL offset\n" ); +return -EINVAL ; + } + dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); rc =validate_dacl (dacl_ptr, end_of_acl);if (rc)
@@ -1694,6 +1716,12 @@ id_mode_to_cifs_acl(struct inode *inode, nsecdesclen =sizeof (struct cifs_ntsd ) + (sizeof (struct cifs_sid ) *2 ); dacloffset =le32_to_cpu (pntsd->dacloffset);if (dacloffset) { +if (!dacl_offset_valid (secdesclen, dacloffset)) { +cifs_dbg (VFS ,"Server returned illegal DACL offset\n" ); + rc = -EINVAL ; + goto id_mode_to_cifs_acl_exit; + } + dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); rc =validate_dacl (dacl_ptr, (char *)pntsd + secdesclen);if (rc) {
@@ -1736,6 +1764,7 @@ id_mode_to_cifs_acl(struct inode *inode, rc = ops->set_acl (pnntsd, nsecdesclen, inode, path, aclflag);cifs_dbg (NOISY ,"set_cifs_acl rc: %d\n" , rc); } +id_mode_to_cifs_acl_exit:cifs_put_tlink (tlink);kfree (pnntsd);
Greg Kroah-Hartman
maintainerPATCH 328/411 btrfs: fix missing last_unlink_trans update when removing a directory
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 999757231c49376cd1a37308d2c8c4c9932571e1 ]
When removing a directory we are not updating its last_unlink_trans field, which can result in incorrect fsync behaviour in case some one fsyncs the directory after it was removed because it's holding a file descriptor on it.
Example scenario:
mkdir /mnt/dir1
mkdir /mnt/dir1/dir2
mkdir /mnt/dir3
sync -f /mnt
# Do some change to the directory and fsync it. chmod 700 /mnt/dir1
xfs_io -c fsync /mnt/dir1
# Move dir2 out of dir1 so that dir1 becomes empty. mv /mnt/dir1/dir2 /mnt/dir3/
open fd on /mnt/dir1
call rmdir(2) on path "/mnt/dir1"
fsync fd
<trigger power failure>
When attempting to mount the filesystem, the log replay will fail with an -EIO error and dmesg/syslog has the following:
[445771.626482] BTRFS info (device dm-0): first mount of filesystem 0368bbea-6c5e-44b5-b409-09abe496e650 [445771.626486] BTRFS info (device dm-0): using crc32c checksum algorithm [445771.627912] BTRFS info (device dm-0): start tree-log replay [445771.628335] page: refcount:2 mapcount:0 mapping:0000000061443ddc index:0x1d00 pfn:0x7072a5 [445771.629453] memcg:ffff89f400351b00 [445771.629892] aops:btree_aops [btrfs] ino:1 [445771.630737] flags: 0x17fffc00000402a(uptodate|lru|private|writeback|node=0|zone=2|lastcpupid=0x1ffff) [445771.632359] raw: 017fffc00000402a fffff47284d950c8 fffff472907b7c08 ffff89f458e412b8 [445771.633713] raw: 0000000000001d00 ffff89f6c51d1a90 00000002ffffffff ffff89f400351b00 [445771.635029] page dumped because: eb page dump [445771.635825] BTRFS critical (device dm-0): corrupt leaf: root=5 block=30408704 slot=10 ino=258, invalid nlink: has 2 expect no more than 1 for dir [445771.638088] BTRFS info (device dm-0): leaf 30408704 gen 10 total ptrs 17 free space 14878 owner 5 [445771.638091] BTRFS info (device dm-0): refs 4 lock_owner 0 current 3581087 [445771.638094] item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160 [445771.638097] inode generation 3 transid 9 size 16 nbytes 16384 [445771.638098] block group 0 mode 40755 links 1 uid 0 gid 0 [445771.638100] rdev 0 sequence 2 flags 0x0 [445771.638102] atime 1775744884.0 [445771.660056] ctime 1775744885.645502983 [445771.660058] mtime 1775744885.645502983 [445771.660060] otime 1775744884.0 [445771.660062] item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12 [445771.660064] index 0 name_len 2 [445771.660066] item 2 key (256 DIR_ITEM 1843588421) itemoff 16077 itemsize 34 [445771.660068] location key (259 1 0) type 2 [445771.660070] transid 9 data_len 0 name_len 4 [445771.660075] item 3 key (256 DIR_ITEM 2363071922) itemoff 16043 itemsize 34 [445771.660076] location key (257 1 0) type 2 [445771.660077] transid 9 data_len 0 name_len 4 [445771.660078] item 4 key (256 DIR_INDEX 2) itemoff 16009 itemsize 34 [445771.660079] location key (257 1 0) type 2 [445771.660080] transid 9 data_len 0 name_len 4 [445771.660081] item 5 key (256 DIR_INDEX 3) itemoff 15975 itemsize 34 [445771.660082] location key (259 1 0) type 2 [445771.660083] transid 9 data_len 0 name_len 4 [445771.660084] item 6 key (257 INODE_ITEM 0) itemoff 15815 itemsize 160 [445771.660086] inode generation 9 transid 9 size 8 nbytes 0 [445771.660087] block group 0 mode 40777 links 1 uid 0 gid 0 [445771.660088] rdev 0 sequence 2 flags 0x0 [445771.660089] atime 1775744885.641174097 [445771.660090] ctime 1775744885.645502983 [445771.660091] mtime 1775744885.645502983 [445771.660105] otime 1775744885.641174097 [445771.660106] item 7 key (257 INODE_REF 256) itemoff 15801 itemsize 14 [445771.660107] index 2 name_len 4 [445771.660108] item 8 key (257 DIR_ITEM 2676584006) itemoff 15767 itemsize 34 [445771.660109] location key (258 1 0) type 2 [445771.660110] transid 9 data_len 0 name_len 4 [445771.660111] item 9 key (257 DIR_INDEX 2) itemoff 15733 itemsize 34 [445771.660112] location key (258 1 0) type 2 [445771.660113] transid 9 data_len 0 name_len 4 [445771.660114] item 10 key (258 INODE_ITEM 0) itemoff 15573 itemsize 160 [445771.660115] inode generation 9 transid 10 size 0 nbytes 0 [445771.660116] block group 0 mode 40755 links 2 uid 0 gid 0 [445771.660117] rdev 0 sequence 0 flags 0x0 [445771.660118] atime 1775744885.645502983 [445771.660119] ctime 1775744885.645502983 [445771.660120] mtime 1775744885.645502983 [445771.660121] otime 1775744885.645502983 [445771.660122] item 11 key (258 INODE_REF 257) itemoff 15559 itemsize 14 [445771.660123] index 2 name_len 4 [445771.660124] item 12 key (258 INODE_REF 259) itemoff 15545 itemsize 14 [445771.660125] index 2 name_len 4 [445771.660126] item 13 key (259 INODE_ITEM 0) itemoff 15385 itemsize 160 [445771.660127] inode generation 9 transid 10 size 8 nbytes 0 [445771.660128] block group 0 mode 40755 links 1 uid 0 gid 0 [445771.660129] rdev 0 sequence 1 flags 0x0 [445771.660130] atime 1775744885.645502983 [445771.660130] ctime 1775744885.645502983 [445771.660131] mtime 1775744885.645502983 [445771.660132] otime 1775744885.645502983 [445771.660133] item 14 key (259 INODE_REF 256) itemoff 15371 itemsize 14 [445771.660134] index 3 name_len 4 [445771.660135] item 15 key (259 DIR_ITEM 2676584006) itemoff 15337 itemsize 34 [445771.660136] location key (258 1 0) type 2 [445771.660137] transid 10 data_len 0 name_len 4 [445771.660138] item 16 key (259 DIR_INDEX 2) itemoff 15303 itemsize 34 [445771.660139] location key (258 1 0) type 2 [445771.660140] transid 10 data_len 0 name_len 4 [445771.660144] BTRFS error (device dm-0): block=30408704 write time tree block corruption detected [445771.661650] ------------[ cut here ]------------ [445771.662358] WARNING: fs/btrfs/disk-io.c:326 at btree_csum_one_bio+0x217/0x230 [btrfs], CPU#8: mount/3581087 [445771.663588] Modules linked in: btrfs f2fs xfs (...) [445771.671229] CPU: 8 UID: 0 PID: 3581087 Comm: mount Tainted: G W 7.0.0-rc6-btrfs-next-230+ #2 PREEMPT(full) [445771.672575] Tainted: [W]=WARN [445771.672987] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014 [445771.674460] RIP: 0010:btree_csum_one_bio+0x217/0x230 [btrfs] [445771.675222] Code: 89 44 24 (...) [445771.677364] RSP: 0018:ffffd23882247660 EFLAGS: 00010246 [445771.678029] RAX: 0000000000000000 RBX: ffff89f6c51d1a90 RCX: 0000000000000000 [445771.678975] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff89f406020000 [445771.679983] RBP: ffff89f821204000 R08: 0000000000000000 R09: 00000000ffefffff [445771.680905] R10: ffffd23882247448 R11: 0000000000000003 R12: ffffd23882247668 [445771.681978] R13: ffff89f458e40fc0 R14: ffff89f737f4f500 R15: ffff89f737f4f500 [445771.682912] FS: 00007f0447a98840(0000) GS:ffff89fb9771d000(0000) knlGS:0000000000000000 [445771.684393] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [445771.685230] CR2: 00007f0447bf1330 CR3: 000000017cb02002 CR4: 0000000000370ef0 [445771.686273] Call Trace: [445771.686646] <TASK> [445771.686969] btrfs_submit_bbio+0x83f/0x860 [btrfs] [445771.687750] ? write_one_eb+0x28f/0x340 [btrfs] [445771.688428] btree_writepages+0x2e3/0x550 [btrfs] [445771.689180] ? kmem_cache_alloc_noprof+0x12a/0x490 [445771.689963] ? alloc_extent_state+0x19/0x120 [btrfs] [445771.690801] ? kmem_cache_free+0x135/0x380 [445771.691328] ? preempt_count_add+0x69/0xa0 [445771.691831] ? set_extent_bit+0x252/0x8e0 [btrfs] [445771.692468] ? xas_load+0x9/0xc0 [445771.692873] ? xas_find+0x14d/0x1a0 [445771.693304] do_writepages+0xc6/0x160 [445771.693756] filemap_writeback+0xb8/0xe0 [445771.694274] btrfs_write_marked_extents+0x61/0x170 [btrfs] [445771.694999] btrfs_write_and_wait_transaction+0x4e/0xc0 [btrfs] [445771.695818] btrfs_commit_transaction+0x5c8/0xd10 [btrfs] [445771.696530] ? kmem_cache_free+0x135/0x380 [445771.697120] ? release_extent_buffer+0x34/0x160 [btrfs] [445771.697786] btrfs_recover_log_trees+0x7be/0x7e0 [btrfs] [445771.698525] ? __pfx_replay_one_buffer+0x10/0x10 [btrfs] [445771.699206] open_ctree+0x11e5/0x1810 [btrfs] [445771.699776] btrfs_get_tree.cold+0xb/0x162 [btrfs] [445771.700463] ? fscontext_read+0x165/0x180 [445771.701146] ? rw_verify_area+0x50/0x180 [445771.701866] vfs_get_tree+0x25/0xd0 [445771.702491] vfs_cmd_create+0x59/0xe0 [445771.703125] __do_sys_fsconfig+0x303/0x610 [445771.703603] do_syscall_64+0xe9/0xf20 [445771.703974] entry_SYSCALL_64_after_hwframe+0x76/0x7e [445771.704700] RIP: 0033:0x7f0447cbd4aa [445771.705108] Code: 73 01 c3 (...) [445771.707263] RSP: 002b:00007ffc4e528318 EFLAGS: 00000246 ORIG_RAX: 00000000000001af [445771.708107] RAX: ffffffffffffffda RBX: 00005561585d8c20 RCX: 00007f0447cbd4aa [445771.708931] RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000000000000003 [445771.709744] RBP: 00005561585d9120 R08: 0000000000000000 R09: 0000000000000000 [445771.710674] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 [445771.711477] R13: 00007f0447e4f580 R14: 00007f0447e5126c R15: 00007f0447e36a23 [445771.712277] </TASK> [445771.712541] ---[ end trace 0000000000000000 ]--- [445771.713382] BTRFS error (device dm-0): error while writing out transaction: -5 [445771.714679] BTRFS warning (device dm-0): Skipping commit of aborted transaction. [445771.715562] BTRFS error (device dm-0 state A): Transaction aborted (error -5) [445771.716459] BTRFS: error (device dm-0 state A) in cleanup_transaction:2068: errno=-5 IO failure [445771.717936] BTRFS error (device dm-0 state EA): failed to recover log trees with error: -5 [445771.719681] BTRFS error (device dm-0 state EA): open_ctree failed: -5
The problem is that such a fsync should have result in a fallback to a transaction commit, but that did not happen because through the btrfs_rmdir() we never update the directory's last_unlink_trans field. Any inode that had a link removed must have its last_unlink_trans updated to the ID of transaction used for the operation, otherwise fsync and log replay will not work correctly.
btrfs_rmdir() calls btrfs_unlink_inode() and through that call chain we never call btrfs_record_unlink_dir() in order to update last_unlink_trans. However btrfs_unlink(), which is used for unlinking regular files, calls btrfs_record_unlink_dir() and then calls btrfs_unlink_inode(). So fix this by moving the call to btrfs_record_unlink_dir() from btrfs_unlink() to btrfs_unlink_inode().
A test case for fstests will follow soon.
--- fs/btrfs/inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/inode.c +2 -0
@@ -4691,6 +4691,8 @@ static int btrfs_rmdir(struct inode *dirif (err) goto out; +btrfs_record_unlink_dir (trans,BTRFS_I (dir),BTRFS_I (inode), false); +/* now the directory is empty */ err = btrfs_unlink_inode(trans, BTRFS_I(dir), BTRFS_I(d_inode(dentry)), dentry->d_name.name,
Greg Kroah-Hartman
maintainerPATCH 329/411 smb: client: Use FullSessionKey for AES-256 encryption key derivation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Piyush Sachdeva <[email protected]>
[ Upstream commit 5be7a0cef3229fb3b63a07c0d289daf752545424 ]
When Kerberos authentication is used with AES-256 encryption (AES-256-CCM or AES-256-GCM), the SMB3 encryption and decryption keys must be derived using the full session key (Session.FullSessionKey) rather than just the first 16 bytes (Session.SessionKey).
Per MS-SMB2 section 3.2.5.3.1, when Connection.Dialect is "3.1.1" and Connection.CipherId is AES-256-CCM or AES-256-GCM, Session.FullSessionKey must be set to the full cryptographic key from the GSS authentication context. The encryption and decryption key derivation (SMBC2SCipherKey, SMBS2CCipherKey) must use this FullSessionKey as the KDF input. The signing key derivation continues to use Session.SessionKey (first 16 bytes) in all cases.
Previously, generate_key() hardcoded SMB2_NTLMV2_SESSKEY_SIZE (16) as the HMAC-SHA256 key input length for all derivations. When Kerberos with AES-256 provides a 32-byte session key, the KDF for encryption/decryption was using only the first 16 bytes, producing keys that did not match the server's, causing mount failures with sec=krb5 and require_gcm_256=1.
Add a full_key_size parameter to generate_key() and pass the appropriate size from generate_smb3signingkey():
- Signing: always SMB2_NTLMV2_SESSKEY_SIZE (16 bytes)
- Encryption/Decryption: ses->auth_key.len when AES-256, otherwise 16
Also fix cifs_dump_full_key() to report the actual session key length for AES-256 instead of hardcoded CIFS_SESS_KEY_SIZE, so that userspace tools like Wireshark receive the correct key for decryption.
--- fs/cifs/ioctl.c | 2 +- fs/cifs/smb2transport.c | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-)
fs/cifs/ioctl.c +1 -1
@@ -262,7 +262,7 @@ search_end:break ;case SMB2_ENCRYPTION_AES256_CCM :case SMB2_ENCRYPTION_AES256_GCM : - out.session_key_length =CIFS_SESS_KEY_SIZE ; + out.session_key_length = ses->auth_key.len; out.server_in_key_length = out.server_out_key_length =SMB3_GCM256_CRYPTKEY_SIZE ;break ;default :
fs/cifs/smb2transport.c +26 -10
@@ -291,7 +291,8 @@ out: }static int generate_key (struct cifs_ses *ses,struct kvec label, -struct kvec context,__u8 *key,unsigned int key_size) +struct kvec context,__u8 *key,unsigned int key_size, +unsigned int full_key_size) {unsigned char zero =0x0 ;__u8 i[4 ] = {0 ,0 ,0 ,1 };
@@ -312,7 +313,7 @@ static int generate_key(struct cifs_ses } rc =crypto_shash_setkey (server->secmech.hmacsha256, - ses->auth_key.response,SMB2_NTLMV2_SESSKEY_SIZE ); + ses->auth_key.response, full_key_size);if (rc) {cifs_server_dbg (VFS ,"%s: Could not set with session key\n" , __func__); goto smb3signkey_ret;
@@ -393,10 +394,9 @@ static int generate_smb3signingkey(struct cifs_ses *ses, const struct derivation_triplet *ptriplet) { - int rc; -#ifdef CONFIG_CIFS_DEBUG_DUMP_KEYS + unsigned int full_key_size = SMB2_NTLMV2_SESSKEY_SIZE;struct TCP_Server_Info *server = ses->server; -#endif +int rc;/* * All channels use the same encryption/decryption keys but
@@ -412,30 +412,46 @@ generate_smb3signingkey(struct cifs_ses rc =generate_key (ses, ptriplet->signing.label, ptriplet->signing.context,cifs_ses_binding_channel (ses)->signkey, -SMB3_SIGN_KEY_SIZE ); +SMB3_SIGN_KEY_SIZE , +SMB2_NTLMV2_SESSKEY_SIZE );if (rc)return rc; }else { rc =generate_key (ses, ptriplet->signing.label, ptriplet->signing.context, ses->smb3signingkey, -SMB3_SIGN_KEY_SIZE ); +SMB3_SIGN_KEY_SIZE , +SMB2_NTLMV2_SESSKEY_SIZE );if (rc)return rc; +/* +* Per MS-SMB2 3.2.5.3.1, signing key always uses Session.SessionKey +* (first 16 bytes). Encryption/decryption keys use +* Session.FullSessionKey when dialect is 3.1.1 and cipher is +* AES-256-CCM or AES-256-GCM, otherwise Session.SessionKey. +*/ + +if (server->dialect ==SMB311_PROT_ID && + (server->cipher_type ==SMB2_ENCRYPTION_AES256_CCM || + server->cipher_type ==SMB2_ENCRYPTION_AES256_GCM )) + full_key_size = ses->auth_key.len; +memcpy (ses->chans[0 ].signkey, ses->smb3signingkey,SMB3_SIGN_KEY_SIZE ); rc =generate_key (ses, ptriplet->encryption.label, ptriplet->encryption.context, ses->smb3encryptionkey, -SMB3_ENC_DEC_KEY_SIZE ); +SMB3_ENC_DEC_KEY_SIZE , + full_key_size);if (rc)return rc; rc =generate_key (ses, ptriplet->decryption.label, ptriplet->decryption.context, ses->smb3decryptionkey, -SMB3_ENC_DEC_KEY_SIZE ); +SMB3_ENC_DEC_KEY_SIZE , + full_key_size);if (rc)return rc; }
@@ -450,7 +466,7 @@ generate_smb3signingkey(struct cifs_ses &ses->Suid);cifs_dbg (VFS ,"Cipher type %d\n" , server->cipher_type);cifs_dbg (VFS ,"Session Key %*ph\n" , -SMB2_NTLMV2_SESSKEY_SIZE , ses->auth_key.response); + (int )ses->auth_key.len, ses->auth_key.response);cifs_dbg (VFS ,"Signing Key %*ph\n" ,SMB3_SIGN_KEY_SIZE , ses->smb3signingkey); if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
Greg Kroah-Hartman
maintainerPATCH 330/411 mptcp: pm: prio: skip closed subflows
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit 166b78344031bf7ac9f55cb5282776cfd85f220e ]
When sending an MP_PRIO, closed subflows need to be skipped.
This fixes the case where the initial subflow got closed, re-opened later, then an MP_PRIO is needed for the same local address.
Note that explicit MP_PRIO cannot be sent during the 3WHS, so it is fine to use __mptcp_subflow_active().
--- net/mptcp/pm_netlink.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/pm_netlink.c +3 -0
@@ -828,6 +828,9 @@ int mptcp_pm_nl_mp_prio_send_ack(structstruct sock *sk = (struct sock *)msk;struct mptcp_addr_info local; +if (!__mptcp_subflow_active (subflow)) +continue ; +mptcp_local_address ((struct sock_common *)ssk, &local);if (!addresses_equal (&local, addr, addr->port))continue ;
Greg Kroah-Hartman
maintainerPATCH 331/411 mptcp: pm: ADD_ADDR rtx: fix potential data-race
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit 5cd6e0ad79d2615264f63929f8b457ad97ae550d ]
This mptcp_pm_add_timer() helper is executed as a timer callback in softirq context. To avoid any data races, the socket lock needs to be held with bh_lock_sock().
If the socket is in use, retry again soon after, similar to what is done with the keepalive timer.
--- net/mptcp/pm_netlink.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/mptcp/pm_netlink.c +8 -0
@@ -330,6 +330,13 @@ static void mptcp_pm_add_timer(struct tiif (!entry->addr.id)return ; +bh_lock_sock (sk); +if (sock_owned_by_user (sk)) { +/* Try again later. */ +sk_reset_timer (sk, timer, jiffies +HZ /20 ); + goto out; + } +if (mptcp_pm_should_add_signal_addr (msk)) {sk_reset_timer (sk, timer, jiffies +TCP_RTO_MAX /8 ); goto out;
@@ -358,6 +365,7 @@ static void mptcp_pm_add_timer(struct timptcp_pm_subflow_established (msk); out: +bh_unlock_sock (sk);__sock_put (sk); }
Greg Kroah-Hartman
maintainerPATCH 332/411 mptcp: pm: ADD_ADDR rtx: resched blocked ADD_ADDR quicker
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit 3cf12492891c4b5ff54dda404a2de4ec54c9e1b5 ]
When an ADD_ADDR needs to be retransmitted and another one has already been prepared -- e.g. multiple ADD_ADDRs have been sent in a row and need to be retransmitted later -- this additional retransmission will need to wait.
In this case, the timer was reset to TCP_RTO_MAX / 8, which is ~15 seconds. This delay is unnecessary long: it should just be rescheduled at the next opportunity, e.g. after the retransmission timeout.
Without this modification, some issues can be seen from time to time in the selftests when multiple ADD_ADDRs are sent, and the host takes time to process them, e.g. the "signal addresses, ADD_ADDR timeout" MPTCP Join selftest, especially with a debug kernel config.
Note that on older kernels, 'timeout' is not available. It should be enough to replace it by one second (HZ).
--- net/mptcp/pm_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/pm_netlink.c +1 -1
@@ -338,7 +338,7 @@ static void mptcp_pm_add_timer(struct ti }if (mptcp_pm_should_add_signal_addr (msk)) { -sk_reset_timer (sk, timer, jiffies +TCP_RTO_MAX /8 ); +sk_reset_timer (sk, timer, jiffies +HZ ); goto out; }
Greg Kroah-Hartman
maintainerPATCH 333/411 f2fs: fix incorrect file address mapping when inline inode is unwritten
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongpeng Yang <[email protected]>
[ Upstream commit 68a0178981a0f493295afa29f8880246e561494c ]
When fileinfo->fi_flags does not have the FIEMAP_FLAG_SYNC bit set and inline data has not been persisted yet, the physical address of the extent is calculated incorrectly for unwritten inline inodes.
root@vm:/mnt/f2fs# dd if=/dev/zero of=data.3k bs=3k count=1 root@vm:/mnt/f2fs# f2fs_io fiemap 0 100 data.3k Fiemap: offset = 0 len = 100 logical addr. physical addr. length flags 0 0000000000000000 00000ffffffff16c 0000000000000c00 00000301
This patch fixes the issue by checking if the inode's address is valid. If the inline inode is unwritten, set the physical address to 0 and mark the extent with FIEMAP_EXTENT_UNKNOWN | FIEMAP_EXTENT_DELALLOC flags.
--- fs/f2fs/inline.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/f2fs/inline.c +9 -4
@@ -771,7 +771,7 @@ int f2fs_read_inline_dir(struct file *fiint f2fs_inline_data_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len) { -__u64 byteaddr, ilen; +__u64 byteaddr =0 , ilen;__u32 flags =FIEMAP_EXTENT_DATA_INLINE |FIEMAP_EXTENT_NOT_ALIGNED |FIEMAP_EXTENT_LAST ;struct node_info ni;
@@ -804,9 +804,14 @@ int f2fs_inline_data_fiemap(struct inodeif (err) goto out; - byteaddr = (__u64 )ni.blk_addr << inode->i_sb->s_blocksize_bits; - byteaddr += (char *)inline_data_addr (inode, ipage) - - (char *)F2FS_INODE (ipage); +if (__is_valid_data_blkaddr (ni.blk_addr)) { + byteaddr = (__u64 )ni.blk_addr << inode->i_sb->s_blocksize_bits; + byteaddr += (char *)inline_data_addr (inode, ipage) - + (char *)F2FS_INODE (ipage); + }else { +f2fs_bug_on (F2FS_I_SB (inode), ni.blk_addr !=NEW_ADDR ); + flags |=FIEMAP_EXTENT_DELALLOC |FIEMAP_EXTENT_UNKNOWN ; + } err =fiemap_fill_next_extent (fieinfo, start, byteaddr, ilen, flags);trace_f2fs_fiemap (inode, start, byteaddr, ilen, flags, err); out:
Greg Kroah-Hartman
maintainerPATCH 334/411 f2fs: fix false alarm of lockdep on cp_global_sem lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit 6a5e3de9c2bb0b691d16789a5d19e9276a09b308 ]
lockdep reported a potential deadlock:
a) TCMU device removal context:
- call del_gendisk() to get q->q_usage_counter
- call start_flush_work() to get work_completion of wb->dwork
b) f2fs writeback context:
- in wb_workfn(), which holds work_completion of wb->dwork
- call f2fs_balance_fs() to get sbi->gc_lock
c) f2fs vfs_write context:
- call f2fs_gc() to get sbi->gc_lock
- call f2fs_write_checkpoint() to get sbi->cp_global_sem
d) f2fs mount context:
- call recover_fsync_data() to get sbi->cp_global_sem
- call f2fs_check_and_fix_write_pointer() to call blkdev_report_zones() that goes down to blk_mq_alloc_request and get q->q_usage_counter
Original callstack is in Closes tag.
However, I think this is a false alarm due to before mount returns successfully (context d), we can not access file therein via vfs_write (context c).
Let's introduce per-sb cp_global_sem_key, and assign the key for cp_global_sem, so that lockdep can recognize cp_global_sem from different super block correctly.
A lot of work are done by Shin'ichiro Kawasaki, thanks a lot for the work.
--- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 11 +++++++++++ 2 files changed, 14 insertions(+)
fs/f2fs/f2fs.h +3 -0
@@ -1798,6 +1798,9 @@ struct f2fs_sb_info {spinlock_t iostat_lat_lock;struct iostat_lat_info *iostat_io_lat;#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC +struct lock_class_key cp_global_sem_key; +#endif };struct f2fs_private_dio {
fs/f2fs/super.c +11 -0
@@ -1668,6 +1668,9 @@ static void f2fs_put_super(struct super_#ifdef CONFIG_UNICODE utf8_unload (sb->s_encoding);#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC +lockdep_unregister_key (&sbi->cp_global_sem_key); +#endif kfree (sbi); }
@@ -4123,6 +4126,11 @@ try_onemore:init_rwsem (&sbi->gc_lock);mutex_init (&sbi->writepages);init_rwsem (&sbi->cp_global_sem); +#ifdef CONFIG_DEBUG_LOCK_ALLOC +lockdep_register_key (&sbi->cp_global_sem_key); +lockdep_set_class (&sbi->cp_global_sem, + &sbi->cp_global_sem_key); +#endif init_rwsem (&sbi->node_write);init_rwsem (&sbi->node_change);
@@ -4524,6 +4532,9 @@ free_sb_buf: free_sbi:if (sbi->s_chksum_driver)crypto_free_shash (sbi->s_chksum_driver); +#ifdef CONFIG_DEBUG_LOCK_ALLOC +lockdep_unregister_key (&sbi->cp_global_sem_key); +#endif kfree (sbi);/* give only one another chance */
Greg Kroah-Hartman
maintainerPATCH 335/411 spi: st-ssc4: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 19857374010d06ca6a2f7c2c53464122eb804df0 ]
Make sure to deregister the controller before disabling underlying resources like clocks during driver unbind.
--- drivers/spi/spi-st-ssc4.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-st-ssc4.c +7 -1
@@ -372,7 +372,7 @@ static int spi_st_probe(struct platform_platform_set_drvdata (pdev, master); - ret =devm_spi_register_master (&pdev->dev, master); + ret =spi_register_master (master);if (ret) {dev_err (&pdev->dev,"Failed to register master\n" ); goto rpm_disable;
@@ -394,10 +394,16 @@ static int spi_st_remove(struct platformstruct spi_master *master =platform_get_drvdata (pdev);struct spi_st *spi_st =spi_master_get_devdata (master); +spi_master_get (master); + +spi_unregister_master (master); +pm_runtime_disable (&pdev->dev);clk_disable_unprepare (spi_st->clk); +spi_master_put (master); +pinctrl_pm_select_sleep_state (&pdev->dev);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 336/411 spi: lantiq-ssc: fix controller deregistration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit b99206710d032c16b7f8b75e4bc18414d8e4b9f4 ]
Make sure to deregister the controller before releasing underlying resources like clocks during driver unbind.
--- drivers/spi/spi-lantiq-ssc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-lantiq-ssc.c +7 -1
@@ -1003,7 +1003,7 @@ static int lantiq_ssc_probe(struct platf"Lantiq SSC SPI controller (Rev %i, TXFS %u, RXFS %u, DMA %u)\n" , revision, spi->tx_fifo_size, spi->rx_fifo_size, supports_dma); - err =devm_spi_register_master (dev, master); + err =spi_register_master (master);if (err) {dev_err (dev,"failed to register spi_master\n" ); goto err_wq_destroy;
@@ -1027,6 +1027,10 @@ static int lantiq_ssc_remove(struct plat {struct lantiq_ssc_spi *spi =platform_get_drvdata (pdev); +spi_master_get (spi->master); + +spi_unregister_master (spi->master); +lantiq_ssc_writel (spi,0 ,LTQ_SPI_IRNEN );lantiq_ssc_writel (spi,0 ,LTQ_SPI_CLC );rx_fifo_flush (spi);
@@ -1037,6 +1041,8 @@ static int lantiq_ssc_remove(struct platclk_disable_unprepare (spi->spi_clk);clk_put (spi->fpi_clk); +spi_master_put (spi->master); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 337/411 genetlink: Use internal flags for multicast groups
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit cd4d7263d58ab98fd4dee876776e4da6c328faa3 ]
As explained in commit e03781879a0d ("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group"), the "flags" field in the multicast group structure reuses uAPI flags despite the field not being exposed to user space. This makes it impossible to extend its use without adding new uAPI flags, which is inappropriate for internal kernel checks.
Solve this by adding internal flags (i.e., "GENL_MCAST_*") and convert the existing users to use them instead of the uAPI flags.
Tested using the reproducers in commit 44ec98ea5ea9 ("psample: Require 'CAP_NET_ADMIN' when joining "packets" group") and commit e03781879a0d ("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group").
No functional changes intended.
Stable-dep-of: d1ebfce2c1d1 ("smb: client: require net admin for CIFS SWN netlink")
--- include/net/genetlink.h | 9 ++++++--- net/core/drop_monitor.c | 2 +- net/mptcp/pm_netlink.c | 2 +- net/netlink/genetlink.c | 4 ++-- net/psample/psample.c | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-)
include/net/genetlink.h +6 -3
@@ -8,16 +8,19 @@#define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN) +/* Binding to multicast group requires %CAP_NET_ADMIN */ +#define GENL_MCAST_CAP_NET_ADMIN BIT(0) +/* Binding to multicast group requires %CAP_SYS_ADMIN */ +#define GENL_MCAST_CAP_SYS_ADMIN BIT(1) +/** * struct genl_multicast_group - generic netlink multicast group * @name: name of the multicast group, names are per-family -* @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM) -* @cap_sys_admin: whether %CAP_SYS_ADMIN is required for binding +* @flags: GENL_MCAST_* flags */ struct genl_multicast_group {char name[GENL_NAMSIZ ];u8 flags; -u8 cap_sys_admin:1 ; };struct genl_ops ;
net/core/drop_monitor.c +1 -1
@@ -184,7 +184,7 @@ out: }static const struct genl_multicast_group dropmon_mcgrps[] = { - { .name ="events" , .cap_sys_admin =1 }, + { .name ="events" , .flags =GENL_MCAST_CAP_SYS_ADMIN , }, };static void send_dm_alert (struct work_struct *work)
net/mptcp/pm_netlink.c +1 -1
@@ -1207,7 +1207,7 @@ void mptcp_pm_nl_data_init(struct mptcp_static const struct genl_multicast_group mptcp_pm_mcgrps[] = { [MPTCP_PM_CMD_GRP_OFFSET ] = { .name =MPTCP_PM_CMD_GRP_NAME , }, [MPTCP_PM_EV_GRP_OFFSET ] = { .name =MPTCP_PM_EV_GRP_NAME , - .flags =GENL_UNS_ADMIN_PERM , + .flags =GENL_MCAST_CAP_NET_ADMIN , }, };
net/netlink/genetlink.c +2 -2
@@ -1372,10 +1372,10 @@ static int genl_bind(struct net *net, incontinue ; grp = &family->mcgrps[i]; -if ((grp->flags &GENL_UNS_ADMIN_PERM ) && +if ((grp->flags &GENL_MCAST_CAP_NET_ADMIN ) && !ns_capable (net->user_ns,CAP_NET_ADMIN )) ret = -EPERM ; -if (grp->cap_sys_admin && +if ((grp->flags &GENL_MCAST_CAP_SYS_ADMIN ) && !ns_capable (net->user_ns,CAP_SYS_ADMIN )) ret = -EPERM ;
net/psample/psample.c +1 -1
@@ -32,7 +32,7 @@ enum psample_nl_multicast_groups {static const struct genl_multicast_group psample_nl_mcgrps[] = { [PSAMPLE_NL_MCGRP_CONFIG ] = { .name =PSAMPLE_NL_MCGRP_CONFIG_NAME }, [PSAMPLE_NL_MCGRP_SAMPLE ] = { .name =PSAMPLE_NL_MCGRP_SAMPLE_NAME , - .flags =GENL_UNS_ADMIN_PERM }, + .flags =GENL_MCAST_CAP_NET_ADMIN , }, };static struct genl_family psample_nl_family__ro_after_init ;
Greg Kroah-Hartman
maintainerPATCH 338/411 smb: client: require net admin for CIFS SWN netlink
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit d1ebfce2c1d161186a82e77590bf7da2ea1bce91 ]
CIFS_GENL_CMD_SWN_NOTIFY is the userspace witness-notify command. The intended sender is the cifs.witness helper, but the generic-netlink operation currently has no capability flag, so any local process can send RESOURCE_CHANGE or CLIENT_MOVE notifications to the in-kernel witness handler.
The same family exposes CIFS_GENL_MCGRP_SWN without multicast-group capability flags. Register messages sent to that group include the witness registration id and, for NTLM-authenticated mounts, the username, domain, and password attributes copied from the CIFS session. An unprivileged local process should not be able to join that group and receive those messages.
Require CAP_NET_ADMIN for incoming SWN_NOTIFY commands with GENL_ADMIN_PERM, and require CAP_NET_ADMIN over the network namespace for joining the SWN multicast group with GENL_MCAST_CAP_NET_ADMIN. The cifs.witness service runs with the privileges needed for both operations.
--- fs/cifs/netlink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/netlink.c +5 -1
@@ -33,13 +33,17 @@ static const struct nla_policy cifs_genlstatic const struct genl_ops cifs_genl_ops[] = { { .cmd =CIFS_GENL_CMD_SWN_NOTIFY , + .flags =GENL_ADMIN_PERM , .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , .doit = cifs_swn_notify, }, };static const struct genl_multicast_group cifs_genl_mcgrps[] = { - [CIFS_GENL_MCGRP_SWN ] = { .name =CIFS_GENL_MCGRP_SWN_NAME }, + [CIFS_GENL_MCGRP_SWN ] = { + .name =CIFS_GENL_MCGRP_SWN_NAME , + .flags =GENL_MCAST_CAP_NET_ADMIN , + }, };struct genl_family cifs_genl_family = {
Greg Kroah-Hartman
maintainerPATCH 339/411 Bluetooth: fix UAF in l2cap_sock_cleanup_listen() vs l2cap_conn_del()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Safa Karakuş <[email protected]>
[ Upstream commit ab1513597c6cf17cd1ad2a21e3b045421b48e022 ]
bt_accept_dequeue() unlinks a not-yet-accepted child from the parent accept queue and release_sock()s it before returning, so the returned sk has no caller reference and is unlocked.
l2cap_sock_cleanup_listen() walks these children on listening-socket close. A concurrent HCI disconnect drives hci_rx_work -> l2cap_conn_del() which runs l2cap_chan_del() + l2cap_sock_kill() and frees the child sk and its l2cap_chan; cleanup_listen() then uses both:
BUG: KASAN: slab-use-after-free in l2cap_sock_kill
l2cap_sock_kill / l2cap_sock_cleanup_listen / __x64_sys_close
Freed by: l2cap_conn_del -> l2cap_sock_close_cb -> l2cap_sock_killThis is distinct from the two fixes already in this area: commit e83f5e24da741 ("Bluetooth: serialize accept_q access") serialises the accept_q list/poll and takes temporary refs inside bt_accept_dequeue(), and CVE-2025-39860 serialises the userspace close()/accept() race by calling cleanup_listen() under lock_sock() in l2cap_sock_release(). Neither covers l2cap_conn_del() running from hci_rx_work, so this UAF still reproduces on current bluetooth/master.
Take the reference at the source: bt_accept_dequeue() does sock_hold() while sk is still locked, before release_sock(); callers sock_put(). cleanup_listen() pins the chan with l2cap_chan_hold_unless_zero() under a brief child sk lock (serialising vs l2cap_sock_teardown_cb()), drops it before l2cap_chan_lock(), and skips a duplicate l2cap_sock_kill() on SOCK_DEAD. conn->lock is not taken here: cleanup_listen() runs under the parent sk lock and that would invertconn->lock -> chan->lock -> sk_lock (lockdep).
KASAN/SMP: an unprivileged listen/close vs HCI-disconnect race produced 12 use-after-free reports per run before this change; 0, and no lockdep report, over 1600+ raced iterations after it on bluetooth/master.
--- net/bluetooth/af_bluetooth.c | 10 ++++++++ net/bluetooth/l2cap_sock.c | 51 +++++++++++++++++++++++++++++++++++++------ net/bluetooth/rfcomm/sock.c | 9 ++++++- net/bluetooth/sco.c | 9 ++++++- 4 files changed, 70 insertions(+), 9 deletions(-)
net/bluetooth/af_bluetooth.c +10 -0
@@ -259,6 +259,16 @@ restart:if (newsock)sock_graft (sk, newsock); +/* Hand the caller a reference taken while sk is +* still locked. bt_accept_unlink() just dropped +* the accept-queue reference; without this hold a +* concurrent teardown (e.g. l2cap_conn_del() -> +* l2cap_sock_kill()) could free sk between +* release_sock() and the caller using it. Every +* caller drops this with sock_put() when done. +*/ +sock_hold (sk); +release_sock (sk);return sk; }
net/bluetooth/l2cap_sock.c +44 -7
74 lines not on this page · raw message
net/bluetooth/rfcomm/sock.c +8 -1
@@ -190,6 +190,8 @@ static void rfcomm_sock_cleanup_listen(swhile ((sk =bt_accept_dequeue (parent,NULL ))) {rfcomm_sock_close (sk);rfcomm_sock_kill (sk); +/* Drop the reference handed back by bt_accept_dequeue(). */ +sock_put (sk); } parent->sk_state =BT_CLOSED ;
@@ -513,8 +515,13 @@ static int rfcomm_sock_accept(struct soc } nsk =bt_accept_dequeue (sk, newsock); -if (nsk) +if (nsk) { +/* Drop the bridging ref from bt_accept_dequeue(); +* the grafted socket keeps nsk alive from here. +*/ +sock_put (nsk);break ; + }if (!timeo) { err = -EAGAIN ;
net/bluetooth/sco.c +8 -1
@@ -394,6 +394,8 @@ static void sco_sock_cleanup_listen(struwhile ((sk =bt_accept_dequeue (parent,NULL ))) {sco_sock_close (sk);sco_sock_kill (sk); +/* Drop the reference handed back by bt_accept_dequeue(). */ +sock_put (sk); } parent->sk_state =BT_CLOSED ;
@@ -687,8 +689,13 @@ static int sco_sock_accept(struct socket } ch =bt_accept_dequeue (sk, newsock); -if (ch) +if (ch) { +/* Drop the bridging ref from bt_accept_dequeue(); +* the grafted socket keeps ch alive from here. +*/ +sock_put (ch);break ; + }if (!timeo) { err = -EAGAIN ;
Greg Kroah-Hartman
maintainerPATCH 340/411 Bluetooth: hci_qca: Convert timeout from jiffies to ms
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuai Zhang <[email protected]>
[ Upstream commit 375ba7484132662a4a8c7547d088fb6275c00282 ]
Since the timer uses jiffies as its unit rather than ms, the timeout value must be converted from ms to jiffies when configuring the timer. Otherwise, the intended 8s timeout is incorrectly set to approximately 33s.
To improve readability, embed msecs_to_jiffies() directly in the macro definitions and drop the _MS suffix from macros that now yield jiffies
values: MEMDUMP_TIMEOUT, FW_DOWNLOAD_TIMEOUT, IBS_DISABLE_SSR_TIMEOUT, CMD_TRANS_TIMEOUT, and IBS_BTSOC_TX_IDLE_TIMEOUT.
IBS_WAKE_RETRANS_TIMEOUT_MS and IBS_HOST_TX_IDLE_TIMEOUT_MS are intentionally left unchanged. Their values are stored in the struct fields wake_retrans and tx_idle_delay, which hold ms values at runtime and can be modified via debugfs. The msecs_to_jiffies() conversion happens at each call site against the field value, so it cannot be embedded in the macro.
Wake timer depends on commit c347ca17d62a
--- drivers/bluetooth/hci_qca.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/bluetooth/hci_qca.c +16 -17
@@ -46,13 +46,12 @@#define HCI_MAX_IBS_SIZE 10#define IBS_WAKE_RETRANS_TIMEOUT_MS 100 -#define IBS_BTSOC_TX_IDLE_TIMEOUT_MS 200 +#define IBS_BTSOC_TX_IDLE_TIMEOUT msecs_to_jiffies(200)#define IBS_HOST_TX_IDLE_TIMEOUT_MS 2000 -#define CMD_TRANS_TIMEOUT_MS 100 -#define MEMDUMP_TIMEOUT_MS 8000 -#define IBS_DISABLE_SSR_TIMEOUT_MS \ - (MEMDUMP_TIMEOUT_MS + FW_DOWNLOAD_TIMEOUT_MS) -#define FW_DOWNLOAD_TIMEOUT_MS 3000 +#define CMD_TRANS_TIMEOUT msecs_to_jiffies(100) +#define MEMDUMP_TIMEOUT msecs_to_jiffies(8000) +#define FW_DOWNLOAD_TIMEOUT msecs_to_jiffies(3000) +#define IBS_DISABLE_SSR_TIMEOUT (MEMDUMP_TIMEOUT + FW_DOWNLOAD_TIMEOUT)/* susclk rate */ #define SUSCLK_RATE_32KHZ 32768
@@ -1058,7 +1057,7 @@ static void qca_controller_memdump(struc dump_size);queue_delayed_work (qca->workqueue, &qca->ctrl_memdump_timeout, -msecs_to_jiffies (MEMDUMP_TIMEOUT_MS ) +MEMDUMP_TIMEOUT );skb_pull (skb,sizeof (dump_size));
@@ -1326,7 +1325,7 @@ static int qca_set_baudrate(struct hci_dif (hu->serdev)serdev_device_wait_until_sent (hu->serdev, -msecs_to_jiffies (CMD_TRANS_TIMEOUT_MS )); +CMD_TRANS_TIMEOUT );/* Give the controller time to process the request */ switch (qca_soc_type (hu)) {
@@ -1356,8 +1355,8 @@ static inline void host_set_baudrate(strstatic int qca_send_power_pulse (struct hci_uart *hu,bool on) { +int timeout =CMD_TRANS_TIMEOUT ;int ret; -int timeout =msecs_to_jiffies (CMD_TRANS_TIMEOUT_MS );u8 cmd = on ?QCA_WCN3990_POWERON_PULSE :QCA_WCN3990_POWEROFF_PULSE ;/* These power pulses are single byte command which are sent
@@ -1556,7 +1555,7 @@ static void qca_wait_for_dump_collectionstruct qca_data *qca = hu->priv;wait_on_bit_timeout (&qca->flags,QCA_MEMDUMP_COLLECTION , -TASK_UNINTERRUPTIBLE ,MEMDUMP_TIMEOUT_MS ); +TASK_UNINTERRUPTIBLE ,MEMDUMP_TIMEOUT );clear_bit (QCA_MEMDUMP_COLLECTION , &qca->flags); }
@@ -2345,7 +2344,7 @@ static void qca_serdev_remove(struct serstatic void qca_serdev_shutdown (struct device *dev) {int ret; -int timeout =msecs_to_jiffies (CMD_TRANS_TIMEOUT_MS ); +int timeout =CMD_TRANS_TIMEOUT ;struct serdev_device *serdev =to_serdev_device (dev);struct qca_serdev *qcadev =serdev_device_get_drvdata (serdev);struct hci_uart *hu = &qcadev->serdev_hu;
@@ -2403,7 +2402,7 @@ static int __maybe_unused qca_suspend(stbool tx_pending = false;int ret =0 ;u8 cmd; -u32 wait_timeout =0 ; +unsigned long wait_timeout =0 ;set_bit (QCA_SUSPENDING , &qca->flags);
@@ -2424,15 +2423,15 @@ static int __maybe_unused qca_suspend(stif (test_bit (QCA_IBS_DISABLED , &qca->flags) ||test_bit (QCA_SSR_TRIGGERED , &qca->flags)) { wait_timeout =test_bit (QCA_SSR_TRIGGERED , &qca->flags) ? -IBS_DISABLE_SSR_TIMEOUT_MS : -FW_DOWNLOAD_TIMEOUT_MS ; +IBS_DISABLE_SSR_TIMEOUT : +FW_DOWNLOAD_TIMEOUT ;/* QCA_IBS_DISABLED flag is set to true, During FW download * and during memory dump collection. It is reset to false, * After FW download complete. */ wait_on_bit_timeout (&qca->flags,QCA_IBS_DISABLED , -TASK_UNINTERRUPTIBLE ,msecs_to_jiffies (wait_timeout)); +TASK_UNINTERRUPTIBLE , wait_timeout);if (test_bit (QCA_IBS_DISABLED , &qca->flags)) {bt_dev_err (hu->hdev,"SSR or FW download time out" );
@@ -2484,7 +2483,7 @@ static int __maybe_unused qca_suspend(stif (tx_pending) {serdev_device_wait_until_sent (hu->serdev, -msecs_to_jiffies (CMD_TRANS_TIMEOUT_MS )); +CMD_TRANS_TIMEOUT );serial_clock_vote (HCI_IBS_TX_VOTE_CLOCK_OFF , hu); }
@@ -2493,7 +2492,7 @@ static int __maybe_unused qca_suspend(st*/ ret =wait_event_interruptible_timeout (qca->suspend_wait_q, qca->rx_ibs_state ==HCI_IBS_RX_ASLEEP , -msecs_to_jiffies (IBS_BTSOC_TX_IDLE_TIMEOUT_MS )); +IBS_BTSOC_TX_IDLE_TIMEOUT );if (ret ==0 ) { ret = -ETIMEDOUT ; goto error;
Greg Kroah-Hartman
maintainerPATCH 341/411 Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit cba6b758711cab946c787f7c15be92cc749b8e1f ]
This make use of hci_cmd_sync_queue for the following MGMT commands:
Add Advertising
Remove Advertising
Add Extended Advertising Parameters
Add Extended Advertising Data
mgmt-tester -s "Add Advertising"
Test Summary
------------
Add Advertising - Failure: LE off Passed Add Advertising - Invalid Params 1 (AD too long) Passed Add Advertising - Invalid Params 2 (Malformed len) Passed Add Advertising - Invalid Params 3 (Malformed len) Passed Add Advertising - Invalid Params 4 (Malformed len) Passed Add Advertising - Invalid Params 5 (AD too long) Passed Add Advertising - Invalid Params 6 (ScRsp too long) Passed Add Advertising - Invalid Params 7 (Malformed len) Passed Add Advertising - Invalid Params 8 (Malformed len) Passed Add Advertising - Invalid Params 9 (Malformed len) Passed
Add Advertising - Invalid Params 10 (ScRsp too long) Passed
Add Advertising - Rejected (Timeout, !Powered) Passed
Add Advertising - Success 1 (Powered, Add Adv Inst) Passed Add Advertising - Success 2 (!Powered, Add Adv Inst) Passed
Add Advertising - Success 3 (!Powered, Adv Enable) Passed Add Advertising - Success 4 (Set Adv on override) Passed Add Advertising - Success 5 (Set Adv off override) Passed Add Advertising - Success 6 (Scan Rsp Dta, Adv ok) Passed Add Advertising - Success 7 (Scan Rsp Dta, Scan ok) Passed Add Advertising - Success 8 (Connectable Flag) Passed Add Advertising - Success 9 (General Discov Flag) Passed Add Advertising - Success 10 (Limited Discov Flag) Passed Add Advertising - Success 11 (Managed Flags) Passed Add Advertising - Success 12 (TX Power Flag) Passed Add Advertising - Success 13 (ADV_SCAN_IND) Passed Add Advertising - Success 14 (ADV_NONCONN_IND) Passed Add Advertising - Success 15 (ADV_IND) Passed Add Advertising - Success 16 (Connectable -> on) Passed Add Advertising - Success 17 (Connectable -> off) Passed Add Advertising - Success 18 (Power -> off, Remove) Passed Add Advertising - Success 19 (Power -> off, Keep) Passed Add Advertising - Success 20 (Add Adv override) Passed Add Advertising - Success 21 (Timeout expires) Passed Add Advertising - Success 22 (LE -> off, Remove) Passed Add Advertising - Success (Empty ScRsp) Passed Add Advertising - Success (ScRsp only) Passed Add Advertising - Invalid Params (ScRsp too long) Passed Add Advertising - Success (ScRsp appear) Passed Add Advertising - Invalid Params (ScRsp appear long) Passed Add Advertising - Success (Appear is null) Passed Add Advertising - Success (Name is null) Passed Add Advertising - Success (Complete name) Passed Add Advertising - Success (Shortened name) Passed Add Advertising - Success (Short name) Passed Add Advertising - Success (Name + data) Passed Add Advertising - Invalid Params (Name + data) Passed Add Advertising - Success (Name+data+appear) Passed
Total: 47, Passed: 47 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 2.17 seconds
mgmt-tester -s "Remove Advertising"
Test Summary
------------
Remove Advertising - Invalid Params 1 Passed Remove Advertising - Success 1 Passed Remove Advertising - Success 2 Passed
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0585 seconds
mgmt-tester -s "Ext Adv MGMT Params"
Test Summary:
------------
Ext Adv MGMT Params - Unpowered Passed Ext Adv MGMT Params - Invalid parameters Passed Ext Adv MGMT Params - Success Passed Ext Adv MGMT Params - (5.0) Success Passed
Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0746 seconds
mgmt-tester -s "Ext Adv MGMT -"
Test Summary
------------
Ext Adv MGMT - Data set without Params Passed Ext Adv MGMT - AD Data (5.0) Invalid parameters Passed Ext Adv MGMT - AD Data (5.0) Success Passed Ext Adv MGMT - AD Scan Response (5.0) Success Passed
Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0805 seconds
Stable-dep-of: d3f7d17960ed ("Bluetooth: MGMT: validate Add Extended Advertising Data length")
--- net/bluetooth/mgmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/mgmt.c +1 -1
@@ -8078,12 +8078,12 @@ static int add_ext_adv_data(struct sock {struct mgmt_cp_add_ext_adv_data *cp = data;struct mgmt_rp_add_ext_adv_data rp; +struct hci_request req;u8 schedule_instance =0 ;struct adv_info *next_instance;struct adv_info *adv_instance;int err =0 ;struct mgmt_pending_cmd *cmd; -struct hci_request req;BT_DBG ("%s" , hdev->name);
Greg Kroah-Hartman
maintainerPATCH 342/411 Bluetooth: MGMT: validate Add Extended Advertising Data length
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit d3f7d17960ed50df3a6709c5158caff989c8c905 ]
MGMT_OP_ADD_EXT_ADV_DATA is registered as a variable-length command, with MGMT_ADD_EXT_ADV_DATA_SIZE as the fixed header size. The handler then uses cp->adv_data_len and cp->scan_rsp_len to validate and copy cp->data, but it never checks that those bytes are part of the mgmt command payload.
A short command can therefore make add_ext_adv_data() pass an out-of-bounds pointer into tlv_data_is_valid(). If the bytes beyond the command buffer are addressable, they can also be copied into the advertising instance as scan response data, where the caller can read them back via MGMT_OP_GET_ADV_INSTANCE. The trigger requires CAP_NET_ADMIN in the initial user namespace; KASAN reports an 8-byte slab-out-of-bounds read.
Reject commands whose length does not match the fixed header plus both advertising data lengths before parsing cp->data.
--- net/bluetooth/mgmt.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bluetooth/mgmt.c +6 -0
@@ -8084,9 +8084,15 @@ static int add_ext_adv_data(struct sockstruct adv_info *adv_instance;int err =0 ;struct mgmt_pending_cmd *cmd; +u16 expected_len;BT_DBG ("%s" , hdev->name); + expected_len =struct_size (cp, data, cp->adv_data_len + cp->scan_rsp_len); +if (expected_len != data_len) +return mgmt_cmd_status (sk, hdev->id,MGMT_OP_ADD_EXT_ADV_DATA , +MGMT_STATUS_INVALID_PARAMS ); +hci_dev_lock (hdev); adv_instance =hci_find_adv_instance (hdev, cp->instance);
Greg Kroah-Hartman
maintainerPATCH 343/411 qed: Use the bitmap API to simplify some functions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit 5e6c7ccd3ea4b25dd6b4b0363859913f315deacb ]
'cid_map' is a bitmap. So use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid some open-coded arithmetic in allocator arguments.
Also change the corresponding 'kfree()' into 'bitmap_free()' to keep consistency.
Also change some 'memset()' into 'bitmap_zero()' to keep consistency. This is also much less verbose.
Stable-dep-of: 2bccfb8476ca ("qed: fix double free in qed_cxt_tables_alloc()")
--- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_cxt.c +5 -19
@@ -1037,12 +1037,12 @@ static void qed_cid_map_free(struct qed_u32 type, vf;for (type =0 ; type <MAX_CONN_TYPES ; type++) { -kfree (p_mngr->acquired[type].cid_map); +bitmap_free (p_mngr->acquired[type].cid_map); p_mngr->acquired[type].max_count =0 ; p_mngr->acquired[type].start_cid =0 ;for (vf =0 ; vf <MAX_NUM_VFS ; vf++) { -kfree (p_mngr->acquired_vf[type][vf].cid_map); +bitmap_free (p_mngr->acquired_vf[type][vf].cid_map); p_mngr->acquired_vf[type][vf].max_count =0 ; p_mngr->acquired_vf[type][vf].start_cid =0 ; }
@@ -1055,15 +1055,10 @@ qed_cid_map_alloc_single(struct qed_hwfnu32 cid_start, u32 cid_count, struct qed_cid_acquired_map *p_map) { - u32 size; - if (!cid_count) return 0; - size =DIV_ROUND_UP (cid_count, -sizeof (unsigned long ) *BITS_PER_BYTE ) * -sizeof (unsigned long ); - p_map->cid_map =kzalloc (size,GFP_KERNEL ); + p_map->cid_map = bitmap_zalloc(cid_count, GFP_KERNEL);if (!p_map->cid_map)return -ENOMEM ;
@@ -1217,7 +1212,6 @@ void qed_cxt_mngr_setup(struct qed_hwfnstruct qed_cid_acquired_map *p_map;struct qed_conn_type_cfg *p_cfg;int type; -u32 len;/* Reset acquired cids */ for (type =0 ; type <MAX_CONN_TYPES ; type++) {
@@ -1226,11 +1220,7 @@ void qed_cxt_mngr_setup(struct qed_hwfn p_cfg = &p_mngr->conn_cfg[type];if (p_cfg->cid_count) { p_map = &p_mngr->acquired[type]; - len =DIV_ROUND_UP (p_map->max_count, -sizeof (unsigned long ) * -BITS_PER_BYTE ) * -sizeof (unsigned long ); -memset (p_map->cid_map,0 , len); +bitmap_zero (p_map->cid_map, p_map->max_count); }if (!p_cfg->cids_per_vf)
@@ -1238,11 +1228,7 @@ void qed_cxt_mngr_setup(struct qed_hwfnfor (vf =0 ; vf <MAX_NUM_VFS ; vf++) { p_map = &p_mngr->acquired_vf[type][vf]; - len =DIV_ROUND_UP (p_map->max_count, -sizeof (unsigned long ) * -BITS_PER_BYTE ) * -sizeof (unsigned long ); -memset (p_map->cid_map,0 , len); +bitmap_zero (p_map->cid_map, p_map->max_count); } } }
Greg Kroah-Hartman
maintainerPATCH 344/411 qed: fix double free in qed_cxt_tables_alloc()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawei Feng <[email protected]>
[ Upstream commit 2bccfb8476ca5f3548afbd623dc7a6980d4e77de ]
If one of the later PF or VF CID bitmap allocations fails, qed_cid_map_alloc() jumps to cid_map_fail and frees the previously allocated CID bitmaps before returning an error. qed_cxt_tables_alloc() then calls qed_cxt_mngr_free(), which invokes qed_cid_map_free() again.
Fix this by setting each CID bitmap pointer to NULL after bitmap_free() to avoid double free.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1-rc3.
Runtime reproduction was not attempted because exercising the failing allocation path requires device-specific setup.
--- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/qlogic/qed/qed_cxt.c +2 -0
@@ -1038,11 +1038,13 @@ static void qed_cid_map_free(struct qed_for (type =0 ; type <MAX_CONN_TYPES ; type++) {bitmap_free (p_mngr->acquired[type].cid_map); + p_mngr->acquired[type].cid_map =NULL ; p_mngr->acquired[type].max_count =0 ; p_mngr->acquired[type].start_cid =0 ;for (vf =0 ; vf <MAX_NUM_VFS ; vf++) {bitmap_free (p_mngr->acquired_vf[type][vf].cid_map); + p_mngr->acquired_vf[type][vf].cid_map =NULL ; p_mngr->acquired_vf[type][vf].max_count =0 ; p_mngr->acquired_vf[type][vf].start_cid =0 ; }
Greg Kroah-Hartman
maintainerPATCH 345/411 Bluetooth: Consolidate code around sk_alloc into a helper function
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit 6bfa273e533d7b25eee3d74e28a7fe8e6a8e7a93 ]
This consolidates code around sk_alloc into bt_sock_alloc which does take care of common initialization.
Stable-dep-of: e83f5e24da74 ("Bluetooth: serialize accept_q access")
--- include/net/bluetooth/bluetooth.h | 2 ++ net/bluetooth/af_bluetooth.c | 21 +++++++++++++++++++++ net/bluetooth/bnep/sock.c | 10 +--------- net/bluetooth/hci_sock.c | 10 ++-------- net/bluetooth/l2cap_sock.c | 10 +--------- net/bluetooth/rfcomm/sock.c | 13 +++---------- net/bluetooth/sco.c | 10 +--------- 7 files changed, 31 insertions(+), 45 deletions(-)
include/net/bluetooth/bluetooth.h +2 -0
@@ -315,6 +315,8 @@ void bt_sock_unregister(int proto);void bt_sock_link (struct bt_sock_list *l,struct sock *s);void bt_sock_unlink (struct bt_sock_list *l,struct sock *s);bool bt_sock_linked (struct bt_sock_list *l,struct sock *s); +struct sock *bt_sock_alloc (struct net *net,struct socket *sock, +struct proto *prot,int proto,gfp_t prio,int kern);int bt_sock_recvmsg (struct socket *sock,struct msghdr *msg,size_t len,int flags); int bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
net/bluetooth/af_bluetooth.c +21 -0
@@ -138,6 +138,27 @@ static int bt_sock_create(struct net *nereturn err; } +struct sock *bt_sock_alloc (struct net *net,struct socket *sock, +struct proto *prot,int proto,gfp_t prio,int kern) +{ +struct sock *sk; + + sk =sk_alloc (net,PF_BLUETOOTH , prio, prot, kern); +if (!sk) +return NULL ; + +sock_init_data (sock, sk); +INIT_LIST_HEAD (&bt_sk (sk)->accept_q); + +sock_reset_flag (sk,SOCK_ZAPPED ); + + sk->sk_protocol = proto; + sk->sk_state =BT_OPEN ; + +return sk; +} +EXPORT_SYMBOL (bt_sock_alloc); +void bt_sock_link (struct bt_sock_list *l,struct sock *sk) {write_lock (&l->lock);
net/bluetooth/bnep/sock.c +1 -9
@@ -204,21 +204,13 @@ static int bnep_sock_create(struct net *if (sock->type !=SOCK_RAW )return -ESOCKTNOSUPPORT ; - sk =sk_alloc (net,PF_BLUETOOTH ,GFP_ATOMIC , &bnep_proto, kern); + sk =bt_sock_alloc (net, sock, &bnep_proto, protocol,GFP_ATOMIC , kern);if (!sk)return -ENOMEM ; -sock_init_data (sock, sk); - sock->ops = &bnep_sock_ops; - sock->state =SS_UNCONNECTED ; -sock_reset_flag (sk,SOCK_ZAPPED ); - - sk->sk_protocol = protocol; - sk->sk_state =BT_OPEN ; -bt_sock_link (&bnep_sk_list, sk);return 0 ; }
net/bluetooth/hci_sock.c +2 -8
@@ -2091,18 +2091,12 @@ static int hci_sock_create(struct net *n sock->ops = &hci_sock_ops; - sk =sk_alloc (net,PF_BLUETOOTH ,GFP_ATOMIC , &hci_sk_proto, kern); + sk =bt_sock_alloc (net, sock, &hci_sk_proto, protocol,GFP_ATOMIC , + kern);if (!sk)return -ENOMEM ; -sock_init_data (sock, sk); - -sock_reset_flag (sk,SOCK_ZAPPED ); - - sk->sk_protocol = protocol; - sock->state =SS_UNCONNECTED ; - sk->sk_state =BT_OPEN ; sk->sk_destruct = hci_sock_destruct;bt_sock_link (&hci_sk_list, sk);
net/bluetooth/l2cap_sock.c +1 -9
@@ -1913,21 +1913,13 @@ static struct sock *l2cap_sock_alloc(strstruct sock *sk;struct l2cap_chan *chan; - sk =sk_alloc (net,PF_BLUETOOTH , prio, &l2cap_proto, kern); + sk =bt_sock_alloc (net, sock, &l2cap_proto, proto, prio, kern);if (!sk)return NULL ; -sock_init_data (sock, sk); -INIT_LIST_HEAD (&bt_sk (sk)->accept_q); - sk->sk_destruct = l2cap_sock_destruct; sk->sk_sndtimeo =L2CAP_CONN_TIMEOUT ; -sock_reset_flag (sk,SOCK_ZAPPED ); - - sk->sk_protocol = proto; - sk->sk_state =BT_OPEN ; - chan =l2cap_chan_create ();if (!chan) {sk_free (sk);
net/bluetooth/rfcomm/sock.c +3 -10
@@ -280,18 +280,16 @@ static struct proto rfcomm_proto = { .obj_size = sizeof(struct rfcomm_pinfo) }; -static struct sock *rfcomm_sock_alloc (struct net *net,struct socket *sock,int proto,gfp_t prio,int kern) +static struct sock *rfcomm_sock_alloc (struct net *net,struct socket *sock, +int proto,gfp_t prio,int kern) {struct rfcomm_dlc *d;struct sock *sk; - sk =sk_alloc (net,PF_BLUETOOTH , prio, &rfcomm_proto, kern); + sk =bt_sock_alloc (net, sock, &rfcomm_proto, proto, prio, kern);if (!sk)return NULL ; -sock_init_data (sock, sk); -INIT_LIST_HEAD (&bt_sk (sk)->accept_q); - d =rfcomm_dlc_alloc (prio);if (!d) {sk_free (sk);
@@ -310,11 +308,6 @@ static struct sock *rfcomm_sock_alloc(st sk->sk_sndbuf =RFCOMM_MAX_CREDITS *RFCOMM_DEFAULT_MTU *10 ; sk->sk_rcvbuf =RFCOMM_MAX_CREDITS *RFCOMM_DEFAULT_MTU *10 ; -sock_reset_flag (sk,SOCK_ZAPPED ); - - sk->sk_protocol = proto; - sk->sk_state =BT_OPEN ; -bt_sock_link (&rfcomm_sk_list, sk);BT_DBG ("sk %p" , sk);
net/bluetooth/sco.c +1 -9
@@ -501,21 +501,13 @@ static struct sock *sco_sock_alloc(struc {struct sock *sk; - sk =sk_alloc (net,PF_BLUETOOTH , prio, &sco_proto, kern); + sk =bt_sock_alloc (net, sock, &sco_proto, proto, prio, kern);if (!sk)return NULL ; -sock_init_data (sock, sk); -INIT_LIST_HEAD (&bt_sk (sk)->accept_q); - sk->sk_destruct = sco_sock_destruct; sk->sk_sndtimeo =SCO_CONN_TIMEOUT ; -sock_reset_flag (sk,SOCK_ZAPPED ); - - sk->sk_protocol = proto; - sk->sk_state =BT_OPEN ; -sco_pi (sk)->setting =BT_VOICE_CVSD_16BIT ;bt_sock_link (&sco_sk_list, sk);
Greg Kroah-Hartman
maintainerPATCH 346/411 Bluetooth: Init sk_peer_* on bt_sock_alloc
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit 464c702fb9374ff8f3f816f24fb7ac719dd20e1e ]
This makes sure peer information is always available via sock when using bt_sock_alloc.
Stable-dep-of: e83f5e24da74 ("Bluetooth: serialize accept_q access")
--- net/bluetooth/af_bluetooth.c | 24 ++++++++++++++++++++++++ net/bluetooth/hidp/sock.c | 10 +--------- net/bluetooth/l2cap_sock.c | 19 ------------------- 3 files changed, 25 insertions(+), 28 deletions(-)
net/bluetooth/af_bluetooth.c +24 -0
@@ -155,6 +155,14 @@ struct sock *bt_sock_alloc(struct net *n sk->sk_protocol = proto; sk->sk_state =BT_OPEN ; +/* Init peer information so it can be properly monitored */ +if (!kern) { +spin_lock (&sk->sk_peer_lock); + sk->sk_peer_pid =get_pid (task_tgid (current)); + sk->sk_peer_cred =get_current_cred (); +spin_unlock (&sk->sk_peer_lock); + } +return sk; }EXPORT_SYMBOL (bt_sock_alloc);
@@ -199,6 +207,9 @@ EXPORT_SYMBOL(bt_sock_linked);void bt_accept_enqueue (struct sock *parent,struct sock *sk,bool bh) { +const struct cred *old_cred; +struct pid *old_pid; +BT_DBG ("parent %p, sk %p" , parent, sk);sock_hold (sk);
@@ -211,6 +222,19 @@ void bt_accept_enqueue(struct sock *parelist_add_tail (&bt_sk (sk)->accept_q, &bt_sk (parent)->accept_q);bt_sk (sk)->parent = parent; +/* Copy credentials from parent since for incoming connections the +* socket is allocated by the kernel. +*/ +spin_lock (&sk->sk_peer_lock); + old_pid = sk->sk_peer_pid; + old_cred = sk->sk_peer_cred; + sk->sk_peer_pid =get_pid (parent->sk_peer_pid); + sk->sk_peer_cred =get_cred (parent->sk_peer_cred); +spin_unlock (&sk->sk_peer_lock); + +put_pid (old_pid); +put_cred (old_cred); +if (bh)bh_unlock_sock (sk);else
net/bluetooth/hidp/sock.c +1 -9
@@ -255,21 +255,13 @@ static int hidp_sock_create(struct net *if (sock->type !=SOCK_RAW )return -ESOCKTNOSUPPORT ; - sk =sk_alloc (net,PF_BLUETOOTH ,GFP_ATOMIC , &hidp_proto, kern); + sk =bt_sock_alloc (net, sock, &hidp_proto, protocol,GFP_ATOMIC , kern);if (!sk)return -ENOMEM ; -sock_init_data (sock, sk); - sock->ops = &hidp_sock_ops; - sock->state =SS_UNCONNECTED ; -sock_reset_flag (sk,SOCK_ZAPPED ); - - sk->sk_protocol = protocol; - sk->sk_state =BT_OPEN ; -bt_sock_link (&hidp_sk_list, sk);return 0 ;
net/bluetooth/l2cap_sock.c +0 -19
@@ -177,21 +177,6 @@ done:return err; } -static void l2cap_sock_init_pid (struct sock *sk) -{ -struct l2cap_chan *chan =l2cap_pi (sk)->chan; - -/* Only L2CAP_MODE_EXT_FLOWCTL ever need to access the PID in order to -* group the channels being requested. -*/ -if (chan->mode !=L2CAP_MODE_EXT_FLOWCTL ) -return ; - -spin_lock (&sk->sk_peer_lock); - sk->sk_peer_pid =get_pid (task_tgid (current)); -spin_unlock (&sk->sk_peer_lock); -} -static int l2cap_sock_connect (struct socket *sock,struct sockaddr *addr,int alen,int flags) {
@@ -267,8 +252,6 @@ static int l2cap_sock_connect(struct soc chan->mode != L2CAP_MODE_EXT_FLOWCTL) chan->mode =L2CAP_MODE_LE_FLOWCTL ; -l2cap_sock_init_pid (sk); - err =l2cap_chan_connect (chan, la.l2_psm,__le16_to_cpu (la.l2_cid), &la.l2_bdaddr, la.l2_bdaddr_type);if (err)
@@ -324,8 +307,6 @@ static int l2cap_sock_listen(struct sock goto done; } -l2cap_sock_init_pid (sk); - sk->sk_max_ack_backlog = backlog; sk->sk_ack_backlog =0 ;
Greg Kroah-Hartman
maintainerPATCH 347/411 Bluetooth: serialize accept_q access
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiexun Wang <[email protected]>
[ Upstream commit e83f5e24da741fa9405aeeff00b08c5ee7c37b88 ]
bt_sock_poll() walks the accept queue without synchronization, while child teardown can unlink the same socket and drop its last reference. The unsynchronized accept queue walk has existed since the initial Bluetooth import.
Protect accept_q with a dedicated lock for queue updates and polling. Also rework bt_accept_dequeue() to take temporary child references under the queue lock before dropping it and locking the child socket.
--- include/net/bluetooth/bluetooth.h | 1 net/bluetooth/af_bluetooth.c | 87 ++++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 22 deletions(-)
include/net/bluetooth/bluetooth.h +1 -0
@@ -291,6 +291,7 @@ void baswap(bdaddr_t *dst, const bdaddr_struct bt_sock {struct sock sk;struct list_head accept_q; +spinlock_t accept_q_lock;/* protects accept_q */ struct sock *parent;unsigned long flags;void (*skb_msg_name)(struct sk_buff *,void *,int *);
net/bluetooth/af_bluetooth.c +65 -22
163 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 348/411 net: hsr: defer node table free until after RCU readers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit aaec7096f9961eb223b5b149abe9495525c205d9 ]
HSR node-list and node-status generic-netlink operations run under rcu_read_lock(). They walk hsr->node_db through hsr_get_next_node() and hsr_get_node_data(), but RTM_DELLINK teardown removes the same node table with plain list_del() and frees each node immediately.
That lets a generic-netlink reader hold a struct hsr_node pointer across hsr_dellink(). In a KASAN build, widening the reader window after hsr_get_next_node() obtains the node reproduces a slab-use-after-free when the reader copies node->macaddress_A; the freeing stack is hsr_del_nodes() from hsr_dellink().
Use list_del_rcu() and defer the free through the existing hsr_free_node_rcu() callback. This matches the lifetime rule used by the HSR prune paths, which already delete nodes with list_del_rcu() and call_rcu().
--- net/hsr/hsr_framereg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/hsr/hsr_framereg.c +4 -2
@@ -123,8 +123,10 @@ void hsr_del_nodes(struct list_head *nodstruct hsr_node *node;struct hsr_node *tmp; -list_for_each_entry_safe (node, tmp, node_db, mac_list) -kfree (node); +list_for_each_entry_safe (node, tmp, node_db, mac_list) { +list_del_rcu (&node->mac_list); +kfree_rcu (node, rcu_head); + } } void prp_handle_san_frame(bool san, enum hsr_port_type port,
Greg Kroah-Hartman
maintainerPATCH 349/411 ice: fix VF queue configuration with low MTU values
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jose Ignacio Tornos Martinez <[email protected]>
[ Upstream commit 3ba4dd024d26372733d1c02e13e076c6016e3320 ]
The ice driver's VF queue configuration validation rejects databuffer_size values below 1024 bytes, which prevents VFs from using MTU values below 871 bytes.
The iavf driver calculates databuffer_size based on the MTU using:
databuffer_size = ALIGN(MTU + LIBETH_RX_LL_LEN, 128)
where LIBETH_RX_LL_LEN = 26 (ETH_HLEN + 2*VLAN_HLEN + ETH_FCS_LEN).
For MTU values below 871:
MTU 870: 870 + 26 = 896, aligned to 128 = 896 (< 1024, rejected) MTU 871: 871 + 26 = 897, aligned to 128 = 1024 (>= 1024, accepted)
The 1024-byte minimum seems unnecessarily restrictive, because the hardware supports databuffer_size as low as 128 bytes (the alignment boundary), which should allow MTU values down to the standard minimum of 68 bytes.
I haven't found the reason why the limit was configured in the commit 9c7dd7566d18 ("ice: add validation in OP_CONFIG_VSI_QUEUES VF message"), so with no more information and since it is working, change the minimum databuffer_size validation from 1024 to 128 bytes to allow standard low MTU values while still preventing invalid configurations.
--- drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c +1 -1
@@ -3585,7 +3585,7 @@ static int ice_vc_cfg_qs_msg(struct ice_if (qpi->rxq.databuffer_size !=0 && (qpi->rxq.databuffer_size > ((16 *1024 ) -128 ) || - qpi->rxq.databuffer_size <1024 )) { + qpi->rxq.databuffer_size <128 )) { v_ret =VIRTCHNL_STATUS_ERR_PARAM ; goto error_param; }
Greg Kroah-Hartman
maintainerPATCH 350/411 ipv6/addrconf: annotate data-races around devconf fields (II)
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 2f0ff05a44302c91af54a5f9efe1b65b7681540e ]
Final (?) round of this series.
Annotate lockless reads on following devconf fields, because they be changed concurrently from /proc/net/ipv6/conf.
- accept_dad
- optimistic_dad
- use_optimistic
- use_oif_addrs_only
- ra_honor_pio_life
- keep_addr_on_down
- ndisc_notify
- ndisc_evict_nocarrier
- suppress_frag_ndisc
- addr_gen_mode
- seg6_enabled
- ioam6_enabled
- ioam6_id
- ioam6_id_wide
- drop_unicast_in_l2_multicast
- mldv[12]_unsolicited_report_interval
- force_mld_version
- force_tllao
- accept_untracked_na
- drop_unsolicited_na
- accept_source_route
Stable-dep-of: d4ea0dfd7501 ("ipv6: ioam: add NULL check for idev in ipv6_hop_ioam()")
--- net/ipv6/addrconf.c | 47 +++++++++++++++++++++++++---------------------- net/ipv6/exthdrs.c | 16 +++++++++------- net/ipv6/ioam6.c | 8 ++++---- net/ipv6/ip6_input.c | 2 +- net/ipv6/mcast.c | 14 +++++++------- net/ipv6/ndisc.c | 12 ++++++------ net/ipv6/seg6_hmac.c | 8 +++++--- 7 files changed, 57 insertions(+), 50 deletions(-)
net/ipv6/addrconf.c +25 -22
@@ -1502,15 +1502,17 @@ static inline int ipv6_saddr_preferred(ireturn 0 ; } -static bool ipv6_use_optimistic_addr (struct net *net, -struct inet6_dev *idev) +static bool ipv6_use_optimistic_addr (const struct net *net, +const struct inet6_dev *idev) {#ifdef CONFIG_IPV6_OPTIMISTIC_DAD if (!idev)return false; -if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad) +if (!READ_ONCE (net->ipv6.devconf_all->optimistic_dad) && + !READ_ONCE (idev->cnf.optimistic_dad))return false; -if (!net->ipv6.devconf_all->use_optimistic && !idev->cnf.use_optimistic) +if (!READ_ONCE (net->ipv6.devconf_all->use_optimistic) && + !READ_ONCE (idev->cnf.use_optimistic))return false;return true;
@@ -1519,13 +1521,14 @@ static bool ipv6_use_optimistic_addr(str#endif } -static bool ipv6_allow_optimistic_dad (struct net *net, -struct inet6_dev *idev) +static bool ipv6_allow_optimistic_dad (const struct net *net, +const struct inet6_dev *idev) {#ifdef CONFIG_IPV6_OPTIMISTIC_DAD if (!idev)return false; -if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad) +if (!READ_ONCE (net->ipv6.devconf_all->optimistic_dad) && + !READ_ONCE (idev->cnf.optimistic_dad))return false;return true;
@@ -1807,7 +1810,7 @@ int ipv6_dev_get_saddr(struct net *net, idev =__in6_dev_get (dst_dev);if ((dst_type &IPV6_ADDR_MULTICAST ) || dst.scope <=IPV6_ADDR_SCOPE_LINKLOCAL || - (idev && idev->cnf.use_oif_addrs_only)) { + (idev &&READ_ONCE (idev->cnf.use_oif_addrs_only))) { use_oif_addr = true; } }
@@ -2631,8 +2634,8 @@ int addrconf_prefix_rcv_add_addr(struct };#ifdef CONFIG_IPV6_OPTIMISTIC_DAD -if ((net->ipv6.devconf_all->optimistic_dad || - in6_dev->cnf.optimistic_dad) && +if ((READ_ONCE (net->ipv6.devconf_all->optimistic_dad) || +READ_ONCE (in6_dev->cnf.optimistic_dad)) && !net->ipv6.devconf_all->forwarding && sllao) cfg.ifa_flags |=IFA_F_OPTIMISTIC ;#endif
@@ -3229,8 +3232,8 @@ void addrconf_add_linklocal(struct inet6struct inet6_ifaddr *ifp;#ifdef CONFIG_IPV6_OPTIMISTIC_DAD -if ((dev_net (idev->dev)->ipv6.devconf_all->optimistic_dad || - idev->cnf.optimistic_dad) && +if ((READ_ONCE (dev_net (idev->dev)->ipv6.devconf_all->optimistic_dad) || +READ_ONCE (idev->cnf.optimistic_dad)) && !dev_net (idev->dev)->ipv6.devconf_all->forwarding) cfg.ifa_flags |=IFA_F_OPTIMISTIC ;#endif
@@ -3798,10 +3801,10 @@ static int addrconf_ifdown(struct net_de*/ if (!unregister && !idev->cnf.disable_ipv6) {/* aggregate the system setting and interface setting */ -int _keep_addr = net->ipv6.devconf_all->keep_addr_on_down; +int _keep_addr =READ_ONCE (net->ipv6.devconf_all->keep_addr_on_down);if (!_keep_addr) - _keep_addr = idev->cnf.keep_addr_on_down; + _keep_addr =READ_ONCE (idev->cnf.keep_addr_on_down); keep_addr = (_keep_addr >0 ); }
@@ -4024,8 +4027,8 @@ static void addrconf_dad_begin(struct in net =dev_net (dev);if (dev->flags&(IFF_NOARP |IFF_LOOPBACK ) || - (net->ipv6.devconf_all->accept_dad <1 && - idev->cnf.accept_dad <1 ) || + (READ_ONCE (net->ipv6.devconf_all->accept_dad) <1 && +READ_ONCE (idev->cnf.accept_dad) <1 ) || !(ifp->flags&IFA_F_TENTATIVE ) || ifp->flags &IFA_F_NODAD ) {bool send_na = false;
@@ -4117,8 +4120,8 @@ static void addrconf_dad_work(struct wor action =DAD_ABORT ; ifp->state =INET6_IFADDR_STATE_POSTDAD ; -if ((dev_net (idev->dev)->ipv6.devconf_all->accept_dad >1 || - idev->cnf.accept_dad >1 ) && +if ((READ_ONCE (dev_net (idev->dev)->ipv6.devconf_all->accept_dad) >1 || +READ_ONCE (idev->cnf.accept_dad) >1 ) && !idev->cnf.disable_ipv6 && !(ifp->flags &IFA_F_STABLE_PRIVACY )) {struct in6_addr addr;
@@ -4256,8 +4259,8 @@ static void addrconf_dad_completed(struc/* send unsolicited NA if enabled */ if (send_na && - (ifp->idev->cnf.ndisc_notify || -dev_net (dev)->ipv6.devconf_all->ndisc_notify)) { + (READ_ONCE (ifp->idev->cnf.ndisc_notify) || +READ_ONCE (dev_net (dev)->ipv6.devconf_all->ndisc_notify))) { ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifp->addr, /*router=*/ !!ifp->idev->cnf.forwarding, /*solicited=*/ false, /*override=*/ true,
@@ -6431,7 +6434,7 @@ static int addrconf_sysctl_addr_gen_mode }else if (&net->ipv6.devconf_all->addr_gen_mode == ctl->data) {struct net_device *dev; - net->ipv6.devconf_dflt->addr_gen_mode = new_val; +WRITE_ONCE (net->ipv6.devconf_dflt->addr_gen_mode, new_val);for_each_netdev (net, dev) { idev =__in6_dev_get (dev); if (idev &&
@@ -6442,7 +6445,7 @@ static int addrconf_sysctl_addr_gen_mode } } - *((u32 *)ctl->data) = new_val; +WRITE_ONCE (*((u32 *)ctl->data), new_val); } out:
net/ipv6/exthdrs.c +9 -7
@@ -382,9 +382,8 @@ static int ipv6_srh_rcv(struct sk_buff *return -1 ; } - accept_seg6 = net->ipv6.devconf_all->seg6_enabled; -if (accept_seg6 > idev->cnf.seg6_enabled) - accept_seg6 = idev->cnf.seg6_enabled; + accept_seg6 =min (READ_ONCE (net->ipv6.devconf_all->seg6_enabled), +READ_ONCE (idev->cnf.seg6_enabled));if (!accept_seg6) {kfree_skb (skb);
@@ -689,11 +688,14 @@ static int ipv6_rthdr_rcv(struct sk_buffstruct ipv6_rt_hdr *hdr;struct rt0_hdr *rthdr;struct net *net =dev_net (skb->dev); -int accept_source_route = net->ipv6.devconf_all->accept_source_route; +int accept_source_route; idev =__in6_dev_get (skb->dev); -if (idev && accept_source_route > idev->cnf.accept_source_route) - accept_source_route = idev->cnf.accept_source_route; + accept_source_route =READ_ONCE (net->ipv6.devconf_all->accept_source_route); + +if (idev) + accept_source_route =min (accept_source_route, +READ_ONCE (idev->cnf.accept_source_route));if (!pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || !pskb_may_pull(skb, (skb_transport_offset(skb) +
@@ -957,7 +959,7 @@ static bool ipv6_hop_ioam(struct sk_buff goto drop;/* Ignore if IOAM is not enabled on ingress */ -if (!__in6_dev_get (skb->dev)->cnf.ioam6_enabled) +if (!READ_ONCE (__in6_dev_get (skb->dev)->cnf.ioam6_enabled)) goto ignore;/* Truncated Option header */
net/ipv6/ioam6.c +4 -4
@@ -673,7 +673,7 @@ static void __ioam6_fill_trace_data(struif (!skb->dev) raw16 =IOAM6_U16_UNAVAILABLE ;else - raw16 = (__force u16 )__in6_dev_get (skb->dev)->cnf.ioam6_id; + raw16 = (__force u16 )READ_ONCE (__in6_dev_get (skb->dev)->cnf.ioam6_id); *(__be16 *)data =cpu_to_be16 (raw16); data +=sizeof (__be16);
@@ -681,7 +681,7 @@ static void __ioam6_fill_trace_data(struif (skb_dst (skb)->dev->flags &IFF_LOOPBACK ) raw16 =IOAM6_U16_UNAVAILABLE ;else - raw16 = (__force u16 )__in6_dev_get (skb_dst (skb)->dev)->cnf.ioam6_id; + raw16 = (__force u16 )READ_ONCE (__in6_dev_get (skb_dst (skb)->dev)->cnf.ioam6_id); *(__be16 *)data =cpu_to_be16 (raw16); data +=sizeof (__be16);
@@ -758,7 +758,7 @@ static void __ioam6_fill_trace_data(struif (!skb->dev) raw32 =IOAM6_U32_UNAVAILABLE ;else - raw32 =__in6_dev_get (skb->dev)->cnf.ioam6_id_wide; + raw32 =READ_ONCE (__in6_dev_get (skb->dev)->cnf.ioam6_id_wide); *(__be32 *)data =cpu_to_be32 (raw32); data +=sizeof (__be32);
@@ -766,7 +766,7 @@ static void __ioam6_fill_trace_data(struif (skb_dst (skb)->dev->flags &IFF_LOOPBACK ) raw32 =IOAM6_U32_UNAVAILABLE ;else - raw32 =__in6_dev_get (skb_dst (skb)->dev)->cnf.ioam6_id_wide; + raw32 =READ_ONCE (__in6_dev_get (skb_dst (skb)->dev)->cnf.ioam6_id_wide); *(__be32 *)data =cpu_to_be32 (raw32); data +=sizeof (__be32);
net/ipv6/ip6_input.c +1 -1
@@ -228,7 +228,7 @@ static struct sk_buff *ip6_rcv_core(struif (!ipv6_addr_is_multicast (&hdr->daddr) && (skb->pkt_type ==PACKET_BROADCAST || skb->pkt_type ==PACKET_MULTICAST ) && - idev->cnf.drop_unicast_in_l2_multicast) +READ_ONCE (idev->cnf.drop_unicast_in_l2_multicast)) goto err;/* RFC4291 2.7
net/ipv6/mcast.c +7 -7
@@ -159,9 +159,9 @@ static int unsolicited_report_interval(sint iv;if (mld_in_v1_mode (idev)) - iv = idev->cnf.mldv1_unsolicited_report_interval; + iv =READ_ONCE (idev->cnf.mldv1_unsolicited_report_interval);else - iv = idev->cnf.mldv2_unsolicited_report_interval; + iv =READ_ONCE (idev->cnf.mldv2_unsolicited_report_interval);return iv >0 ? iv :1 ; }
@@ -1201,15 +1201,15 @@ static bool mld_marksources(struct ifmcastatic int mld_force_mld_version (const struct inet6_dev *idev) { +const struct net *net =dev_net (idev->dev); +int all_force; + + all_force =READ_ONCE (net->ipv6.devconf_all->force_mld_version);/* Normally, both are 0 here. If enforcement to a particular is * being used, individual device enforcement will have a lower * precedence over 'all' device (.../conf/all/force_mld_version). */ - -if (dev_net (idev->dev)->ipv6.devconf_all->force_mld_version !=0 ) -return dev_net (idev->dev)->ipv6.devconf_all->force_mld_version; -else -return idev->cnf.force_mld_version; +return all_force ?:READ_ONCE (idev->cnf.force_mld_version); }static bool mld_in_v2_mode_only (const struct inet6_dev *idev)
net/ipv6/ndisc.c +6 -6
@@ -450,7 +450,7 @@ static void ip6_nd_hdr(struct sk_buff *srcu_read_lock (); idev =__in6_dev_get (skb->dev); - tclass = idev ? idev->cnf.ndisc_tclass :0 ; + tclass = idev ?READ_ONCE (idev->cnf.ndisc_tclass) :0 ;rcu_read_unlock ();skb_push (skb,sizeof (*hdr));
@@ -538,7 +538,7 @@ void ndisc_send_na(struct net_device *de src_addr = solicited_addr;if (ifp->flags &IFA_F_OPTIMISTIC ) override = false; - inc_opt |= ifp->idev->cnf.force_tllao; + inc_opt |=READ_ONCE (ifp->idev->cnf.force_tllao);in6_ifa_put (ifp); }else { if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
@@ -991,7 +991,7 @@ static void ndisc_recv_na(struct sk_buff* and thus should not be accepted. */ if (!msg->icmph.icmp6_solicited && idev && - idev->cnf.drop_unsolicited_na) +READ_ONCE (idev->cnf.drop_unsolicited_na))return ;if (!ndisc_parse_options (dev, msg->opt, ndoptlen, &ndopts)) {
@@ -1749,7 +1749,7 @@ static bool ndisc_suppress_frag_ndisc(stif (!idev)return true;if (IP6CB (skb)->flags &IP6SKB_FRAGMENTED && - idev->cnf.suppress_frag_ndisc) { +READ_ONCE (idev->cnf.suppress_frag_ndisc)) {net_warn_ratelimited ("Received fragmented ndisc packet. Carefully consider disabling suppress_frag_ndisc.\n" );return true; }
@@ -1824,8 +1824,8 @@ static int ndisc_netdev_event(struct not idev =in6_dev_get (dev);if (!idev)break ; -if (idev->cnf.ndisc_notify || - net->ipv6.devconf_all->ndisc_notify) +if (READ_ONCE (idev->cnf.ndisc_notify) || +READ_ONCE (net->ipv6.devconf_all->ndisc_notify))ndisc_send_unsol_na (dev);in6_dev_put (idev);break ;
net/ipv6/seg6_hmac.c +5 -3
@@ -242,6 +242,7 @@ bool seg6_hmac_validate_skb(struct sk_bustruct sr6_tlv_hmac *tlv;struct ipv6_sr_hdr *srh;struct inet6_dev *idev; +int require_hmac; idev =__in6_dev_get (skb->dev);if (!idev)
@@ -251,16 +252,17 @@ bool seg6_hmac_validate_skb(struct sk_bu tlv =seg6_get_tlv_hmac (srh); + require_hmac =READ_ONCE (idev->cnf.seg6_require_hmac);/* mandatory check but no tlv */ -if (idev->cnf.seg6_require_hmac >0 && !tlv) +if (require_hmac >0 && !tlv)return false;/* no check */ -if (idev->cnf.seg6_require_hmac <0 ) +if (require_hmac <0 )return true;/* check only if present */ -if (idev->cnf.seg6_require_hmac ==0 && !tlv) +if (require_hmac ==0 && !tlv)return true;/* now, seg6_require_hmac >= 0 && tlv */
Greg Kroah-Hartman
maintainerPATCH 351/411 ipv6: ioam: add NULL check for idev in ipv6_hop_ioam()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Iurman <[email protected]>
[ Upstream commit d4ea0dfd75011b78cebf3808f98ac4c4f51a6fb9 ]
Reported by Sashiko:
The function ipv6_hop_ioam() accesses __in6_dev_get(skb->dev)->cnf.ioam6_enabled without validating the returned idev pointer. Because addrconf_ifdown() can concurrently clear dev->ip6_ptr via RCU, __in6_dev_get() can return NULL during interface teardown, which could cause a NULL pointer dereference when processing an IOAM Hop-by-Hop option.
Let's add a check and use SKB_DROP_REASON_IPV6DISABLED accordingly.
--- net/ipv6/exthdrs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/ipv6/exthdrs.c +7 -1
@@ -952,14 +952,20 @@ static bool ipv6_hop_ioam(struct sk_buff {struct ioam6_trace_hdr *trace;struct ioam6_namespace *ns; +struct inet6_dev *idev;struct ioam6_hdr *hdr;/* Bad alignment (must be 4n-aligned) */ if (optoff &3 ) goto drop; +/* Does the device still have IPv6 configuration? */ + idev =__in6_dev_get (skb->dev); +if (!idev) + goto drop; +/* Ignore if IOAM is not enabled on ingress */ -if (!READ_ONCE (__in6_dev_get (skb->dev)->cnf.ioam6_enabled)) +if (!READ_ONCE (idev->cnf.ioam6_enabled)) goto ignore;/* Truncated Option header */
Greg Kroah-Hartman
maintainerPATCH 352/411 use less confusing names for iov_iter direction initializers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit de4eda9de2d957ef2d6a8365a01e26a435e958cb ]
READ/WRITE proved to be actively confusing - the meanings are "data destination, as used with read(2)" and "data source, as used with write(2)", but people keep interpreting those as "we read data from it" and "we write data to it", i.e. exactly the wrong way.
Call them ITER_DEST and ITER_SOURCE - at least that is harder to misinterpret...
Stable-dep-of: a4f0b001782b ("vsock/virtio: reset connection on receiving queue overflow")
--- arch/x86/kernel/cpu/microcode/intel.c | 4 ++-- crypto/testmgr.c | 4 ++-- drivers/block/drbd/drbd_main.c | 2 +- drivers/block/drbd/drbd_receiver.c | 2 +- drivers/block/loop.c | 14 +++++++------- drivers/block/nbd.c | 10 +++++----- drivers/char/random.c | 4 ++-- drivers/fsi/fsi-sbefifo.c | 6 +++--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 2 +- drivers/isdn/mISDN/l1oip_core.c | 2 +- drivers/misc/vmw_vmci/vmci_queue_pair.c | 6 +++--- drivers/net/ppp/ppp_generic.c | 2 +- drivers/nvme/host/tcp.c | 4 ++-- drivers/nvme/target/io-cmd-file.c | 4 ++-- drivers/nvme/target/tcp.c | 2 +- drivers/scsi/sg.c | 2 +- drivers/target/iscsi/iscsi_target_util.c | 4 ++-- drivers/target/target_core_file.c | 2 +- drivers/usb/usbip/usbip_common.c | 2 +- drivers/vhost/net.c | 6 +++--- drivers/vhost/scsi.c | 10 +++++----- drivers/vhost/vhost.c | 6 +++--- drivers/vhost/vringh.c | 4 ++-- drivers/vhost/vsock.c | 4 ++-- drivers/xen/pvcalls-back.c | 8 ++++---- fs/9p/vfs_addr.c | 4 ++-- fs/9p/vfs_dir.c | 2 +- fs/9p/xattr.c | 4 ++-- fs/afs/cmservice.c | 2 +- fs/afs/dir.c | 2 +- fs/afs/file.c | 4 ++-- fs/afs/internal.h | 4 ++-- fs/afs/rxrpc.c | 10 +++++----- fs/afs/write.c | 4 ++-- fs/aio.c | 4 ++-- fs/ceph/addr.c | 2 +- fs/ceph/file.c | 4 ++-- fs/cifs/connect.c | 6 +++--- fs/cifs/file.c | 4 ++-- fs/cifs/smb2ops.c | 4 ++-- fs/cifs/transport.c | 6 +++--- fs/fuse/ioctl.c | 4 ++-- fs/nfsd/vfs.c | 4 ++-- fs/ocfs2/cluster/tcp.c | 2 +- fs/orangefs/inode.c | 8 ++++---- fs/read_write.c | 12 ++++++------ fs/seq_file.c | 2 +- fs/splice.c | 10 +++++----- include/linux/uio.h | 3 +++ mm/madvise.c | 2 +- mm/page_io.c | 2 +- mm/process_vm_access.c | 2 +- net/9p/client.c | 2 +- net/bluetooth/6lowpan.c | 2 +- net/bluetooth/a2mp.c | 2 +- net/bluetooth/smp.c | 2 +- net/ceph/messenger_v1.c | 4 ++-- net/ceph/messenger_v2.c | 14 +++++++------- net/compat.c | 2 +- net/ipv4/tcp.c | 4 ++-- net/netfilter/ipvs/ip_vs_sync.c | 2 +- net/smc/smc_clc.c | 6 +++--- net/socket.c | 12 ++++++------ net/sunrpc/socklib.c | 6 +++--- net/sunrpc/svcsock.c | 4 ++-- net/sunrpc/xprtsock.c | 6 +++--- net/tipc/topsrv.c | 2 +- net/tls/tls_device.c | 4 ++-- net/xfrm/espintcp.c | 2 +- security/keys/keyctl.c | 4 ++-- 70 files changed, 158 insertions(+), 155 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +2 -2
@@ -940,7 +940,7 @@ static enum ucode_state request_microcod kvec.iov_base = (void *)firmware->data; kvec.iov_len = firmware->size; -iov_iter_kvec (&iter,WRITE , &kvec,1 , firmware->size); +iov_iter_kvec (&iter,ITER_SOURCE , &kvec,1 , firmware->size); ret =generic_load_microcode (cpu, &iter);release_firmware (firmware);
@@ -959,7 +959,7 @@ request_microcode_user(int cpu, const vo iov.iov_base = (void __user *)buf; iov.iov_len = size; -iov_iter_init (&iter,WRITE , &iov,1 , size); +iov_iter_init (&iter,ITER_SOURCE , &iov,1 , size);return generic_load_microcode (cpu, &iter); }
crypto/testmgr.c +2 -2
@@ -750,7 +750,7 @@ static int build_cipher_test_sglists(strstruct iov_iter input;int err; -iov_iter_kvec (&input,WRITE , inputs, nr_inputs, src_total_len); +iov_iter_kvec (&input,ITER_SOURCE , inputs, nr_inputs, src_total_len); err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask, cfg->inplace ? max(dst_total_len, src_total_len) :
@@ -1133,7 +1133,7 @@ static int build_hash_sglist(struct test kv.iov_base = (void *)vec->plaintext; kv.iov_len = vec->psize; -iov_iter_kvec (&input,WRITE , &kv,1 , vec->psize); +iov_iter_kvec (&input,ITER_SOURCE , &kv,1 , vec->psize);return build_test_sglist (tsgl, cfg->src_divs, alignmask, vec->psize, &input, divs); }
drivers/block/drbd/drbd_main.c +1 -1
@@ -1843,7 +1843,7 @@ int drbd_send(struct drbd_connection *co/* THINK if (signal_pending) return ... ? */ -iov_iter_kvec (&msg.msg_iter,WRITE , &iov,1 , size); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , &iov,1 , size);if (sock == connection->data.socket) {rcu_read_lock ();
drivers/block/drbd/drbd_receiver.c +1 -1
@@ -507,7 +507,7 @@ static int drbd_recv_short(struct socketstruct msghdr msg = { .msg_flags = (flags ? flags :MSG_WAITALL |MSG_NOSIGNAL ) }; -iov_iter_kvec (&msg.msg_iter,READ , &iov,1 , size); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , size);return sock_recvmsg (sock, &msg, msg.msg_flags); }
drivers/block/loop.c +7 -7
@@ -310,7 +310,7 @@ static int lo_write_bvec(struct file *fistruct iov_iter i;ssize_t bw; -iov_iter_bvec (&i,WRITE , bvec,1 , bvec->bv_len); +iov_iter_bvec (&i,ITER_SOURCE , bvec,1 , bvec->bv_len);file_start_write (file); bw =vfs_iter_write (file, &i, ppos,0 );
@@ -388,7 +388,7 @@ static int lo_read_simple(struct loop_dessize_t len;rq_for_each_segment (bvec, rq, iter) { -iov_iter_bvec (&i,READ , &bvec,1 , bvec.bv_len); +iov_iter_bvec (&i,ITER_DEST , &bvec,1 , bvec.bv_len); len =vfs_iter_read (lo->lo_backing_file, &i, &pos,0 );if (len <0 )return len;
@@ -429,7 +429,7 @@ static int lo_read_transfer(struct loop_ b.bv_offset =0 ; b.bv_len = bvec.bv_len; -iov_iter_bvec (&i,READ , &b,1 , b.bv_len); +iov_iter_bvec (&i,ITER_DEST , &b,1 , b.bv_len); len =vfs_iter_read (lo->lo_backing_file, &i, &pos,0 );if (len <0 ) { ret = len;
@@ -551,7 +551,7 @@ static void lo_rw_aio_complete(struct ki }static int lo_rw_aio (struct loop_device *lo,struct loop_cmd *cmd, -loff_t pos,bool rw) +loff_t pos,int rw) {struct iov_iter iter;struct req_iterator rq_iter;
@@ -607,7 +607,7 @@ static int lo_rw_aio(struct loop_device cmd->iocb.ki_flags =IOCB_DIRECT ; cmd->iocb.ki_ioprio =req_get_ioprio (rq); -if (rw ==WRITE ) +if (rw ==ITER_SOURCE ) ret =call_write_iter (file, &cmd->iocb, &iter);else ret =call_read_iter (file, &cmd->iocb, &iter);
@@ -651,14 +651,14 @@ static int do_req_filebacked(struct loopif (lo->transfer)return lo_write_transfer (lo, rq, pos);else if (cmd->use_aio) -return lo_rw_aio (lo, cmd, pos,WRITE ); +return lo_rw_aio (lo, cmd, pos,ITER_SOURCE );else return lo_write_simple (lo, rq, pos);case REQ_OP_READ :if (lo->transfer)return lo_read_transfer (lo, rq, pos);else if (cmd->use_aio) -return lo_rw_aio (lo, cmd, pos,READ ); +return lo_rw_aio (lo, cmd, pos,ITER_DEST );else return lo_read_simple (lo, rq, pos);default :
drivers/block/nbd.c +5 -5
@@ -562,7 +562,7 @@ static int nbd_send_cmd(struct nbd_devicu32 nbd_cmd_flags =0 ;int sent = nsock->sent, skip =0 ; -iov_iter_kvec (&from,WRITE , &iov,1 ,sizeof (request)); +iov_iter_kvec (&from,ITER_SOURCE , &iov,1 ,sizeof (request)); type =req_to_nbd_cmd_type (req);if (type ==U32_MAX )
@@ -648,7 +648,7 @@ send_pages:dev_dbg (nbd_to_dev (nbd),"request %p: sending %d bytes data\n" , req, bvec.bv_len); -iov_iter_bvec (&from,WRITE , &bvec,1 , bvec.bv_len); +iov_iter_bvec (&from,ITER_SOURCE , &bvec,1 , bvec.bv_len);if (skip) {if (skip >=iov_iter_count (&from)) { skip -=iov_iter_count (&from);
@@ -700,7 +700,7 @@ static int nbd_read_reply(struct nbd_devint result; reply->magic =0 ; -iov_iter_kvec (&to,READ , &iov,1 ,sizeof (*reply)); +iov_iter_kvec (&to,ITER_DEST , &iov,1 ,sizeof (*reply)); result =sock_xmit (nbd, index,0 , &to,MSG_WAITALL ,NULL );if (result <0 ) {if (!nbd_disconnected (nbd->config))
@@ -777,7 +777,7 @@ static struct nbd_cmd *nbd_handle_reply(struct iov_iter to;rq_for_each_segment (bvec, req, iter) { -iov_iter_bvec (&to,READ , &bvec,1 , bvec.bv_len); +iov_iter_bvec (&to,ITER_DEST , &bvec,1 , bvec.bv_len); result =sock_xmit (nbd, index,0 , &to,MSG_WAITALL ,NULL );if (result <0 ) { dev_err(disk_to_dev(nbd->disk), "Receive data failed (result %d)\n",
@@ -1228,7 +1228,7 @@ static void send_disconnects(struct nbd_for (i =0 ; i < config->num_connections; i++) {struct nbd_sock *nsock = config->socks[i]; -iov_iter_kvec (&from,WRITE , &iov,1 ,sizeof (request)); +iov_iter_kvec (&from,ITER_SOURCE , &iov,1 ,sizeof (request));mutex_lock (&nsock->tx_lock); ret =sock_xmit (nbd, i,1 , &from,0 ,NULL );if (ret <0 )
drivers/char/random.c +2 -2
@@ -1236,7 +1236,7 @@ SYSCALL_DEFINE3(getrandom, char __user *return ret; } - ret =import_single_range (READ , ubuf, len, &iov, &iter); + ret =import_single_range (ITER_DEST , ubuf, len, &iov, &iter);if (unlikely (ret))return ret;return get_random_bytes_user (&iter);
@@ -1347,7 +1347,7 @@ static long random_ioctl(struct file *f,return -EINVAL ;if (get_user (len, p++))return -EFAULT ; - ret =import_single_range (WRITE , p, len, &iov, &iter); + ret =import_single_range (ITER_SOURCE , p, len, &iov, &iter);if (unlikely (ret))return ret; ret =write_pool_user (&iter);
drivers/fsi/fsi-sbefifo.c +3 -3
@@ -640,7 +640,7 @@ static void sbefifo_collect_async_ffdc(s } ffdc_iov.iov_base = ffdc; ffdc_iov.iov_len =SBEFIFO_MAX_FFDC_SIZE ; -iov_iter_kvec (&ffdc_iter,READ , &ffdc_iov,1 ,SBEFIFO_MAX_FFDC_SIZE ); +iov_iter_kvec (&ffdc_iter,ITER_DEST , &ffdc_iov,1 ,SBEFIFO_MAX_FFDC_SIZE ); cmd[0 ] =cpu_to_be32 (2 ); cmd[1 ] =cpu_to_be32 (SBEFIFO_CMD_GET_SBE_FFDC ); rc =sbefifo_do_command (sbefifo, cmd,2 , &ffdc_iter);
@@ -737,7 +737,7 @@ int sbefifo_submit(struct device *dev, c rbytes = (*resp_len) *sizeof (__be32); resp_iov.iov_base = response; resp_iov.iov_len = rbytes; -iov_iter_kvec (&resp_iter,READ , &resp_iov,1 , rbytes); +iov_iter_kvec (&resp_iter,ITER_DEST , &resp_iov,1 , rbytes);/* Perform the command */ mutex_lock (&sbefifo->lock);
@@ -817,7 +817,7 @@ static ssize_t sbefifo_user_read(struct/* Prepare iov iterator */ resp_iov.iov_base = buf; resp_iov.iov_len = len; -iov_iter_init (&resp_iter,READ , &resp_iov,1 , len); +iov_iter_init (&resp_iter,ITER_DEST , &resp_iov,1 , len);/* Perform the command */ mutex_lock (&sbefifo->lock);
drivers/infiniband/ulp/rtrs/rtrs-clt.c +1 -1
@@ -968,7 +968,7 @@ static void rtrs_clt_init_req(struct rtrrefcount_set (&req->ref,1 ); req->mp_policy = clt_path->clt->mp_policy; -iov_iter_kvec (&iter,WRITE , vec,1 , usr_len); +iov_iter_kvec (&iter,ITER_SOURCE , vec,1 , usr_len); len =_copy_from_iter (req->iu->buf, usr_len, &iter);WARN_ON (len != usr_len);
drivers/isdn/mISDN/l1oip_core.c +1 -1
@@ -706,7 +706,7 @@ l1oip_socket_thread(void *data)printk (KERN_DEBUG "%s: socket created and open\n" , __func__);while (!signal_pending (current)) { -iov_iter_kvec (&msg.msg_iter,READ , &iov,1 , recvbuf_size); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , recvbuf_size); recvlen =sock_recvmsg (socket, &msg,0 );if (recvlen >0 ) {l1oip_socket_parse (hc, &sin_rx, recvbuf, recvlen);
drivers/misc/vmw_vmci/vmci_queue_pair.c +3 -3
@@ -3032,7 +3032,7 @@ ssize_t vmci_qpair_enqueue(struct vmci_qif (!qpair || !buf)return VMCI_ERROR_INVALID_ARGS ; -iov_iter_kvec (&from,WRITE , &v,1 , buf_size); +iov_iter_kvec (&from,ITER_SOURCE , &v,1 , buf_size);qp_lock (qpair);
@@ -3076,7 +3076,7 @@ ssize_t vmci_qpair_dequeue(struct vmci_qif (!qpair || !buf)return VMCI_ERROR_INVALID_ARGS ; -iov_iter_kvec (&to,READ , &v,1 , buf_size); +iov_iter_kvec (&to,ITER_DEST , &v,1 , buf_size);qp_lock (qpair);
@@ -3121,7 +3121,7 @@ ssize_t vmci_qpair_peek(struct vmci_qp *if (!qpair || !buf)return VMCI_ERROR_INVALID_ARGS ; -iov_iter_kvec (&to,READ , &v,1 , buf_size); +iov_iter_kvec (&to,ITER_DEST , &v,1 , buf_size);qp_lock (qpair);
drivers/net/ppp/ppp_generic.c +1 -1
@@ -492,7 +492,7 @@ static ssize_t ppp_read(struct file *fil ret = -EFAULT ; iov.iov_base = buf; iov.iov_len = count; -iov_iter_init (&to,READ , &iov,1 , count); +iov_iter_init (&to,ITER_DEST , &iov,1 , count);if (skb_copy_datagram_iter (skb,0 , &to, skb->len)) goto outf; ret = skb->len;
drivers/nvme/host/tcp.c +2 -2
@@ -297,7 +297,7 @@ static inline void nvme_tcp_advance_req(if (!iov_iter_count (&req->iter) && req->data_sent < req->data_len) { req->curr_bio = req->curr_bio->bi_next; -nvme_tcp_init_iter (req,WRITE ); +nvme_tcp_init_iter (req,ITER_SOURCE ); } }
@@ -775,7 +775,7 @@ static int nvme_tcp_recv_data(struct nvmnvme_tcp_init_recv_ctx (queue);return -EIO ; } -nvme_tcp_init_iter (req,READ ); +nvme_tcp_init_iter (req,ITER_DEST ); }/* we can read only from what is left in this bio */
drivers/nvme/target/io-cmd-file.c +2 -2
@@ -92,10 +92,10 @@ static ssize_t nvmet_file_submit_bvec(stif (req->cmd->rw.control &cpu_to_le16 (NVME_RW_FUA )) ki_flags |=IOCB_DSYNC ; call_iter = req->ns->file->f_op->write_iter; - rw =WRITE ; + rw =ITER_SOURCE ; }else { call_iter = req->ns->file->f_op->read_iter; - rw =READ ; + rw =ITER_DEST ; }iov_iter_bvec (&iter, rw, req->f.bvec, nr_segs, count);
drivers/nvme/target/tcp.c +1 -1
@@ -351,7 +351,7 @@ static void nvmet_tcp_build_pdu_iovec(st sg_offset =0 ; } -iov_iter_bvec (&cmd->recv_msg.msg_iter,READ , cmd->iov, +iov_iter_bvec (&cmd->recv_msg.msg_iter,ITER_DEST , cmd->iov, nr_pages, cmd->pdu_len); }
drivers/scsi/sg.c +1 -1
@@ -1721,7 +1721,7 @@ sg_start_req(Sg_request *srp, unsigned cSg_scatter_hold *rsv_schp = &sfp->reserve;struct request_queue *q = sfp->parentdp->device->request_queue;struct rq_map_data *md, map_data; -int rw = hp->dxfer_direction ==SG_DXFER_TO_DEV ?WRITE :READ ; +int rw = hp->dxfer_direction ==SG_DXFER_TO_DEV ?ITER_SOURCE :ITER_DEST ;unsigned char *long_cmdp =NULL ; SCSI_LOG_TIMEOUT(4, sg_printk(KERN_INFO, sfp->parentdp,
drivers/target/iscsi/iscsi_target_util.c +2 -2
@@ -1231,7 +1231,7 @@ int rx_data(return -1 ;memset (&msg,0 ,sizeof (struct msghdr )); -iov_iter_kvec (&msg.msg_iter,READ , iov, iov_count, data); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , iov, iov_count, data);while (msg_data_left (&msg)) { rx_loop =sock_recvmsg (conn->sock, &msg,MSG_WAITALL );
@@ -1267,7 +1267,7 @@ int tx_data(memset (&msg,0 ,sizeof (struct msghdr )); -iov_iter_kvec (&msg.msg_iter,WRITE , iov, iov_count, data); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , iov, iov_count, data);while (msg_data_left (&msg)) {int tx_loop =sock_sendmsg (conn->sock, &msg);
drivers/target/target_core_file.c +1 -1
@@ -472,7 +472,7 @@ fd_execute_write_same(struct se_cmd *cmd len += se_dev->dev_attrib.block_size; } -iov_iter_bvec (&iter,WRITE , bvec, nolb, len); +iov_iter_bvec (&iter,ITER_SOURCE , bvec, nolb, len); ret =vfs_iter_write (fd_dev->fd_file, &iter, &pos,0 );kfree (bvec);
drivers/usb/usbip/usbip_common.c +1 -1
@@ -309,7 +309,7 @@ int usbip_recv(struct socket *sock, voidif (!sock || !buf || !size)return -EINVAL ; -iov_iter_kvec (&msg.msg_iter,READ , &iov,1 , size); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , size);usbip_dbg_xmit ("enter\n" );
drivers/vhost/net.c +3 -3
@@ -615,7 +615,7 @@ static size_t init_iov_iter(struct vhost/* Skip header. TODO: support TSO. */ size_t len =iov_length (vq->iov, out); -iov_iter_init (iter,WRITE , vq->iov, out, len); +iov_iter_init (iter,ITER_SOURCE , vq->iov, out, len);iov_iter_advance (iter, hdr_size);return iov_iter_count (iter);
@@ -1193,14 +1193,14 @@ static void handle_rx(struct vhost_net * msg.msg_control =vhost_net_buf_consume (&nvq->rxq);/* On overrun, truncate and discard */ if (unlikely (headcount >UIO_MAXIOV )) { -iov_iter_init (&msg.msg_iter,READ , vq->iov,1 ,1 ); +iov_iter_init (&msg.msg_iter,ITER_DEST , vq->iov,1 ,1 ); err = sock->ops->recvmsg (sock, &msg,1 ,MSG_DONTWAIT |MSG_TRUNC );pr_debug ("Discarded rx packet: len %zd\n" , sock_len);continue ; }/* We don't need to be notified again. */ -iov_iter_init (&msg.msg_iter,READ , vq->iov, in, vhost_len); +iov_iter_init (&msg.msg_iter,ITER_DEST , vq->iov, in, vhost_len); fixup = msg.msg_iter;if (unlikely ((vhost_hlen))) {/* We will supply the header ourselves
drivers/vhost/scsi.c +5 -5
@@ -558,7 +558,7 @@ static void vhost_scsi_complete_cmd_workmemcpy (v_rsp.sense, cmd->tvc_sense_buf, se_cmd->scsi_sense_length); -iov_iter_init (&iov_iter,READ , &cmd->tvc_resp_iov, +iov_iter_init (&iov_iter,ITER_DEST , &cmd->tvc_resp_iov, cmd->tvc_in_iovs,sizeof (v_rsp)); ret =copy_to_iter (&v_rsp,sizeof (v_rsp), &iov_iter);if (likely (ret ==sizeof (v_rsp))) {
@@ -863,7 +863,7 @@ vhost_scsi_get_desc(struct vhost_scsi *v* point at the start of the outgoing WRITE payload, if * DMA_TO_DEVICE is set. */ -iov_iter_init (&vc->out_iter,WRITE , vq->iov, vc->out, vc->out_size); +iov_iter_init (&vc->out_iter,ITER_SOURCE , vq->iov, vc->out, vc->out_size); ret =0 ; done:
@@ -1016,7 +1016,7 @@ vhost_scsi_handle_vq(struct vhost_scsi * data_direction =DMA_FROM_DEVICE ; exp_data_len = vc.in_size - vc.rsp_size; -iov_iter_init (&in_iter,READ , &vq->iov[vc.out], vc.in, +iov_iter_init (&in_iter,ITER_DEST , &vq->iov[vc.out], vc.in, vc.rsp_size + exp_data_len);iov_iter_advance (&in_iter, vc.rsp_size); data_iter = in_iter;
@@ -1146,7 +1146,7 @@ vhost_scsi_send_tmf_resp(struct vhost_scmemset (&rsp,0 ,sizeof (rsp)); rsp.response = tmf_resp_code; -iov_iter_init (&iov_iter,READ , resp_iov, in_iovs,sizeof (rsp)); +iov_iter_init (&iov_iter,ITER_DEST , resp_iov, in_iovs,sizeof (rsp)); ret =copy_to_iter (&rsp,sizeof (rsp), &iov_iter);if (likely (ret ==sizeof (rsp)))
@@ -1241,7 +1241,7 @@ vhost_scsi_send_an_resp(struct vhost_scsmemset (&rsp,0 ,sizeof (rsp));/* event_actual = 0 */ rsp.response =VIRTIO_SCSI_S_OK ; -iov_iter_init (&iov_iter,READ , &vq->iov[vc->out], vc->in,sizeof (rsp)); +iov_iter_init (&iov_iter,ITER_DEST , &vq->iov[vc->out], vc->in,sizeof (rsp)); ret =copy_to_iter (&rsp,sizeof (rsp), &iov_iter);if (likely (ret ==sizeof (rsp)))
drivers/vhost/vhost.c +3 -3
@@ -841,7 +841,7 @@ static int vhost_copy_to_user(struct vho VHOST_ACCESS_WO);if (ret <0 ) goto out; -iov_iter_init (&t,WRITE , vq->iotlb_iov, ret, size); +iov_iter_init (&t,ITER_SOURCE , vq->iotlb_iov, ret, size); ret =copy_to_iter (from, size, &t);if (ret == size) ret =0 ;
@@ -880,7 +880,7 @@ static int vhost_copy_from_user(struct v (unsigned long long) size); goto out; } -iov_iter_init (&f,READ , vq->iotlb_iov, ret, size); +iov_iter_init (&f,ITER_DEST , vq->iotlb_iov, ret, size); ret =copy_from_iter (to, size, &f);if (ret == size) ret =0 ;
@@ -2137,7 +2137,7 @@ static int get_indirect(struct vhost_virvq_err (vq,"Translation failure %d in indirect.\n" , ret);return ret; } -iov_iter_init (&from,READ , vq->indirect, ret, len); +iov_iter_init (&from,ITER_DEST , vq->indirect, ret, len); count = len /sizeof desc;/* Buffers are chained via a 16 bit next field, so * we can have at most 2^16 of these. */
drivers/vhost/vringh.c +2 -2
@@ -1160,7 +1160,7 @@ static inline int copy_from_iotlb(constif (ret <0 )return ret; -iov_iter_bvec (&iter,READ , iov, ret, len); +iov_iter_bvec (&iter,ITER_DEST , iov, ret, len); ret =copy_from_iter (dst, len, &iter);
@@ -1179,7 +1179,7 @@ static inline int copy_to_iotlb(const stif (ret <0 )return ret; -iov_iter_bvec (&iter,WRITE , iov, ret, len); +iov_iter_bvec (&iter,ITER_SOURCE , iov, ret, len);return copy_to_iter (src, len, &iter); }
drivers/vhost/vsock.c +2 -2
@@ -166,7 +166,7 @@ vhost_transport_do_send_pkt(struct vhostbreak ; } -iov_iter_init (&iov_iter,READ , &vq->iov[out], in, iov_len); +iov_iter_init (&iov_iter,ITER_DEST , &vq->iov[out], in, iov_len); payload_len = pkt->len - pkt->off;/* If the packet is greater than the space available in the
@@ -372,7 +372,7 @@ vhost_vsock_alloc_pkt(struct vhost_virtqreturn NULL ; len =iov_length (vq->iov, out); -iov_iter_init (&iov_iter,WRITE , vq->iov, out, len); +iov_iter_init (&iov_iter,ITER_SOURCE , vq->iov, out, len); nbytes =copy_from_iter (&pkt->hdr,sizeof (pkt->hdr), &iov_iter);if (nbytes !=sizeof (pkt->hdr)) {
drivers/xen/pvcalls-back.c +4 -4
@@ -129,13 +129,13 @@ static bool pvcalls_conn_back_read(voidif (masked_prod < masked_cons) { vec[0 ].iov_base = data->in + masked_prod; vec[0 ].iov_len = wanted; -iov_iter_kvec (&msg.msg_iter,READ , vec,1 , wanted); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , vec,1 , wanted); }else { vec[0 ].iov_base = data->in + masked_prod; vec[0 ].iov_len = array_size - masked_prod; vec[1 ].iov_base = data->in; vec[1 ].iov_len = wanted - vec[0 ].iov_len; -iov_iter_kvec (&msg.msg_iter,READ , vec,2 , wanted); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , vec,2 , wanted); }atomic_set (&map->read,0 );
@@ -188,13 +188,13 @@ static bool pvcalls_conn_back_write(struif (pvcalls_mask (prod, array_size) >pvcalls_mask (cons, array_size)) { vec[0 ].iov_base = data->out +pvcalls_mask (cons, array_size); vec[0 ].iov_len = size; -iov_iter_kvec (&msg.msg_iter,WRITE , vec,1 , size); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , vec,1 , size); }else { vec[0 ].iov_base = data->out +pvcalls_mask (cons, array_size); vec[0 ].iov_len = array_size -pvcalls_mask (cons, array_size); vec[1 ].iov_base = data->out; vec[1 ].iov_len = size - vec[0 ].iov_len; -iov_iter_kvec (&msg.msg_iter,WRITE , vec,2 , size); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , vec,2 , size); }atomic_set (&map->write,0 );
fs/9p/vfs_addr.c +2 -2
@@ -50,7 +50,7 @@ static int v9fs_fid_readpage(void *data,if (retval ==0 )return retval; -iov_iter_bvec (&to,READ , &bvec,1 ,PAGE_SIZE ); +iov_iter_bvec (&to,ITER_DEST , &bvec,1 ,PAGE_SIZE ); retval =p9_client_read (fid,page_offset (page), &to, &err);if (err) {
@@ -163,7 +163,7 @@ static int v9fs_vfs_writepage_locked(str bvec.bv_page = page; bvec.bv_offset =0 ; bvec.bv_len = len; -iov_iter_bvec (&from,WRITE , &bvec,1 , len); +iov_iter_bvec (&from,ITER_SOURCE , &bvec,1 , len);/* We should have writeback_fid always set */ BUG_ON (!v9inode->writeback_fid);
fs/9p/vfs_dir.c +1 -1
@@ -108,7 +108,7 @@ static int v9fs_dir_readdir(struct fileif (rdir->tail == rdir->head) {struct iov_iter to;int n; -iov_iter_kvec (&to,READ , &kvec,1 , buflen); +iov_iter_kvec (&to,ITER_DEST , &kvec,1 , buflen); n =p9_client_read (file->private_data, ctx->pos, &to, &err);if (err)
fs/9p/xattr.c +2 -2
@@ -32,7 +32,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fidstruct iov_iter to;int err; -iov_iter_kvec (&to,READ , &kvec,1 , buffer_size); +iov_iter_kvec (&to,ITER_DEST , &kvec,1 , buffer_size); attr_fid =p9_client_xattrwalk (fid, name, &attr_size);if (IS_ERR (attr_fid)) {
@@ -117,7 +117,7 @@ int v9fs_fid_xattr_set(struct p9_fid *fistruct iov_iter from;int retval, err; -iov_iter_kvec (&from,WRITE , &kvec,1 , value_len); +iov_iter_kvec (&from,ITER_SOURCE , &kvec,1 , value_len);p9_debug (P9_DEBUG_VFS ,"name = %s value_len = %zu flags = %d\n" , name, value_len, flags);
fs/afs/cmservice.c +1 -1
@@ -298,7 +298,7 @@ static int afs_deliver_cb_callback(strucif (call->count2 != call->count && call->count2 !=0 )return afs_protocol_error (call, afs_eproto_cb_count); call->iter = &call->def_iter; -iov_iter_discard (&call->def_iter,READ , call->count2 *3 *4 ); +iov_iter_discard (&call->def_iter,ITER_DEST , call->count2 *3 *4 ); call->unmarshall++; fallthrough;
fs/afs/dir.c +1 -1
@@ -315,7 +315,7 @@ expand: req->actual_len = i_size;/* May change */ req->len = nr_pages *PAGE_SIZE ;/* We can ask for more than there is */ req->data_version = dvnode->status.data_version;/* May change */ -iov_iter_xarray (&req->def_iter,READ , &dvnode->vfs_inode.i_mapping->i_pages, +iov_iter_xarray (&req->def_iter,ITER_DEST , &dvnode->vfs_inode.i_mapping->i_pages,0 , i_size); req->iter = &req->def_iter;
fs/afs/file.c +2 -2
@@ -305,7 +305,7 @@ static void afs_req_issue_op(struct netf fsreq->vnode = vnode; fsreq->iter = &fsreq->def_iter; -iov_iter_xarray (&fsreq->def_iter,READ , +iov_iter_xarray (&fsreq->def_iter,ITER_DEST , &fsreq->vnode->vfs_inode.i_mapping->i_pages, fsreq->pos, fsreq->len);
@@ -327,7 +327,7 @@ static int afs_symlink_readpage(struct p fsreq->len =PAGE_SIZE ; fsreq->vnode = vnode; fsreq->iter = &fsreq->def_iter; -iov_iter_xarray (&fsreq->def_iter,READ , &page->mapping->i_pages, +iov_iter_xarray (&fsreq->def_iter,ITER_DEST , &page->mapping->i_pages, fsreq->pos, fsreq->len); ret =afs_fetch_data (fsreq->vnode, fsreq);
fs/afs/internal.h +2 -2
@@ -1296,7 +1296,7 @@ static inline void afs_extract_begin(str call->iov_len = size; call->kvec[0 ].iov_base = buf; call->kvec[0 ].iov_len = size; -iov_iter_kvec (&call->def_iter,READ , call->kvec,1 , size); +iov_iter_kvec (&call->def_iter,ITER_DEST , call->kvec,1 , size); }static inline void afs_extract_to_tmp (struct afs_call *call)
@@ -1314,7 +1314,7 @@ static inline void afs_extract_to_tmp64(static inline void afs_extract_discard (struct afs_call *call,size_t size) { call->iov_len = size; -iov_iter_discard (&call->def_iter,READ , size); +iov_iter_discard (&call->def_iter,ITER_DEST , size); }static inline void afs_extract_to_buf (struct afs_call *call,size_t size)
fs/afs/rxrpc.c +5 -5
@@ -358,7 +358,7 @@ void afs_make_call(struct afs_addr_curso msg.msg_name =NULL ; msg.msg_namelen =0 ; -iov_iter_kvec (&msg.msg_iter,WRITE , iov,1 , call->request_size); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , iov,1 , call->request_size); msg.msg_control =NULL ; msg.msg_controllen =0 ; msg.msg_flags =MSG_WAITALL | (call->write_iter ?MSG_MORE :0 );
@@ -399,7 +399,7 @@ error_do_abort: RX_USER_ABORT, ret, "KSD"); }else { len =0 ; -iov_iter_kvec (&msg.msg_iter,READ ,NULL ,0 ,0 ); +iov_iter_kvec (&msg.msg_iter,ITER_DEST ,NULL ,0 ,0 );rxrpc_kernel_recv_data (call->net->socket, rxcall, &msg.msg_iter, &len, false, &call->abort_code, &call->service_id);
@@ -484,7 +484,7 @@ static void afs_deliver_to_call(struct a ) {if (state ==AFS_CALL_SV_AWAIT_ACK ) { len =0 ; -iov_iter_kvec (&call->def_iter,READ ,NULL ,0 ,0 ); +iov_iter_kvec (&call->def_iter,ITER_DEST ,NULL ,0 ,0 ); ret = rxrpc_kernel_recv_data(call->net->socket, call->rxcall, &call->def_iter, &len, false, &remote_abort,
@@ -821,7 +821,7 @@ void afs_send_empty_reply(struct afs_cal msg.msg_name =NULL ; msg.msg_namelen =0 ; -iov_iter_kvec (&msg.msg_iter,WRITE ,NULL ,0 ,0 ); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE ,NULL ,0 ,0 ); msg.msg_control =NULL ; msg.msg_controllen =0 ; msg.msg_flags =0 ;
@@ -861,7 +861,7 @@ void afs_send_simple_reply(struct afs_ca iov[0 ].iov_len = len; msg.msg_name =NULL ; msg.msg_namelen =0 ; -iov_iter_kvec (&msg.msg_iter,WRITE , iov,1 , len); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , iov,1 , len); msg.msg_control =NULL ; msg.msg_controllen =0 ; msg.msg_flags =0 ;
fs/afs/write.c +2 -2
@@ -601,7 +601,7 @@ static ssize_t afs_write_back_from_lockeif (start < i_size) {_debug ("write back %x @%llx [%llx]" , len, start, i_size); -iov_iter_xarray (&iter,WRITE , &mapping->i_pages, start, len); +iov_iter_xarray (&iter,ITER_SOURCE , &mapping->i_pages, start, len); ret =afs_store_data (vnode, &iter, start, false); }else {_debug ("write discard %x @%llx [%llx]" , len, start, i_size);
@@ -972,7 +972,7 @@ int afs_launder_page(struct page *page) bv[0 ].bv_page = page; bv[0 ].bv_offset = f; bv[0 ].bv_len = t - f; -iov_iter_bvec (&iter,WRITE , bv,1 , bv[0 ].bv_len); +iov_iter_bvec (&iter,ITER_SOURCE , bv,1 , bv[0 ].bv_len);trace_afs_page_dirty (vnode,tracepoint_string ("launder" ), page); ret =afs_store_data (vnode, &iter,page_offset (page) + f, true);
fs/aio.c +2 -2
@@ -1546,7 +1546,7 @@ static int aio_read(struct kiocb *req, cif (unlikely (!file->f_op->read_iter))return -EINVAL ; - ret =aio_setup_rw (READ , iocb, &iovec, vectored, compat, &iter); + ret =aio_setup_rw (ITER_DEST , iocb, &iovec, vectored, compat, &iter);if (ret <0 )return ret; ret =rw_verify_area (READ , file, &req->ki_pos,iov_iter_count (&iter));
@@ -1574,7 +1574,7 @@ static int aio_write(struct kiocb *req,if (unlikely (!file->f_op->write_iter))return -EINVAL ; - ret =aio_setup_rw (WRITE , iocb, &iovec, vectored, compat, &iter); + ret =aio_setup_rw (ITER_SOURCE , iocb, &iovec, vectored, compat, &iter);if (ret <0 )return ret; ret =rw_verify_area (WRITE , file, &req->ki_pos,iov_iter_count (&iter));
fs/ceph/addr.c +1 -1
@@ -263,7 +263,7 @@ static void ceph_netfs_issue_op(struct n }dout ("%s: pos=%llu orig_len=%zu len=%llu\n" , __func__, subreq->start, subreq->len, len); -iov_iter_xarray (&iter,READ , &rreq->mapping->i_pages, subreq->start, len); +iov_iter_xarray (&iter,ITER_DEST , &rreq->mapping->i_pages, subreq->start, len); err =iov_iter_get_pages_alloc (&iter, &pages, len, &page_off);if (err <0 ) {dout ("%s: iov_ter_get_pages_alloc returned %d\n" , __func__, err);
fs/ceph/file.c +2 -2
@@ -1111,7 +1111,7 @@ static void ceph_aio_complete_req(struct aio_req->total_len = rc + zlen; } -iov_iter_bvec (&i,READ , osd_data->bvec_pos.bvecs, +iov_iter_bvec (&i,ITER_DEST , osd_data->bvec_pos.bvecs, osd_data->num_bvecs, len);iov_iter_advance (&i, rc);iov_iter_zero (zlen, &i);
@@ -1347,7 +1347,7 @@ ceph_direct_read_write(struct kiocb *iocint zlen =min_t (size_t, len - ret, size - pos - ret); -iov_iter_bvec (&i,READ , bvecs, num_pages, len); +iov_iter_bvec (&i,ITER_DEST , bvecs, num_pages, len);iov_iter_advance (&i, ret);iov_iter_zero (zlen, &i); ret += zlen;
fs/cifs/connect.c +3 -3
@@ -621,7 +621,7 @@ cifs_read_from_socket(struct TCP_Server_ {struct msghdr smb_msg = {};struct kvec iov = {.iov_base = buf, .iov_len = to_read}; -iov_iter_kvec (&smb_msg.msg_iter,READ , &iov,1 , to_read); +iov_iter_kvec (&smb_msg.msg_iter,ITER_DEST , &iov,1 , to_read);return cifs_readv_from_socket (server, &smb_msg); }
@@ -636,7 +636,7 @@ cifs_discard_from_socket(struct TCP_Serv* and cifs_readv_from_socket sets msg_control and msg_controllen * so little to initialize in struct msghdr */ -iov_iter_discard (&smb_msg.msg_iter,READ , to_read); +iov_iter_discard (&smb_msg.msg_iter,ITER_DEST , to_read);return cifs_readv_from_socket (server, &smb_msg); }
@@ -648,7 +648,7 @@ cifs_read_page_from_socket(struct TCP_Sestruct msghdr smb_msg = {};struct bio_vec bv = { .bv_page = page, .bv_len = to_read, .bv_offset = page_offset}; -iov_iter_bvec (&smb_msg.msg_iter,READ , &bv,1 , to_read); +iov_iter_bvec (&smb_msg.msg_iter,ITER_DEST , &bv,1 , to_read);return cifs_readv_from_socket (server, &smb_msg); }
fs/cifs/file.c +2 -2
@@ -3265,7 +3265,7 @@ static ssize_t __cifs_writev( ctx->iter = *from; ctx->len = len; }else { - rc =setup_aio_ctx_iter (ctx, from,WRITE ); + rc =setup_aio_ctx_iter (ctx, from,ITER_SOURCE );if (rc) {kref_put (&ctx->refcount, cifs_aio_ctx_release);return rc;
@@ -4010,7 +4010,7 @@ static ssize_t __cifs_readv( ctx->iter = *to; ctx->len = len; }else { - rc =setup_aio_ctx_iter (ctx, to,READ ); + rc =setup_aio_ctx_iter (ctx, to,ITER_DEST );if (rc) {kref_put (&ctx->refcount, cifs_aio_ctx_release);return rc;
fs/cifs/smb2ops.c +2 -2
@@ -4960,13 +4960,13 @@ handle_read_data(struct TCP_Server_Inforeturn 0 ; } -iov_iter_bvec (&iter,WRITE , bvec, npages, data_len); +iov_iter_bvec (&iter,ITER_SOURCE , bvec, npages, data_len); }else if (buf_len >= data_offset + data_len) {/* read response payload is in buf */ WARN_ONCE (npages >0 ,"read data can be either in buf or in pages" ); iov.iov_base = buf + data_offset; iov.iov_len = data_len; -iov_iter_kvec (&iter,WRITE , &iov,1 , data_len); +iov_iter_kvec (&iter,ITER_SOURCE , &iov,1 , data_len); }else {/* read response payload cannot be in both buf and pages */ WARN_ONCE (1 ,"buf can not contain only a part of read data" );
fs/cifs/transport.c +3 -3
@@ -349,7 +349,7 @@ __smb_send_rqst(struct TCP_Server_Info * .iov_base = &rfc1002_marker, .iov_len = 4 }; -iov_iter_kvec (&smb_msg.msg_iter,WRITE , &hiov,1 ,4 ); +iov_iter_kvec (&smb_msg.msg_iter,ITER_SOURCE , &hiov,1 ,4 ); rc =smb_send_kvec (server, &smb_msg, &sent);if (rc <0 ) goto unmask;
@@ -370,7 +370,7 @@ __smb_send_rqst(struct TCP_Server_Info * size += iov[i].iov_len; } -iov_iter_kvec (&smb_msg.msg_iter,WRITE , iov, n_vec, size); +iov_iter_kvec (&smb_msg.msg_iter,ITER_SOURCE , iov, n_vec, size); rc =smb_send_kvec (server, &smb_msg, &sent);if (rc <0 )
@@ -386,7 +386,7 @@ __smb_send_rqst(struct TCP_Server_Info *rqst_page_get_length (&rqst[j], i, &bvec.bv_len, &bvec.bv_offset); -iov_iter_bvec (&smb_msg.msg_iter,WRITE , +iov_iter_bvec (&smb_msg.msg_iter,ITER_SOURCE , &bvec,1 , bvec.bv_len); rc =smb_send_kvec (server, &smb_msg, &sent);if (rc <0 )
fs/fuse/ioctl.c +2 -2
@@ -264,7 +264,7 @@ long fuse_do_ioctl(struct file *file, un ap.args.in_pages = true; err = -EFAULT ; -iov_iter_init (&ii,WRITE , in_iov, in_iovs, in_size); +iov_iter_init (&ii,ITER_SOURCE , in_iov, in_iovs, in_size);for (i =0 ;iov_iter_count (&ii) && !WARN_ON (i >= ap.num_pages); i++) { c =copy_page_from_iter (ap.pages[i],0 ,PAGE_SIZE , &ii);if (c !=PAGE_SIZE &&iov_iter_count (&ii))
@@ -331,7 +331,7 @@ long fuse_do_ioctl(struct file *file, un goto out; err = -EFAULT ; -iov_iter_init (&ii,READ , out_iov, out_iovs, transferred); +iov_iter_init (&ii,ITER_DEST , out_iov, out_iovs, transferred);for (i =0 ;iov_iter_count (&ii) && !WARN_ON (i >= ap.num_pages); i++) { c =copy_page_to_iter (ap.pages[i],0 ,PAGE_SIZE , &ii);if (c !=PAGE_SIZE &&iov_iter_count (&ii))
fs/nfsd/vfs.c +2 -2
@@ -1027,7 +1027,7 @@ __be32 nfsd_readv(struct svc_rqst *rqstpssize_t host_err;trace_nfsd_read_vector (rqstp, fhp, offset, *count); -iov_iter_kvec (&iter,READ , vec, vlen, *count); +iov_iter_kvec (&iter,ITER_DEST , vec, vlen, *count); host_err =vfs_iter_read (file, &iter, &ppos,0 );return nfsd_finish_read (rqstp, fhp, file, offset, count, eof, host_err); }
@@ -1117,7 +1117,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, sif (stable && !use_wgather) flags |=RWF_SYNC ; -iov_iter_kvec (&iter,WRITE , vec, vlen, *cnt); +iov_iter_kvec (&iter,ITER_SOURCE , vec, vlen, *cnt); since =READ_ONCE (file->f_wb_err);if (verf)nfsd_copy_write_verifier (verf, nn);
fs/ocfs2/cluster/tcp.c +1 -1
@@ -900,7 +900,7 @@ static int o2net_recv_tcp_msg(struct soc {struct kvec vec = { .iov_len = len, .iov_base = data, };struct msghdr msg = { .msg_flags =MSG_DONTWAIT , }; -iov_iter_kvec (&msg.msg_iter,READ , &vec,1 , len); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &vec,1 , len);return sock_recvmsg (sock, &msg,MSG_DONTWAIT ); }
fs/orangefs/inode.c +4 -4
@@ -53,7 +53,7 @@ static int orangefs_writepage_locked(str bv.bv_len = wlen; bv.bv_offset = off %PAGE_SIZE ;WARN_ON (wlen ==0 ); -iov_iter_bvec (&iter,WRITE , &bv,1 , wlen); +iov_iter_bvec (&iter,ITER_SOURCE , &bv,1 , wlen); ret =wait_for_direct_io (ORANGEFS_IO_WRITE , inode, &off, &iter, wlen, len, wr,NULL ,NULL );
@@ -111,7 +111,7 @@ static int orangefs_writepages_work(struelse ow->bv[i].bv_offset =0 ; } -iov_iter_bvec (&iter,WRITE , ow->bv, ow->npages, ow->len); +iov_iter_bvec (&iter,ITER_SOURCE , ow->bv, ow->npages, ow->len);WARN_ON (ow->off >= len);if (ow->off + ow->len > len)
@@ -269,7 +269,7 @@ static void orangefs_readahead(struct re offset =readahead_pos (rac); i_pages = &rac->mapping->i_pages; -iov_iter_xarray (&iter,READ , i_pages, offset,readahead_length (rac)); +iov_iter_xarray (&iter,ITER_DEST , i_pages, offset,readahead_length (rac));/* read in the pages. */ if ((ret = wait_for_direct_io(ORANGEFS_IO_READ, inode,
@@ -302,7 +302,7 @@ static int orangefs_readpage(struct file bv.bv_page = page; bv.bv_len =PAGE_SIZE ; bv.bv_offset =0 ; -iov_iter_bvec (&iter,READ , &bv,1 ,PAGE_SIZE ); +iov_iter_bvec (&iter,ITER_DEST , &bv,1 ,PAGE_SIZE ); ret =wait_for_direct_io (ORANGEFS_IO_READ , inode, &off, &iter,PAGE_SIZE , inode->i_size,NULL ,NULL , file);
fs/read_write.c +6 -6
@@ -399,7 +399,7 @@ static ssize_t new_sync_read(struct fileinit_sync_kiocb (&kiocb, filp); kiocb.ki_pos = (ppos ? *ppos :0 ); -iov_iter_init (&iter,READ , &iov,1 , len); +iov_iter_init (&iter,ITER_DEST , &iov,1 , len); ret =call_read_iter (filp, &kiocb, &iter);BUG_ON (ret == -EIOCBQUEUED );
@@ -439,7 +439,7 @@ ssize_t __kernel_read(struct file *file,init_sync_kiocb (&kiocb, file); kiocb.ki_pos = pos ? *pos :0 ; -iov_iter_kvec (&iter,READ , &iov,1 , iov.iov_len); +iov_iter_kvec (&iter,ITER_DEST , &iov,1 , iov.iov_len); ret = file->f_op->read_iter (&kiocb, &iter);if (ret >0 ) {if (pos)
@@ -502,7 +502,7 @@ static ssize_t new_sync_write(struct filinit_sync_kiocb (&kiocb, filp); kiocb.ki_pos = (ppos ? *ppos :0 ); -iov_iter_init (&iter,WRITE , &iov,1 , len); +iov_iter_init (&iter,ITER_SOURCE , &iov,1 , len); ret =call_write_iter (filp, &kiocb, &iter);BUG_ON (ret == -EIOCBQUEUED );
@@ -535,7 +535,7 @@ ssize_t __kernel_write(struct file *fileinit_sync_kiocb (&kiocb, file); kiocb.ki_pos = pos ? *pos :0 ; -iov_iter_kvec (&iter,WRITE , &iov,1 , iov.iov_len); +iov_iter_kvec (&iter,ITER_SOURCE , &iov,1 , iov.iov_len); ret = file->f_op->write_iter (&kiocb, &iter);if (ret >0 ) {if (pos)
@@ -905,7 +905,7 @@ static ssize_t vfs_readv(struct file *fistruct iov_iter iter;ssize_t ret; - ret =import_iovec (READ , vec, vlen,ARRAY_SIZE (iovstack), &iov, &iter); + ret =import_iovec (ITER_DEST , vec, vlen,ARRAY_SIZE (iovstack), &iov, &iter);if (ret >=0 ) { ret =do_iter_read (file, &iter, pos, flags);kfree (iov);
@@ -922,7 +922,7 @@ static ssize_t vfs_writev(struct file *fstruct iov_iter iter;ssize_t ret; - ret =import_iovec (WRITE , vec, vlen,ARRAY_SIZE (iovstack), &iov, &iter); + ret =import_iovec (ITER_SOURCE , vec, vlen,ARRAY_SIZE (iovstack), &iov, &iter);if (ret >=0 ) {file_start_write (file); ret =do_iter_write (file, &iter, pos, flags);
fs/seq_file.c +1 -1
@@ -156,7 +156,7 @@ ssize_t seq_read(struct file *file, charssize_t ret;init_sync_kiocb (&kiocb, file); -iov_iter_init (&iter,READ , &iov,1 , size); +iov_iter_init (&iter,ITER_DEST , &iov,1 , size); kiocb.ki_pos = *ppos; ret =seq_read_iter (&kiocb, &iter);
fs/splice.c +5 -5
@@ -304,7 +304,7 @@ ssize_t generic_file_splice_read(structunsigned int i_head;int ret; -iov_iter_pipe (&to,READ , pipe, len); +iov_iter_pipe (&to,ITER_DEST , pipe, len); i_head = to.head;init_sync_kiocb (&kiocb, in); kiocb.ki_pos = *ppos;
@@ -685,7 +685,7 @@ iter_file_splice_write(struct pipe_inode n++; } -iov_iter_bvec (&from,WRITE , array, n, sd.total_len - left); +iov_iter_bvec (&from,ITER_SOURCE , array, n, sd.total_len - left); ret =vfs_iter_write (out, &from, &sd.pos,0 );if (ret <=0 )break ;
@@ -1296,9 +1296,9 @@ static int vmsplice_type(struct fd f, inif (!f.file)return -EBADF ;if (f.file->f_mode &FMODE_WRITE ) { - *type =WRITE ; + *type =ITER_SOURCE ; }else if (f.file->f_mode &FMODE_READ ) { - *type =READ ; + *type =ITER_DEST ; }else {fdput (f);return -EBADF ;
@@ -1347,7 +1347,7 @@ SYSCALL_DEFINE4(vmsplice, int, fd, constif (!iov_iter_count (&iter)) error =0 ; -else if (iov_iter_rw (&iter) ==WRITE ) +else if (type ==ITER_SOURCE ) error =vmsplice_to_pipe (f.file, &iter, flags);else error =vmsplice_to_user (f.file, &iter, flags);
include/linux/uio.h +3 -0
@@ -27,6 +27,9 @@ enum iter_type { ITER_DISCARD, }; +#define ITER_SOURCE 1 // == WRITE +#define ITER_DEST 0 // == READ +struct iov_iter_state {size_t iov_offset;size_t count;
mm/madvise.c +1 -1
@@ -1251,7 +1251,7 @@ SYSCALL_DEFINE5(process_madvise, int, pi goto out; } - ret =import_iovec (READ , vec, vlen,ARRAY_SIZE (iovstack), &iov, &iter); + ret =import_iovec (ITER_DEST , vec, vlen,ARRAY_SIZE (iovstack), &iov, &iter);if (ret <0 ) goto out;
mm/page_io.c +1 -1
@@ -252,7 +252,7 @@ int __swap_writepage(struct page *page, };struct iov_iter from; -iov_iter_bvec (&from,WRITE , &bv,1 ,PAGE_SIZE ); +iov_iter_bvec (&from,ITER_SOURCE , &bv,1 ,PAGE_SIZE );init_sync_kiocb (&kiocb, swap_file); kiocb.ki_pos =page_file_offset (page);
mm/process_vm_access.c +1 -1
@@ -263,7 +263,7 @@ static ssize_t process_vm_rw(pid_t pid,struct iovec *iov_r;struct iov_iter iter;ssize_t rc; -int dir = vm_write ?WRITE :READ ; +int dir = vm_write ?ITER_SOURCE :ITER_DEST ;if (flags !=0 )return -EINVAL ;
net/9p/client.c +1 -1
@@ -2096,7 +2096,7 @@ int p9_client_readdir(struct p9_fid *fidstruct kvec kv = {.iov_base = data, .iov_len = count};struct iov_iter to; -iov_iter_kvec (&to,READ , &kv,1 , count); +iov_iter_kvec (&to,ITER_DEST , &kv,1 , count);p9_debug (P9_DEBUG_9P ,">>> TREADDIR fid %d offset %llu count %d\n" , fid->fid, offset, count);
net/bluetooth/6lowpan.c +1 -1
@@ -449,7 +449,7 @@ static int send_pkt(struct l2cap_chan *c iv.iov_len = skb->len;memset (&msg,0 ,sizeof (msg)); -iov_iter_kvec (&msg.msg_iter,WRITE , &iv,1 , skb->len); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , &iv,1 , skb->len); err =l2cap_chan_send (chan, &msg, skb->len);if (err >0 ) {
net/bluetooth/a2mp.c +1 -1
@@ -56,7 +56,7 @@ static void a2mp_send(struct amp_mgr *mgmemset (&msg,0 ,sizeof (msg)); -iov_iter_kvec (&msg.msg_iter,WRITE , &iv,1 , total_len); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , &iv,1 , total_len);l2cap_chan_send (chan, &msg, total_len);
net/bluetooth/smp.c +1 -1
@@ -605,7 +605,7 @@ static void smp_send_cmd(struct l2cap_comemset (&msg,0 ,sizeof (msg)); -iov_iter_kvec (&msg.msg_iter,WRITE , iv,2 ,1 + len); +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , iv,2 ,1 + len);l2cap_chan_send (chan, &msg,1 + len);
net/ceph/messenger_v1.c +2 -2
@@ -30,7 +30,7 @@ static int ceph_tcp_recvmsg(struct sockeif (!buf) msg.msg_flags |=MSG_TRUNC ; -iov_iter_kvec (&msg.msg_iter,READ , &iov,1 , len); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , len); r =sock_recvmsg (sock, &msg, msg.msg_flags);if (r == -EAGAIN ) r =0 ;
@@ -49,7 +49,7 @@ static int ceph_tcp_recvpage(struct sockint r;BUG_ON (page_offset + length >PAGE_SIZE ); -iov_iter_bvec (&msg.msg_iter,READ , &bvec,1 , length); +iov_iter_bvec (&msg.msg_iter,ITER_DEST , &bvec,1 , length); r =sock_recvmsg (sock, &msg, msg.msg_flags);if (r == -EAGAIN ) r =0 ;
net/ceph/messenger_v2.c +7 -7
@@ -167,7 +167,7 @@ static int do_try_sendpage(struct socket bv.bv_offset, bv.bv_len, CEPH_MSG_FLAGS); }else { -iov_iter_bvec (&msg.msg_iter,WRITE , &bv,1 , bv.bv_len); +iov_iter_bvec (&msg.msg_iter,ITER_SOURCE , &bv,1 , bv.bv_len); ret =sock_sendmsg (sock, &msg); }if (ret <=0 ) {
@@ -224,7 +224,7 @@ static void reset_in_kvecs(struct ceph_cWARN_ON (iov_iter_count (&con->v2.in_iter)); con->v2.in_kvec_cnt =0 ; -iov_iter_kvec (&con->v2.in_iter,READ , con->v2.in_kvecs,0 ,0 ); +iov_iter_kvec (&con->v2.in_iter,ITER_DEST , con->v2.in_kvecs,0 ,0 ); }static void set_in_bvec (struct ceph_connection *con,const struct bio_vec *bv)
@@ -232,7 +232,7 @@ static void set_in_bvec(struct ceph_connWARN_ON (iov_iter_count (&con->v2.in_iter)); con->v2.in_bvec = *bv; -iov_iter_bvec (&con->v2.in_iter,READ , &con->v2.in_bvec,1 , bv->bv_len); +iov_iter_bvec (&con->v2.in_iter,ITER_DEST , &con->v2.in_bvec,1 , bv->bv_len); }static void set_in_skip (struct ceph_connection *con,int len)
@@ -240,7 +240,7 @@ static void set_in_skip(struct ceph_connWARN_ON (iov_iter_count (&con->v2.in_iter));dout ("%s con %p len %d\n" , __func__, con, len); -iov_iter_discard (&con->v2.in_iter,READ , len); +iov_iter_discard (&con->v2.in_iter,ITER_DEST , len); }static void add_out_kvec (struct ceph_connection *con,void *buf,int len)
@@ -264,7 +264,7 @@ static void reset_out_kvecs(struct ceph_ con->v2.out_kvec_cnt =0 ; -iov_iter_kvec (&con->v2.out_iter,WRITE , con->v2.out_kvecs,0 ,0 ); +iov_iter_kvec (&con->v2.out_iter,ITER_SOURCE , con->v2.out_kvecs,0 ,0 ); con->v2.out_iter_sendpage = false; }
@@ -276,7 +276,7 @@ static void set_out_bvec(struct ceph_con con->v2.out_bvec = *bv; con->v2.out_iter_sendpage = zerocopy; -iov_iter_bvec (&con->v2.out_iter,WRITE , &con->v2.out_bvec,1 , +iov_iter_bvec (&con->v2.out_iter,ITER_SOURCE , &con->v2.out_bvec,1 , con->v2.out_bvec.bv_len); }
@@ -289,7 +289,7 @@ static void set_out_bvec_zero(struct cep con->v2.out_bvec.bv_offset =0 ; con->v2.out_bvec.bv_len =min (con->v2.out_zero, (int )PAGE_SIZE ); con->v2.out_iter_sendpage = true; -iov_iter_bvec (&con->v2.out_iter,WRITE , &con->v2.out_bvec,1 , +iov_iter_bvec (&con->v2.out_iter,ITER_SOURCE , &con->v2.out_bvec,1 , con->v2.out_bvec.bv_len); }
net/compat.c +1 -1
@@ -98,7 +98,7 @@ int get_compat_msghdr(struct msghdr *kmsif (err)return err; - err =import_iovec (save_addr ?READ :WRITE ,compat_ptr (ptr), len, + err =import_iovec (save_addr ?ITER_DEST :ITER_SOURCE ,compat_ptr (ptr), len,UIO_FASTIOV , iov, &kmsg->msg_iter);return err <0 ? err :0 ; }
net/ipv4/tcp.c +2 -2
@@ -1886,7 +1886,7 @@ static int receive_fallback_to_copy(struif (copy_address != zc->copybuf_address)return -EINVAL ; - err =import_single_range (READ , (void __user *)copy_address, + err =import_single_range (ITER_DEST , (void __user *)copy_address, inq, &iov, &msg.msg_iter);if (err)return err;
@@ -1920,7 +1920,7 @@ static int tcp_copy_straggler_data(strucif (copy_address != zc->copybuf_address)return -EINVAL ; - err =import_single_range (READ , (void __user *)copy_address, + err =import_single_range (ITER_DEST , (void __user *)copy_address, copylen, &iov, &msg.msg_iter);if (err)return err;
net/netfilter/ipvs/ip_vs_sync.c +1 -1
@@ -1617,7 +1617,7 @@ ip_vs_receive(struct socket *sock, charEnterFunction (7 );/* Receive a packet */ -iov_iter_kvec (&msg.msg_iter,READ , &iov,1 , buflen); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , buflen); len =sock_recvmsg (sock, &msg,MSG_DONTWAIT );if (len <0 )return len;
net/smc/smc_clc.c +3 -3
@@ -361,7 +361,7 @@ int smc_clc_wait_msg(struct smc_sock *sm*/ krflags =MSG_PEEK |MSG_WAITALL ; clc_sk->sk_rcvtimeo = timeout; -iov_iter_kvec (&msg.msg_iter,READ , &vec,1 , +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &vec,1 ,sizeof (struct smc_clc_msg_hdr )); len =sock_recvmsg (smc->clcsock, &msg, krflags);if (signal_pending (current)) {
@@ -408,7 +408,7 @@ int smc_clc_wait_msg(struct smc_sock *sm }else { recvlen = datlen; } -iov_iter_kvec (&msg.msg_iter,READ , &vec,1 , recvlen); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &vec,1 , recvlen); krflags =MSG_WAITALL ; len =sock_recvmsg (smc->clcsock, &msg, krflags);if (len < recvlen || !smc_clc_msg_hdr_valid (clcm, check_trl)) {
@@ -425,7 +425,7 @@ int smc_clc_wait_msg(struct smc_sock *sm/* receive remaining proposal message */ recvlen = datlen >SMC_CLC_RECV_BUF_LEN ?SMC_CLC_RECV_BUF_LEN : datlen; -iov_iter_kvec (&msg.msg_iter,READ , &vec,1 , recvlen); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &vec,1 , recvlen); len =sock_recvmsg (smc->clcsock, &msg, krflags);if (len < recvlen) { smc->sk.sk_err =EPROTO ;
net/socket.c +6 -6
@@ -761,7 +761,7 @@ EXPORT_SYMBOL(sock_sendmsg);int kernel_sendmsg (struct socket *sock,struct msghdr *msg,struct kvec *vec,size_t num,size_t size) { -iov_iter_kvec (&msg->msg_iter,WRITE , vec, num, size); +iov_iter_kvec (&msg->msg_iter,ITER_SOURCE , vec, num, size);return sock_sendmsg (sock, msg); }EXPORT_SYMBOL (kernel_sendmsg);
@@ -787,7 +787,7 @@ int kernel_sendmsg_locked(struct sock *sif (!sock->ops->sendmsg_locked)return sock_no_sendmsg_locked (sk, msg, size); -iov_iter_kvec (&msg->msg_iter,WRITE , vec, num, size); +iov_iter_kvec (&msg->msg_iter,ITER_SOURCE , vec, num, size);return sock->ops->sendmsg_locked (sk, msg,msg_data_left (msg)); }
@@ -1008,7 +1008,7 @@ int kernel_recvmsg(struct socket *sock, struct kvec *vec, size_t num, size_t size, int flags) { msg->msg_control_is_user = false; -iov_iter_kvec (&msg->msg_iter,READ , vec, num, size); +iov_iter_kvec (&msg->msg_iter,ITER_DEST , vec, num, size);return sock_recvmsg (sock, msg, flags); }EXPORT_SYMBOL (kernel_recvmsg);
@@ -2049,7 +2049,7 @@ int __sys_sendto(int fd, void __user *bustruct iovec iov;int fput_needed; - err =import_single_range (WRITE , buff, len, &iov, &msg.msg_iter); + err =import_single_range (ITER_SOURCE , buff, len, &iov, &msg.msg_iter);if (unlikely (err))return err; sock =sockfd_lookup_light (fd, &err, &fput_needed);
@@ -2110,7 +2110,7 @@ int __sys_recvfrom(int fd, void __user *int err, err2;int fput_needed; - err =import_single_range (READ , ubuf, size, &iov, &msg.msg_iter); + err =import_single_range (ITER_DEST , ubuf, size, &iov, &msg.msg_iter);if (unlikely (err))return err; sock =sockfd_lookup_light (fd, &err, &fput_needed);
@@ -2381,7 +2381,7 @@ static int copy_msghdr_from_user(structif (err)return err; - err =import_iovec (save_addr ?READ :WRITE , + err =import_iovec (save_addr ?ITER_DEST :ITER_SOURCE , msg.msg_iov, msg.msg_iovlen,UIO_FASTIOV , iov, &kmsg->msg_iter);return err <0 ? err :0 ;
net/sunrpc/socklib.c +3 -3
@@ -213,7 +213,7 @@ static inline int xprt_sendmsg(struct sostatic int xprt_send_kvec (struct socket *sock,struct msghdr *msg,struct kvec *vec,size_t seek) { -iov_iter_kvec (&msg->msg_iter,WRITE , vec,1 , vec->iov_len); +iov_iter_kvec (&msg->msg_iter,ITER_SOURCE , vec,1 , vec->iov_len);return xprt_sendmsg (sock, msg, seek); }
@@ -226,7 +226,7 @@ static int xprt_send_pagedata(struct socif (err <0 )return err; -iov_iter_bvec (&msg->msg_iter,WRITE , xdr->bvec,xdr_buf_pagecount (xdr), +iov_iter_bvec (&msg->msg_iter,ITER_SOURCE , xdr->bvec,xdr_buf_pagecount (xdr), xdr->page_len + xdr->page_base);return xprt_sendmsg (sock, msg, base + xdr->page_base); }
@@ -249,7 +249,7 @@ static int xprt_send_rm_and_kvec(struct };size_t len = iov[0 ].iov_len + iov[1 ].iov_len; -iov_iter_kvec (&msg->msg_iter,WRITE , iov,2 , len); +iov_iter_kvec (&msg->msg_iter,ITER_SOURCE , iov,2 , len);return xprt_sendmsg (sock, msg, base); }
net/sunrpc/svcsock.c +2 -2
@@ -260,7 +260,7 @@ static ssize_t svc_tcp_read_msg(struct s rqstp->rq_respages = &rqstp->rq_pages[i]; rqstp->rq_next_page = rqstp->rq_respages +1 ; -iov_iter_bvec (&msg.msg_iter,READ , bvec, i, buflen); +iov_iter_bvec (&msg.msg_iter,ITER_DEST , bvec, i, buflen);if (seek) {iov_iter_advance (&msg.msg_iter, seek); buflen -= seek;
@@ -871,7 +871,7 @@ static ssize_t svc_tcp_read_marker(struc want =sizeof (rpc_fraghdr) - svsk->sk_tcplen; iov.iov_base = ((char *)&svsk->sk_marker) + svsk->sk_tcplen; iov.iov_len = want; -iov_iter_kvec (&msg.msg_iter,READ , &iov,1 , want); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , want); len =sock_recvmsg (svsk->sk_sock, &msg,MSG_DONTWAIT );if (len <0 )return len;
net/sunrpc/xprtsock.c +3 -3
@@ -363,7 +363,7 @@ static ssize_t xs_read_kvec(struct socket *sock, struct msghdr *msg, int flags, struct kvec *kvec, size_t count, size_t seek) { - iov_iter_kvec(&msg->msg_iter, READ, kvec, 1, count); + iov_iter_kvec(&msg->msg_iter, ITER_DEST, kvec, 1, count);return xs_sock_recvmsg (sock, msg, flags, seek); }
@@ -372,7 +372,7 @@ xs_read_bvec(struct socket *sock, struct struct bio_vec *bvec, unsigned long nr, size_t count, size_t seek) { - iov_iter_bvec(&msg->msg_iter, READ, bvec, nr, count); + iov_iter_bvec(&msg->msg_iter, ITER_DEST, bvec, nr, count);return xs_sock_recvmsg (sock, msg, flags, seek); }
@@ -380,7 +380,7 @@ static ssize_t xs_read_discard(struct socket *sock, struct msghdr *msg, int flags, size_t count) { - iov_iter_discard(&msg->msg_iter, READ, count); + iov_iter_discard(&msg->msg_iter, ITER_DEST, count);return sock_recvmsg (sock, msg, flags); }
net/tipc/topsrv.c +1 -1
@@ -396,7 +396,7 @@ static int tipc_conn_rcv_from_sock(struc iov.iov_base = &s; iov.iov_len =sizeof (s); msg.msg_name =NULL ; -iov_iter_kvec (&msg.msg_iter,READ , &iov,1 , iov.iov_len); +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , iov.iov_len); ret =sock_recvmsg (con->sock, &msg,MSG_DONTWAIT );if (ret == -EWOULDBLOCK )return -EWOULDBLOCK ;
net/tls/tls_device.c +2 -2
@@ -571,7 +571,7 @@ int tls_device_sendpage(struct sock *sk, kaddr =kmap (page); iov.iov_base = kaddr + offset; iov.iov_len = size; -iov_iter_kvec (&msg_iter,WRITE , &iov,1 , size); +iov_iter_kvec (&msg_iter,ITER_SOURCE , &iov,1 , size); rc =tls_push_data (sk, &msg_iter, size, flags,TLS_RECORD_TYPE_DATA );kunmap (page);
@@ -646,7 +646,7 @@ static int tls_device_push_pending_recor {struct iov_iter msg_iter; -iov_iter_kvec (&msg_iter,WRITE ,NULL ,0 ,0 ); +iov_iter_kvec (&msg_iter,ITER_SOURCE ,NULL ,0 ,0 );return tls_push_data (sk, &msg_iter,0 , flags,TLS_RECORD_TYPE_DATA ); }
net/xfrm/espintcp.c +1 -1
@@ -362,7 +362,7 @@ static int espintcp_sendmsg(struct sock *((__be16 *)buf) =cpu_to_be16 (msglen); pfx_iov.iov_base = buf; pfx_iov.iov_len =sizeof (buf); -iov_iter_kvec (&pfx_iter,WRITE , &pfx_iov,1 , pfx_iov.iov_len); +iov_iter_kvec (&pfx_iter,ITER_SOURCE , &pfx_iov,1 , pfx_iov.iov_len); err =sk_msg_memcopy_from_iter (sk, &pfx_iter, &emsg->skmsg, pfx_iov.iov_len);
security/keys/keyctl.c +2 -2
@@ -1256,7 +1256,7 @@ long keyctl_instantiate_key(key_serial_tstruct iov_iter from;int ret; - ret =import_single_range (WRITE , (void __user *)_payload, plen, + ret =import_single_range (ITER_SOURCE , (void __user *)_payload, plen, &iov, &from);if (unlikely (ret))return ret;
@@ -1288,7 +1288,7 @@ long keyctl_instantiate_key_iov(key_seriif (!_payload_iov) ioc =0 ; - ret =import_iovec (WRITE , _payload_iov, ioc, + ret =import_iovec (ITER_SOURCE , _payload_iov, ioc,ARRAY_SIZE (iovstack), &iov, &from);if (ret <0 )return ret;
Greg Kroah-Hartman
maintainerPATCH 353/411 mptcp: pm: fix ADD_ADDR timer infinite retry on option space insufficient
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Xiasong <[email protected]>
[ Upstream commit 51e398a3b8961b26a8c0a4ba9a777c5339791707 ]
When TCP option space is insufficient (e.g., when sending ADD_ADDR with an IPv6 address and port while tcp_timestamps is enabled), the original code jumped to out_unlock without clearing the addr_signal flag. This caused mptcp_pm_add_timer to keep rescheduling indefinitely, not sending ADD_ADDR, preventing subsequent addresses in the endpoint list from being announced.
Handle this case by clearing the ADD_ADDR signal and skipping the matching ADD_ADDR retransmission entry. The skip path cancels the matching timer (with id check) and advances PM state progression, preserving forward progress to subsequent PM work.
This cancellation is inherently best-effort. A concurrent add_timer callback may already be running and may acquire pm.lock before the cancel path updates entry state. In that case, one final ADD_ADDR transmit attempt can still be executed.
Once the cancel path sets entry->retrans_times to ADD_ADDR_RETRANS_MAX, the callback-side retrans_times check suppresses further ADD_ADDR retransmissions.
Note that when an ADD_ADDR is being prepared, a pure-ACK is queued. On the output side, it means that it is fine to skip non-pure-ACK packets, when drop_other_suboptions is set: a pure-ACK will be processed soon after.
--- net/mptcp/pm.c | 34 +++++++++++++++++++++++++++------- net/mptcp/pm_netlink.c | 16 +++++++++++++--- 2 files changed, 40 insertions(+), 10 deletions(-)
net/mptcp/pm.c +27 -7
@@ -270,6 +270,7 @@ bool mptcp_pm_add_addr_signal(struct mpt struct mptcp_addr_info *addr, bool *echo, bool *drop_other_suboptions) { + bool skip_add_addr = false;int ret = false;u8 add_addr;u8 family;
@@ -291,24 +292,43 @@ bool mptcp_pm_add_addr_signal(struct mpt } *echo =mptcp_pm_should_add_signal_echo (msk); - port = !!(*echo ? msk->pm.remote.port : msk->pm.local.port); - - family = *echo ? msk->pm.remote.family : msk->pm.local.family; -if (remaining <mptcp_add_addr_len (family, *echo, port)) - goto out_unlock; -if (*echo) { *addr = msk->pm.remote; add_addr = msk->pm.addr_signal & ~BIT (MPTCP_ADD_ADDR_ECHO ); + port = !!msk->pm.remote.port; + family = msk->pm.remote.family; }else { *addr = msk->pm.local; add_addr = msk->pm.addr_signal & ~BIT (MPTCP_ADD_ADDR_SIGNAL ); + port = !!msk->pm.local.port; + family = msk->pm.local.family; } -WRITE_ONCE (msk->pm.addr_signal, add_addr); + +if (remaining <mptcp_add_addr_len (family, *echo, port)) { +if (!*drop_other_suboptions) + goto out_unlock; + +if (!*echo) + skip_add_addr = true; + goto drop_signal_mark; + } + ret = true; +drop_signal_mark: +WRITE_ONCE (msk->pm.addr_signal, add_addr); + out_unlock:spin_unlock_bh (&msk->pm.lock); + +/* On pure-ACK option-space exhaustion, stop retrying this ADD_ADDR: +* clear the signal bit, cancel the matching retransmission timer, and +* let the PM state machine progress. +*/ +if (skip_add_addr) { +mptcp_pm_del_add_timer (msk, addr, true); +mptcp_pm_subflow_established (msk); + }return ret; }
net/mptcp/pm_netlink.c +13 -3
@@ -348,7 +348,13 @@ static void mptcp_pm_add_timer(struct tispin_lock_bh (&msk->pm.lock); -if (!mptcp_pm_should_add_signal_addr (msk)) { +/* The cancel path (mptcp_pm_del_add_timer()) can race with this +* callback. Once cancel updates retrans_times to MAX, suppress further +* retransmissions here. If this callback acquires pm.lock first, one +* final transmit attempt is still possible. +*/ +if (entry->retrans_times <ADD_ADDR_RETRANS_MAX && + !mptcp_pm_should_add_signal_addr (msk)) {pr_debug ("retransmit ADD_ADDR id=%d\n" , entry->addr.id);mptcp_pm_announce_addr (msk, &entry->addr, false);mptcp_pm_add_addr_send_ack (msk);
@@ -392,8 +398,12 @@ mptcp_pm_del_add_timer(struct mptcp_sock/* Note: entry might have been removed by another thread. * We hold rcu_read_lock() to ensure it is not freed under us. */ -if (stop_timer) -sk_stop_timer_sync (sk, &entry->add_timer); +if (stop_timer) { +if (check_id) +sk_stop_timer (sk, &entry->add_timer); +else +sk_stop_timer_sync (sk, &entry->add_timer); + }rcu_read_unlock ();return entry;
Greg Kroah-Hartman
maintainerPATCH 354/411 selftests: mptcp: drop nanoseconds width specifier
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit 01ff78e4b3d98689184c52d97f9575dfbdc3b10f ]
Using the format specifier +%s%3N with GNU date is honoured, and only prints 3 digits of the nanoseconds portion of the seconds since epoch, which corresponds to the milliseconds.
The uutils implementation of date currently does not honour this, and always prints all 9 digits. This is a known issue [1], but can be worked around by adapting this test to use nanoseconds instead of microseconds, and then divide it by 1e6.
This fix is similar to what has been done on systemd side [2], and it is needed to run the selftests on Ubuntu 26.04, containing uutils 0.8.0.
Note that the Fixes tag is there even if this patch doesn't fix an issue in the kernel selftests, but it is useful for those using uutils 0.8.0.
--- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +3 -3
@@ -462,7 +462,7 @@ do_transfer() wait_local_port_listen "${listener_ns}" "${port}" local start - start=$(date +%s%3N) + start=$(date +%s%N) timeout ${timeout_test} \ ip netns exec ${connector_ns} \ ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
@@ -475,7 +475,7 @@ do_transfer() local rets=$? local stop - stop=$(date +%s%3N) + stop=$(date +%s%N) if $capture; then sleep 1
@@ -491,7 +491,7 @@ do_transfer() fi local duration - duration=$((stop-start)) + duration=$(((stop-start) / 1000000)) printf "(duration %05sms) " "${duration}" if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then echo "[ FAIL ] client exit code $retc, server $rets" 1>&2
Greg Kroah-Hartman
maintainerPATCH 355/411 mptcp: do not drop partial packets
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shardul Bankar <[email protected]>
[ Upstream commit 50c2d91c5dfa0e465826ec1f8dbad9cdc254bd85 ]
When a packet arrives with map_seq < ack_seq < end_seq, the beginning of the packet has already been acknowledged but the end contains new data. Currently the entire packet is dropped as "old data," forcing the sender to retransmit.
Instead, skip the already-acked bytes by adjusting the skb offset and enqueue only the new portion. Update bytes_received and ack_seq to reflect the new data consumed.
A previous attempt at this fix has been sent by Paolo Abeni [1], but had issues [2]: it also added a zero-window check and changed rcv_wnd_sent initialization, which caused test regressions. This version addresses only the partial packet handling without modifying receive window accounting.
--- net/mptcp/protocol.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +19 -3
@@ -329,10 +329,26 @@ static bool __mptcp_move_skb(struct mptcreturn false; } -/* old data, keep it simple and drop the whole pkt, sender -* will retransmit as needed, if needed. +/* Completely old data? */ +if (!after64 (MPTCP_SKB_CB (skb)->end_seq, msk->ack_seq)) { +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_DUPDATA ); +mptcp_drop (sk, skb); +return false; + } + +/* Partial packet: map_seq < ack_seq < end_seq. +* Skip the already-acked bytes and enqueue the new data. */ -MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_DUPDATA ); + copy_len =MPTCP_SKB_CB (skb)->end_seq - msk->ack_seq; +MPTCP_SKB_CB (skb)->offset += msk->ack_seq -MPTCP_SKB_CB (skb)->map_seq; +MPTCP_SKB_CB (skb)->map_seq += msk->ack_seq - +MPTCP_SKB_CB (skb)->map_seq; +WRITE_ONCE (msk->ack_seq, msk->ack_seq + copy_len); + +skb_set_owner_r (skb, sk); +__skb_queue_tail (&sk->sk_receive_queue, skb); +return true; + drop:mptcp_drop (sk, skb);return false;
Greg Kroah-Hartman
maintainerPATCH 356/411 octeontx2-af: CGX: add bounds check to cgx_speed_mbps index
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sam Daly <[email protected]>
[ Upstream commit c0bf0a4f3f1f5f57aa83e1400ba4f56f0abfd542 ]
cgx_speed_mbps has 13 elements but RESP_LINKSTAT_SPEED can yield values 0-15. If it returns a value >= 13, this causes an out-of-bounds array access. Add a bounds check and default to speed 0 if the index is out of range.
--- drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +4 -1
@@ -1096,10 +1096,13 @@ static inline void link_status_user_form struct cgx *cgx, u8 lmac_id) {const char *lmac_string; +unsigned int speed; linfo->link_up =FIELD_GET (RESP_LINKSTAT_UP , lstat); linfo->full_duplex =FIELD_GET (RESP_LINKSTAT_FDUPLEX , lstat); - linfo->speed = cgx_speed_mbps[FIELD_GET (RESP_LINKSTAT_SPEED , lstat)]; + speed =FIELD_GET (RESP_LINKSTAT_SPEED , lstat); + linfo->speed = speed <ARRAY_SIZE (cgx_speed_mbps) ? + cgx_speed_mbps[speed] :0 ; linfo->an =FIELD_GET (RESP_LINKSTAT_AN , lstat); linfo->fec =FIELD_GET (RESP_LINKSTAT_FEC , lstat); linfo->lmac_type_id =cgx_get_lmac_type (cgx, lmac_id);
Greg Kroah-Hartman
maintainerPATCH 357/411 octeontx2-pf: avoid double free of pool->stack on AQ init failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawei Feng <[email protected]>
[ Upstream commit 9b244c242bec48b37e82b89787afd6a4c43457e1 ]
otx2_pool_aq_init() frees pool->stack when mailbox sync or retry allocation fails, but leaves the pointer unchanged. Later, otx2_sq_aura_pool_init() unwinds the partial setup through otx2_aura_pool_free(), which frees pool->stack again. The CN20K-specific cn20k_pool_aq_init() implementation has the same bug in
its corresponding error path.
Set pool->stack to NULL immediately after the local free so the shared cleanup path does not free the same stack again while cleaning up partially initialized pool state.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1-rc3.
Runtime validation was not performed because reproducing this path requires OcteonTX2/CN20K hardware.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +2 -0
@@ -1258,11 +1258,13 @@ static int otx2_pool_init(struct otx2_ni err =otx2_sync_mbox_msg (&pfvf->mbox);if (err) {qmem_free (pfvf->dev, pool->stack); + pool->stack =NULL ;return err; } aq =otx2_mbox_alloc_msg_npa_aq_enq (&pfvf->mbox);if (!aq) {qmem_free (pfvf->dev, pool->stack); + pool->stack =NULL ;return -ENOMEM ; } }
Greg Kroah-Hartman
maintainerPATCH 358/411 spi: qup: switch to use modern name
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Yingliang <[email protected]>
[ Upstream commit 597442ff4f6226206b7cc28b86eb2be0ae9c6418 ]
Change legacy name master to modern name host or controller.
No functional changed.
Stable-dep-of: a7e8f3efd50a ("spi: qup: fix error pointer deref after DMA setup failure")
--- drivers/spi/spi-qup.c | 164 +++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 82 deletions(-)
drivers/spi/spi-qup.c +82 -82
@@ -386,20 +386,20 @@ static void spi_qup_write(struct spi_qup }while (remainder); } -static int spi_qup_prep_sg (struct spi_master *master,struct scatterlist *sgl, +static int spi_qup_prep_sg (struct spi_controller *host,struct scatterlist *sgl,unsigned int nents,enum dma_transfer_direction dir,dma_async_tx_callback callback) { -struct spi_qup *qup =spi_master_get_devdata (master); +struct spi_qup *qup =spi_controller_get_devdata (host);unsigned long flags =DMA_PREP_INTERRUPT |DMA_PREP_FENCE ;struct dma_async_tx_descriptor *desc;struct dma_chan *chan;dma_cookie_t cookie;if (dir ==DMA_MEM_TO_DEV ) - chan = master->dma_tx; + chan = host->dma_tx;else - chan = master->dma_rx; + chan = host->dma_rx; desc =dmaengine_prep_slave_sg (chan, sgl, nents, dir, flags);if (IS_ERR_OR_NULL (desc))
@@ -413,13 +413,13 @@ static int spi_qup_prep_sg(struct spi_mareturn dma_submit_error (cookie); } -static void spi_qup_dma_terminate (struct spi_master *master, +static void spi_qup_dma_terminate (struct spi_controller *host,struct spi_transfer *xfer) {if (xfer->tx_buf) -dmaengine_terminate_all (master->dma_tx); +dmaengine_terminate_all (host->dma_tx);if (xfer->rx_buf) -dmaengine_terminate_all (master->dma_rx); +dmaengine_terminate_all (host->dma_rx); } static u32 spi_qup_sgl_get_nents_len(struct scatterlist *sgl, u32 max,
@@ -446,8 +446,8 @@ static int spi_qup_do_dma(struct spi_dev unsigned long timeout) {dma_async_tx_callback rx_done =NULL , tx_done =NULL ; -struct spi_master *master = spi->master; -struct spi_qup *qup =spi_master_get_devdata (master); +struct spi_controller *host = spi->controller; +struct spi_qup *qup =spi_controller_get_devdata (host);struct scatterlist *tx_sgl, *rx_sgl;int ret;
@@ -482,20 +482,20 @@ static int spi_qup_do_dma(struct spi_devreturn ret; }if (rx_sgl) { - ret =spi_qup_prep_sg (master, rx_sgl, rx_nents, + ret =spi_qup_prep_sg (host, rx_sgl, rx_nents,DMA_DEV_TO_MEM , rx_done);if (ret)return ret; -dma_async_issue_pending (master->dma_rx); +dma_async_issue_pending (host->dma_rx); }if (tx_sgl) { - ret =spi_qup_prep_sg (master, tx_sgl, tx_nents, + ret =spi_qup_prep_sg (host, tx_sgl, tx_nents,DMA_MEM_TO_DEV , tx_done);if (ret)return ret; -dma_async_issue_pending (master->dma_tx); +dma_async_issue_pending (host->dma_tx); }if (!wait_for_completion_timeout (&qup->done, timeout))
@@ -514,8 +514,8 @@ static int spi_qup_do_dma(struct spi_devstatic int spi_qup_do_pio (struct spi_device *spi,struct spi_transfer *xfer,unsigned long timeout) { -struct spi_master *master = spi->master; -struct spi_qup *qup =spi_master_get_devdata (master); +struct spi_controller *host = spi->controller; +struct spi_qup *qup =spi_controller_get_devdata (host);int ret, n_words, iterations, offset =0 ; n_words = qup->n_words;
@@ -660,7 +660,7 @@ static irqreturn_t spi_qup_qup_irq(int i/* set clock freq ... bits per word, determine mode */ static int spi_qup_io_prep (struct spi_device *spi,struct spi_transfer *xfer) { -struct spi_qup *controller =spi_master_get_devdata (spi->master); +struct spi_qup *controller =spi_controller_get_devdata (spi->controller);int ret;if (spi->mode &SPI_LOOP && xfer->len > controller->in_fifo_sz) {
@@ -681,9 +681,9 @@ static int spi_qup_io_prep(struct spi_deif (controller->n_words <= (controller->in_fifo_sz /sizeof (u32))) controller->mode =QUP_IO_M_MODE_FIFO ; -else if (spi->master->can_dma && - spi->master->can_dma (spi->master, spi, xfer) && - spi->master->cur_msg_mapped) +else if (spi->controller->can_dma && + spi->controller->can_dma (spi->controller, spi, xfer) && + spi->controller->cur_msg_mapped) controller->mode =QUP_IO_M_MODE_BAM ;else controller->mode =QUP_IO_M_MODE_BLOCK ;
@@ -694,7 +694,7 @@ static int spi_qup_io_prep(struct spi_de/* prep qup for another spi transaction of specific type */ static int spi_qup_io_config (struct spi_device *spi,struct spi_transfer *xfer) { -struct spi_qup *controller =spi_master_get_devdata (spi->master); +struct spi_qup *controller =spi_controller_get_devdata (spi->controller);u32 config, iomode, control;unsigned long flags;
@@ -842,11 +842,11 @@ static int spi_qup_io_config(struct spi_return 0 ; } -static int spi_qup_transfer_one (struct spi_master *master, +static int spi_qup_transfer_one (struct spi_controller *host,struct spi_device *spi,struct spi_transfer *xfer) { -struct spi_qup *controller =spi_master_get_devdata (master); +struct spi_qup *controller =spi_controller_get_devdata (host);unsigned long timeout, flags;int ret;
@@ -880,21 +880,21 @@ static int spi_qup_transfer_one(struct sspin_unlock_irqrestore (&controller->lock, flags);if (ret &&spi_qup_is_dma_xfer (controller->mode)) -spi_qup_dma_terminate (master, xfer); +spi_qup_dma_terminate (host, xfer);return ret; } -static bool spi_qup_can_dma (struct spi_master *master,struct spi_device *spi, +static bool spi_qup_can_dma (struct spi_controller *host,struct spi_device *spi,struct spi_transfer *xfer) { -struct spi_qup *qup =spi_master_get_devdata (master); +struct spi_qup *qup =spi_controller_get_devdata (host);size_t dma_align =dma_get_cache_alignment ();int n_words;if (xfer->rx_buf) {if (!IS_ALIGNED ((size_t )xfer->rx_buf, dma_align) || -IS_ERR_OR_NULL (master->dma_rx)) +IS_ERR_OR_NULL (host->dma_rx))return false;if (qup->qup_v1 && (xfer->len % qup->in_blk_sz))return false;
@@ -902,7 +902,7 @@ static bool spi_qup_can_dma(struct spi_mif (xfer->tx_buf) {if (!IS_ALIGNED ((size_t )xfer->tx_buf, dma_align) || -IS_ERR_OR_NULL (master->dma_tx)) +IS_ERR_OR_NULL (host->dma_tx))return false;if (qup->qup_v1 && (xfer->len % qup->out_blk_sz))return false;
@@ -915,30 +915,30 @@ static bool spi_qup_can_dma(struct spi_mreturn true; } -static void spi_qup_release_dma (struct spi_master *master) +static void spi_qup_release_dma (struct spi_controller *host) { -if (!IS_ERR_OR_NULL (master->dma_rx)) -dma_release_channel (master->dma_rx); -if (!IS_ERR_OR_NULL (master->dma_tx)) -dma_release_channel (master->dma_tx); +if (!IS_ERR_OR_NULL (host->dma_rx)) +dma_release_channel (host->dma_rx); +if (!IS_ERR_OR_NULL (host->dma_tx)) +dma_release_channel (host->dma_tx); } -static int spi_qup_init_dma (struct spi_master *master,resource_size_t base) +static int spi_qup_init_dma (struct spi_controller *host,resource_size_t base) { -struct spi_qup *spi =spi_master_get_devdata (master); +struct spi_qup *spi =spi_controller_get_devdata (host);struct dma_slave_config *rx_conf = &spi->rx_conf, *tx_conf = &spi->tx_conf;struct device *dev = spi->dev;int ret;/* allocate dma resources, if available */ - master->dma_rx =dma_request_chan (dev,"rx" ); -if (IS_ERR (master->dma_rx)) -return PTR_ERR (master->dma_rx); - - master->dma_tx =dma_request_chan (dev,"tx" ); -if (IS_ERR (master->dma_tx)) { - ret =PTR_ERR (master->dma_tx); + host->dma_rx =dma_request_chan (dev,"rx" ); +if (IS_ERR (host->dma_rx)) +return PTR_ERR (host->dma_rx); + + host->dma_tx =dma_request_chan (dev,"tx" ); +if (IS_ERR (host->dma_tx)) { + ret =PTR_ERR (host->dma_tx); goto err_tx; }
@@ -953,13 +953,13 @@ static int spi_qup_init_dma(struct spi_m tx_conf->dst_addr = base +QUP_OUTPUT_FIFO ; tx_conf->dst_maxburst = spi->out_blk_sz; - ret =dmaengine_slave_config (master->dma_rx, rx_conf); + ret =dmaengine_slave_config (host->dma_rx, rx_conf);if (ret) {dev_err (dev,"failed to configure RX channel\n" ); goto err; } - ret =dmaengine_slave_config (master->dma_tx, tx_conf); + ret =dmaengine_slave_config (host->dma_tx, tx_conf);if (ret) {dev_err (dev,"failed to configure TX channel\n" ); goto err;
@@ -968,9 +968,9 @@ static int spi_qup_init_dma(struct spi_mreturn 0 ; err: -dma_release_channel (master->dma_tx); +dma_release_channel (host->dma_tx); err_tx: -dma_release_channel (master->dma_rx); +dma_release_channel (host->dma_rx);return ret; }
@@ -980,7 +980,7 @@ static void spi_qup_set_cs(struct spi_deu32 spi_ioc;u32 spi_ioc_orig; - controller =spi_master_get_devdata (spi->master); + controller =spi_controller_get_devdata (spi->controller); spi_ioc =readl_relaxed (controller->base +SPI_IO_CONTROL ); spi_ioc_orig = spi_ioc;if (!val)
@@ -994,7 +994,7 @@ static void spi_qup_set_cs(struct spi_destatic int spi_qup_probe (struct platform_device *pdev) { -struct spi_master *master; +struct spi_controller *host;struct clk *iclk, *cclk;struct spi_qup *controller;struct resource *res;
@@ -1030,32 +1030,32 @@ static int spi_qup_probe(struct platformreturn -ENXIO ; } - master =spi_alloc_master (dev,sizeof (struct spi_qup )); -if (!master) { -dev_err (dev,"cannot allocate master\n" ); + host =spi_alloc_master (dev,sizeof (struct spi_qup )); +if (!host) { +dev_err (dev,"cannot allocate host\n" );return -ENOMEM ; }/* use num-cs unless not present or out of range */ if (of_property_read_u32 (dev->of_node,"num-cs" , &num_cs) || num_cs >SPI_NUM_CHIPSELECTS ) - master->num_chipselect =SPI_NUM_CHIPSELECTS ; + host->num_chipselect =SPI_NUM_CHIPSELECTS ;else - master->num_chipselect = num_cs; + host->num_chipselect = num_cs; - master->bus_num = pdev->id; - master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH |SPI_LOOP ; - master->bits_per_word_mask =SPI_BPW_RANGE_MASK (4 ,32 ); - master->max_speed_hz = max_freq; - master->transfer_one = spi_qup_transfer_one; - master->dev.of_node = pdev->dev.of_node; - master->auto_runtime_pm = true; - master->dma_alignment =dma_get_cache_alignment (); - master->max_dma_len =SPI_MAX_XFER ; + host->bus_num = pdev->id; + host->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH |SPI_LOOP ; + host->bits_per_word_mask =SPI_BPW_RANGE_MASK (4 ,32 ); + host->max_speed_hz = max_freq; + host->transfer_one = spi_qup_transfer_one; + host->dev.of_node = pdev->dev.of_node; + host->auto_runtime_pm = true; + host->dma_alignment =dma_get_cache_alignment (); + host->max_dma_len =SPI_MAX_XFER ; -platform_set_drvdata (pdev, master); +platform_set_drvdata (pdev, host); - controller =spi_master_get_devdata (master); + controller =spi_controller_get_devdata (host); controller->dev = dev; controller->base = base;
@@ -1063,16 +1063,16 @@ static int spi_qup_probe(struct platform controller->cclk = cclk; controller->irq = irq; - ret =spi_qup_init_dma (master, res->start); + ret =spi_qup_init_dma (host, res->start);if (ret == -EPROBE_DEFER ) goto error;else if (!ret) - master->can_dma = spi_qup_can_dma; + host->can_dma = spi_qup_can_dma; controller->qup_v1 = (uintptr_t )of_device_get_match_data (dev);if (!controller->qup_v1) - master->set_cs = spi_qup_set_cs; + host->set_cs = spi_qup_set_cs;spin_lock_init (&controller->lock);init_completion (&controller->done);
@@ -1150,7 +1150,7 @@ static int spi_qup_probe(struct platformpm_runtime_set_active (dev);pm_runtime_enable (dev); - ret =devm_spi_register_master (dev, master); + ret =devm_spi_register_controller (dev, host);if (ret) goto disable_pm;
@@ -1162,17 +1162,17 @@ error_clk:clk_disable_unprepare (cclk);clk_disable_unprepare (iclk); error_dma: -spi_qup_release_dma (master); +spi_qup_release_dma (host); error: -spi_master_put (master); +spi_controller_put (host);return ret; }#ifdef CONFIG_PM static int spi_qup_pm_suspend_runtime (struct device *device) { -struct spi_master *master =dev_get_drvdata (device); -struct spi_qup *controller =spi_master_get_devdata (master); +struct spi_controller *host =dev_get_drvdata (device); +struct spi_qup *controller =spi_controller_get_devdata (host);u32 config;/* Enable clocks auto gaiting */
@@ -1188,8 +1188,8 @@ static int spi_qup_pm_suspend_runtime(ststatic int spi_qup_pm_resume_runtime (struct device *device) { -struct spi_master *master =dev_get_drvdata (device); -struct spi_qup *controller =spi_master_get_devdata (master); +struct spi_controller *host =dev_get_drvdata (device); +struct spi_qup *controller =spi_controller_get_devdata (host);u32 config;int ret;
@@ -1214,8 +1214,8 @@ static int spi_qup_pm_resume_runtime(str#ifdef CONFIG_PM_SLEEP static int spi_qup_suspend (struct device *device) { -struct spi_master *master =dev_get_drvdata (device); -struct spi_qup *controller =spi_master_get_devdata (master); +struct spi_controller *host =dev_get_drvdata (device); +struct spi_qup *controller =spi_controller_get_devdata (host);int ret;if (pm_runtime_suspended (device)) {
@@ -1223,7 +1223,7 @@ static int spi_qup_suspend(struct deviceif (ret)return ret; } - ret =spi_master_suspend (master); + ret =spi_controller_suspend (host);if (ret)return ret;
@@ -1238,8 +1238,8 @@ static int spi_qup_suspend(struct devicestatic int spi_qup_resume (struct device *device) { -struct spi_master *master =dev_get_drvdata (device); -struct spi_qup *controller =spi_master_get_devdata (master); +struct spi_controller *host =dev_get_drvdata (device); +struct spi_qup *controller =spi_controller_get_devdata (host);int ret; ret =clk_prepare_enable (controller->iclk);
@@ -1256,7 +1256,7 @@ static int spi_qup_resume(struct deviceif (ret) goto disable_clk; - ret =spi_master_resume (master); + ret =spi_controller_resume (host);if (ret) goto disable_clk;
@@ -1271,8 +1271,8 @@ disable_clk:static int spi_qup_remove (struct platform_device *pdev) { -struct spi_master *master =dev_get_drvdata (&pdev->dev); -struct spi_qup *controller =spi_master_get_devdata (master); +struct spi_controller *host =dev_get_drvdata (&pdev->dev); +struct spi_qup *controller =spi_controller_get_devdata (host);int ret; ret =pm_runtime_get_sync (&pdev->dev);
@@ -1290,7 +1290,7 @@ static int spi_qup_remove(struct platfor ERR_PTR(ret)); } -spi_qup_release_dma (master); +spi_qup_release_dma (host);pm_runtime_put_noidle (&pdev->dev);pm_runtime_disable (&pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 359/411 spi: qup: fix error pointer deref after DMA setup failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit a7e8f3efd50a165ba0189f6dc57f7e51a7d149db ]
The driver falls back to PIO mode if DMA setup fails during probe.
Make sure to the clear the DMA channel pointers on setup failure to avoid dereferencing an error pointer (or attempting to release a channel a second time) on later probe errors or driver unbind.
This issue was flagged by Sashiko when reviewing a devres allocation conversion patch.
--- drivers/spi/spi-qup.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/spi/spi-qup.c +3 -0
@@ -969,8 +969,11 @@ static int spi_qup_init_dma(struct spi_c err:dma_release_channel (host->dma_tx); + host->dma_tx =NULL ; err_tx:dma_release_channel (host->dma_rx); + host->dma_rx =NULL ; +return ret; }
Greg Kroah-Hartman
maintainerPATCH 360/411 arm64: tlb: Flush walk cache when unsharing PMD tables
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zeng Heng <[email protected]>
[ Upstream commit c2ff4764e03e7a8d758352f4aceb8fe1be6ac971 ]
When huge_pmd_unshare() is called to unshare a PMD table, the tlb_unshare_pmd_ptdesc() function sets tlb->unshared_tables=true but the aarch64 tlb_flush() only checked tlb->freed_tables to determine whether to use TLBF_NONE (vae1is, invalidates walk cache) or TLBF_NOWALKCACHE (vale1is, leaf-only).
This caused the stale PMD page table entry to remain in the walk cache after unshare, potentially leading to incorrect page table walks.
Fix by including unshared_tables in the check, so that when unsharing tables, TLBF_NONE is used and the walk cache is properly invalidated.
Here is the detailed distinction between vae1is and vale1is:
| Instruction Combination | Actual Invalidation Scope | | ------------------------ | --------------------------------------------------| | `VAE1IS` + TTL=`0` | All entries at all levels (full invalidation) | | `VAE1IS` + TTL=`2` (L2) | Non-leaf at Level 0/1 + leaf at Level 2 | | `VALE1IS` + TTL=`0` | Leaf entries at all levels (non-leaf not cleared) | | `VALE1IS` + TTL=`2` (L2) | Leaf entry at Level 2 only |
--- arch/arm64/include/asm/tlb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/tlb.h +1 -1
@@ -53,7 +53,7 @@ static inline int tlb_get_level(struct mstatic inline void tlb_flush (struct mmu_gather *tlb) {struct vm_area_struct vma =TLB_FLUSH_VMA (tlb->mm,0 ); -bool last_level = !tlb->freed_tables; +bool last_level = !(tlb->freed_tables || tlb->unshared_tables);unsigned long stride =tlb_get_unmap_size (tlb);int tlb_level =tlb_get_level (tlb);
Greg Kroah-Hartman
maintainerPATCH 361/411 phy: tegra: xusb: Disable trk clk when not in use
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wayne Chang <[email protected]>
[ Upstream commit 71d9e899584e11bbd7eaf9934a619c69a15060d8 ]
Pad tracking is a one-time calibration for Tegra186 and Tegra194. Clk should be disabled after calibration.
Disable clk after calibration.
While at it add 100us delay for HW recording the calibration value.
Stable-dep-of: da110228b54f ("phy: tegra: xusb: Fix per-pad high-speed termination calibration")
--- drivers/phy/tegra/xusb-tegra186.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/phy/tegra/xusb-tegra186.c +4 -2
@@ -612,6 +612,10 @@ static void tegra186_utmi_bias_pad_power value &= ~USB2_PD_TRK ;padctl_writel (padctl, value,XUSB_PADCTL_USB2_BIAS_PAD_CTL1 ); +udelay (100 ); + +clk_disable_unprepare (priv->usb2_trk_clk); +mutex_unlock (&padctl->lock); }
@@ -636,8 +640,6 @@ static void tegra186_utmi_bias_pad_power value |=USB2_PD_TRK ;padctl_writel (padctl, value,XUSB_PADCTL_USB2_BIAS_PAD_CTL1 ); -clk_disable_unprepare (priv->usb2_trk_clk); -mutex_unlock (&padctl->lock); }
Greg Kroah-Hartman
maintainerPATCH 362/411 phy: tegra: xusb: Fix per-pad high-speed termination calibration
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wayne Chang <[email protected]>
[ Upstream commit da110228b54f2e2143d97ea7151e0dc22e539d67 ]
The existing code reads a single hs_term_range_adj value from bit field [10:7] of FUSE_SKU_CALIB_0 and applies it to all USB2 pads uniformly. However, on SoCs that support per-pad termination, each pad has its own hs_term_range_adj field: pad 0 in FUSE_SKU_CALIB_0[10:7], and pads 1-3 in FUSE_USB_CALIB_EXT_0 at bit offsets [8:5], [12:9], and [16:13] respectively.
Fix the calibration by reading per-pad values from the appropriate fuse registers. For SoCs that do not support per-pad termination, replicate pad 0's value to all pads to maintain existing behavior.
Add a has_per_pad_term flag to the SoC data to indicate whether per-pad termination values are available in FUSE_USB_CALIB_EXT_0.
--- drivers/phy/tegra/xusb-tegra186.c | 32 +++++++++++++++++++++++++------- drivers/phy/tegra/xusb.h | 1 + 2 files changed, 26 insertions(+), 7 deletions(-)
drivers/phy/tegra/xusb-tegra186.c +25 -7
@@ -20,8 +20,8 @@/* FUSE USB_CALIB registers */ #define HS_CURR_LEVEL_PADX_SHIFT (x) ((x) ? (11 + (x - 1) * 6) : 0)#define HS_CURR_LEVEL_PAD_MASK 0x3f -#define HS_TERM_RANGE_ADJ_SHIFT 7 -#define HS_TERM_RANGE_ADJ_MASK 0xf +#define HS_TERM_RANGE_ADJ_PADX_SHIFT (x) ((x) ? (5 + (x - 1) * 4) : 7) +#define HS_TERM_RANGE_ADJ_PAD_MASK 0xf#define HS_SQUELCH_SHIFT 29#define HS_SQUELCH_MASK 0x7
@@ -238,7 +238,7 @@struct tegra_xusb_fuse_calibration {u32 *hs_curr_level;u32 hs_squelch; -u32 hs_term_range_adj; +u32 *hs_term_range_adj;u32 rpd_ctrl; };
@@ -864,7 +864,7 @@ static int tegra186_utmi_phy_power_on(st value =padctl_readl (padctl,XUSB_PADCTL_USB2_OTG_PADX_CTL1 (index)); value &= ~TERM_RANGE_ADJ (~0 ); - value |=TERM_RANGE_ADJ (priv->calib.hs_term_range_adj); + value |=TERM_RANGE_ADJ (priv->calib.hs_term_range_adj[index]); value &= ~RPD_CTRL (~0 ); value |=RPD_CTRL (priv->calib.rpd_ctrl);padctl_writel (padctl, value,XUSB_PADCTL_USB2_OTG_PADX_CTL1 (index));
@@ -1400,17 +1400,23 @@ static const char * const tegra186_usb3_static int tegra186_xusb_read_fuse_calibration (struct tegra186_xusb_padctl *padctl) { +const struct tegra_xusb_padctl_soc *soc = padctl->base.soc;struct device *dev = padctl->base.dev;unsigned int i, count;u32 value, *level; +u32 *hs_term_range_adj;int err; - count = padctl->base.soc->ports.usb2.count; + count = soc->ports.usb2.count; level =devm_kcalloc (dev, count,sizeof (u32),GFP_KERNEL );if (!level)return -ENOMEM ; + hs_term_range_adj =devm_kcalloc (dev, count,sizeof (u32),GFP_KERNEL ); +if (!hs_term_range_adj) +return -ENOMEM ; + err =tegra_fuse_readl (TEGRA_FUSE_SKU_CALIB_0 , &value);if (err) {if (err != -EPROBE_DEFER )
@@ -1429,8 +1435,8 @@ tegra186_xusb_read_fuse_calibration(stru padctl->calib.hs_squelch = (value >>HS_SQUELCH_SHIFT ) &HS_SQUELCH_MASK ; - padctl->calib.hs_term_range_adj = (value >>HS_TERM_RANGE_ADJ_SHIFT ) & -HS_TERM_RANGE_ADJ_MASK ; + hs_term_range_adj[0 ] = (value >>HS_TERM_RANGE_ADJ_PADX_SHIFT (0 )) & +HS_TERM_RANGE_ADJ_PAD_MASK ; err =tegra_fuse_readl (TEGRA_FUSE_USB_CALIB_EXT_0 , &value);if (err) {
@@ -1442,6 +1448,17 @@ tegra186_xusb_read_fuse_calibration(stru padctl->calib.rpd_ctrl = (value >>RPD_CTRL_SHIFT ) &RPD_CTRL_MASK ; +for (i =1 ; i < count; i++) { +if (soc->has_per_pad_term) + hs_term_range_adj[i] = + (value >>HS_TERM_RANGE_ADJ_PADX_SHIFT (i)) & +HS_TERM_RANGE_ADJ_PAD_MASK ; +else + hs_term_range_adj[i] = hs_term_range_adj[0 ]; + } + + padctl->calib.hs_term_range_adj = hs_term_range_adj; +return 0 ; }
@@ -1643,6 +1660,7 @@ const struct tegra_xusb_padctl_soc tegra .supply_names = tegra194_xusb_padctl_supply_names, .num_supplies = ARRAY_SIZE(tegra194_xusb_padctl_supply_names), .supports_gen2 = true, + .has_per_pad_term = true, };EXPORT_SYMBOL_GPL (tegra194_xusb_padctl_soc);#endif
drivers/phy/tegra/xusb.h +1 -0
@@ -431,6 +431,7 @@ struct tegra_xusb_padctl_soc {unsigned int num_supplies;bool supports_gen2;bool need_fake_usb3_port; +bool has_per_pad_term; };struct tegra_xusb_padctl {
Greg Kroah-Hartman
maintainerPATCH 363/411 Bluetooth: L2CAP: use chan timer to close channels in cleanup_listen()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Siwei Zhang <[email protected]>
[ Upstream commit 8c8e620467a7b51562dbcefbd1f09f288d7d710d ]
l2cap_chan_close() removes the channel from conn->chan_l, which must be done under conn->lock. cleanup_listen() runs under the parent sk_lock, so acquiring conn->lock would invert the established conn->lock -> chan->lock -> sk_lock order.
Instead of calling l2cap_chan_close() directly, schedule l2cap_chan_timeout with delay 0 to close the channel asynchronously. The timeout handler already acquires conn->lock and chan->lock in the correct order.
The timer is only armed when chan->conn is still set: if it is already NULL, l2cap_conn_del() has already processed this channel (l2cap_chan_del + l2cap_sock_teardown_cb + l2cap_sock_close_cb), so there is nothing left to do. If l2cap_conn_del() races in after the timer is armed, __clear_chan_timer() inside l2cap_chan_del() cancels it; if the timer has already fired, the handler returns harmlessly because chan->conn was cleared.
--- net/bluetooth/l2cap_sock.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/bluetooth/l2cap_sock.c +9 -7
@@ -1449,6 +1449,10 @@ static void l2cap_sock_cleanup_listen(st* pin it (hold_unless_zero() additionally skips a chan already past * its last reference). We then drop the sk lock before taking * chan->lock, so sk and chan locks are never held together. +* +* Since we cannot call l2cap_chan_close() without conn->lock, +* schedule l2cap_chan_timeout to close the channel; it already +* acquires conn->lock -> chan->lock in the correct order. */ while ((sk =bt_accept_dequeue (parent,NULL ))) {struct l2cap_chan *chan;
@@ -1466,14 +1470,12 @@ static void l2cap_sock_cleanup_listen(st state_to_string(chan->state));l2cap_chan_lock (chan); -__clear_chan_timer (chan); -l2cap_chan_close (chan,ECONNRESET ); -/* l2cap_conn_del() may already have killed this socket -* (it sets SOCK_DEAD); skip the duplicate to avoid a -* double sock_put()/l2cap_chan_put(). +/* Since we cannot call l2cap_chan_close() without +* conn->lock, schedule its timer to trigger the close +* and cleanup of this channel. */ -if (!sock_flag (sk,SOCK_DEAD )) -l2cap_sock_kill (sk); +if (chan->conn) +__set_chan_timer (chan,0 );l2cap_chan_unlock (chan);l2cap_chan_put (chan);
Greg Kroah-Hartman
maintainerPATCH 364/411 iio: gyro: adis16260: fix division by zero in write_raw
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
[ Upstream commit 761e8b489e6cf166c574034b70637f8a7eadd0ee ]
Add a validation check for the sampling frequency value before using it as a divisor. A user writing zero to the sampling_frequency sysfs attribute triggers a division by zero in the kernel.
--- drivers/iio/gyro/adis16260.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/gyro/adis16260.c +3 -0
@@ -288,6 +288,9 @@ static int adis16260_write_raw(struct ii addr = adis16260_addresses[chan->scan_index][1 ];return adis_write_reg_16 (adis, addr, val);case IIO_CHAN_INFO_SAMP_FREQ : +if (val <=0 ) +return -EINVAL ; +adis_dev_lock (adis);if (spi_get_device_id (adis->spi)->driver_data) t =256 / val;
Greg Kroah-Hartman
maintainerPATCH 365/411 iio: chemical: scd30: Use guard(mutex) to allow early returns
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonathan Cameron <[email protected]>
[ Upstream commit 5feb5532870fbced5d6f450b8061a33f461b88ca ]
Auto cleanup based release of the lock allows for simpler code flow in a few functions with large multiplexing style switch statements and no common operations following the switch.
Stable-dep-of: 5aba4f94b225 ("iio: chemical: scd30: fix division by zero in write_raw")
--- drivers/iio/chemical/scd30_core.c | 63 ++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 35 deletions(-)
drivers/iio/chemical/scd30_core.c +28 -35
@@ -5,6 +5,7 @@* Copyright (c) 2020 Tomasz Duszynski <[email protected]> */ #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/completion.h> #include <linux/delay.h> #include <linux/device.h>
@@ -198,112 +199,104 @@ static int scd30_read_raw(struct iio_dev int *val, int *val2, long mask) { struct scd30_state *state = iio_priv(indio_dev); -int ret = -EINVAL ; +int ret;u16 tmp; -mutex_lock (&state->lock); +guard (mutex)(&state->lock);switch (mask) {case IIO_CHAN_INFO_RAW :case IIO_CHAN_INFO_PROCESSED :if (chan->output) { *val = state->pressure_comp; - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ; } ret =iio_device_claim_direct_mode (indio_dev);if (ret) -break ; +return ret; ret =scd30_read (state);if (ret) {iio_device_release_direct_mode (indio_dev); -break ; +return ret; } *val = state->meas[chan->address];iio_device_release_direct_mode (indio_dev); - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : *val =0 ; *val2 =1 ; - ret =IIO_VAL_INT_PLUS_MICRO ; -break ; +return IIO_VAL_INT_PLUS_MICRO ;case IIO_CHAN_INFO_SAMP_FREQ : ret =scd30_command_read (state,CMD_MEAS_INTERVAL , &tmp);if (ret) -break ; +return ret; *val =0 ; *val2 =1000000000 / tmp; - ret =IIO_VAL_INT_PLUS_NANO ; -break ; +return IIO_VAL_INT_PLUS_NANO ;case IIO_CHAN_INFO_CALIBBIAS : ret =scd30_command_read (state,CMD_TEMP_OFFSET , &tmp);if (ret) -break ; +return ret; *val = tmp; - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ; +default : +return -EINVAL ; } -mutex_unlock (&state->lock); - -return ret; }static int scd30_write_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int val,int val2,long mask) {struct scd30_state *state =iio_priv (indio_dev); -int ret = -EINVAL ; +int ret; -mutex_lock (&state->lock); +guard (mutex)(&state->lock);switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ :if (val) -break ; +return -EINVAL ; val =1000000000 / val2;if (val <SCD30_MEAS_INTERVAL_MIN_S || val >SCD30_MEAS_INTERVAL_MAX_S ) -break ; +return -EINVAL ; ret =scd30_command_write (state,CMD_MEAS_INTERVAL , val);if (ret) -break ; +return ret; state->meas_interval = val; -break ; +return 0 ;case IIO_CHAN_INFO_RAW :switch (chan->type) {case IIO_PRESSURE :if (val <SCD30_PRESSURE_COMP_MIN_MBAR || val >SCD30_PRESSURE_COMP_MAX_MBAR ) -break ; +return -EINVAL ; ret =scd30_command_write (state,CMD_START_MEAS , val);if (ret) -break ; +return ret; state->pressure_comp = val; -break ; +return 0 ;default : -break ; +return -EINVAL ; } -break ;case IIO_CHAN_INFO_CALIBBIAS :if (val <0 || val >SCD30_TEMP_OFFSET_MAX ) -break ; +return -EINVAL ;/* * Manufacturer does not explicitly specify min/max sensible * values hence check is omitted for simplicity. */ - ret =scd30_command_write (state,CMD_TEMP_OFFSET /10 , val); +return scd30_command_write (state,CMD_TEMP_OFFSET /10 , val); +default : +return -EINVAL ; } -mutex_unlock (&state->lock); - -return ret; } static int scd30_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
Greg Kroah-Hartman
maintainerPATCH 366/411 iio: chemical: scd30: fix division by zero in write_raw
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
[ Upstream commit 5aba4f94b225617a55fed442a70329b2ee19c0a5 ]
Add a zero check for val2 before using it as a divisor when setting the sampling frequency. A user writing a zero fractional part to the sampling_frequency sysfs attribute triggers a division by zero in the kernel.
--- drivers/iio/chemical/scd30_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/scd30_core.c +1 -1
@@ -257,7 +257,7 @@ static int scd30_write_raw(struct iio_deguard (mutex)(&state->lock);switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ : -if (val) +if (val || !val2)return -EINVAL ; val =1000000000 / val2;
Greg Kroah-Hartman
maintainerPATCH 367/411 iio: dac: ad5686: fix ref bit initialization for single-channel parts
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rodrigo Alencar <[email protected]>
[ Upstream commit ecae2ae606d493cf11457946436335bd0e726663 ]
The reference bit position was ignored when writing the register at the probe() function (!!val was used). When such bit is 1, internal voltage reference is disabled so that an external one can be used. For multi-channel devices, bit 0 of the Internal Reference Setup command behaves the same way, so AD5686_REF_BIT_MSK is created. The issue exists since support for single-channel devices were first introduced.
--- drivers/iio/dac/ad5686.c | 6 +++--- drivers/iio/dac/ad5686.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/iio/dac/ad5686.c +3 -3
@@ -513,7 +513,7 @@ int ad5686_probe(struct device *dev,break ;case AD5686_REGMAP : cmd =AD5686_CMD_INTERNAL_REFER_SETUP ; - ref_bit_msk =0 ; + ref_bit_msk =AD5686_REF_BIT_MSK ;break ;case AD5693_REGMAP : cmd =AD5686_CMD_CONTROL_REG ;
@@ -525,9 +525,9 @@ int ad5686_probe(struct device *dev, goto error_disable_reg; } - val = (voltage_uv | ref_bit_msk); + val = voltage_uv ? ref_bit_msk :0 ; - ret = st->write (st, cmd,0 , !!val); + ret = st->write (st, cmd,0 , val);if (ret) goto error_disable_reg;
drivers/iio/dac/ad5686.h +1 -0
@@ -44,6 +44,7 @@#define AD5310_REF_BIT_MSK BIT(8)#define AD5683_REF_BIT_MSK BIT(12) +#define AD5686_REF_BIT_MSK BIT(0)#define AD5693_REF_BIT_MSK BIT(12)/**
Greg Kroah-Hartman
maintainerPATCH 368/411 usb: cdns3: plat: fix leaked usb2_phy initialization on usb3_phy acquisition failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Chen <[email protected]>
[ Upstream commit e6970cda63fd4b4546aeed9d0e2f53a7c95cd09c ]
Move usb2_phy initialization after usb3_phy acquisition.
--- drivers/usb/cdns3/cdns3-plat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/cdns3/cdns3-plat.c +4 -4
@@ -120,14 +120,14 @@ static int cdns3_plat_probe(struct platfif (IS_ERR (cdns->usb2_phy))return PTR_ERR (cdns->usb2_phy); - ret =phy_init (cdns->usb2_phy); -if (ret) -return ret; - cdns->usb3_phy =devm_phy_optional_get (dev,"cdns3,usb3-phy" );if (IS_ERR (cdns->usb3_phy))return PTR_ERR (cdns->usb3_phy); + ret =phy_init (cdns->usb2_phy); +if (ret) +return ret; + ret =phy_init (cdns->usb3_phy);if (ret) goto err_phy3_init;
Greg Kroah-Hartman
maintainerPATCH 369/411 net: skbuff: fix missing zerocopy reference in pskb_carve helpers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Minh Nguyen <[email protected]>
[ Upstream commit 98d0912e9f841e5529a5b89a972805f34cb1c69d ]
pskb_carve_inside_header() and pskb_carve_inside_nonlinear() both copy the old skb_shared_info header into a new buffer via memcpy(), which includes the destructor_arg pointer (uarg) for MSG_ZEROCOPY skbs. Neither function calls net_zcopy_get() for the new shinfo, creating an unaccounted holder: every skb_shared_info with destructor_arg set will call skb_zcopy_clear() once when freed, but the corresponding net_zcopy_get() was never called for the new copy. Repeated calls drive uarg->refcnt to zero prematurely, freeing ubuf_info_msgzc while TX skbs still hold live destructor_arg pointers.
KASAN reports use-after-free on a freed ubuf_info_msgzc:
BUG: KASAN: slab-use-after-free in skb_release_data+0x77b/0x810 Read of size 8 at addr ffff88801574d3e8 by task poc/220 Call Trace: skb_release_data+0x77b/0x810 kfree_skb_list_reason+0x13e/0x610 skb_release_data+0x4cd/0x810 sk_skb_reason_drop+0xf3/0x340 skb_queue_purge_reason+0x282/0x440 rds_tcp_inc_free+0x1e/0x30 rds_recvmsg+0x354/0x1780 __sys_recvmsg+0xdf/0x180 Allocated by task 219: msg_zerocopy_realloc+0x157/0x7b0 tcp_sendmsg_locked+0x2892/0x3ba0 Freed by task 219: ip_recv_error+0x74a/0xb10 tcp_recvmsg+0x475/0x530
The skb consuming the late access still referenced the same uarg via shinfo->destructor_arg copied by pskb_carve_inside_nonlinear() without a refcount bump. This has been verified to be reliably exploitable: a working proof-of-concept achieves full root privilege escalation from an unprivileged local user on a default kernel configuration.
The fix follows the pattern of pskb_expand_head() which has the same memcpy/cloned structure. For pskb_carve_inside_header(), net_zcopy_get() is placed after skb_orphan_frags() succeeds, so the orphan error path needs no cleanup. For pskb_carve_inside_nonlinear(), net_zcopy_get() is placed after all failure points and just before skb_release_data(), so no error path needs cleanup at all -- matching pskb_expand_head() more closely and avoiding the need for a balancing net_zcopy_put().
--- net/core/skbuff.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/skbuff.c +4 -0
@@ -6256,6 +6256,8 @@ static int pskb_carve_inside_header(strukfree (data);return -ENOMEM ; } +if (skb_zcopy (skb)) +net_zcopy_get (skb_zcopy (skb));for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++)skb_frag_ref (skb, i);if (skb_has_frag_list (skb))
@@ -6404,6 +6406,8 @@ static int pskb_carve_inside_nonlinear(skfree (data);return -ENOMEM ; } +if (skb_zcopy (skb)) +net_zcopy_get (skb_zcopy (skb));skb_release_data (skb); skb->head = data;