6.1.193-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 1230/2857 mm/memfd: make f_pos accesses atomic
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 5426cd43a4d28f1041c9ca45955121b921f29548 ]
Commit 9c225f2655e3 ("vfs: atomic f_pos accesses as per POSIX") made read(), write() and lseek() on a shared open file description of a regular file serialize on ->f_pos_lock. The flag that asks for it, FMODE_ATOMIC_POS, is set in do_dentry_open(). A memfd is a regular file too, but its struct file comes from alloc_file_pseudo() and never passes through do_dentry_open(), so it does not get the flag:
CPU0 CPU1
write(memfd, "a", 1) write(memfd, "b", 1)
pos = file->f_pos (= 0)
pos = file->f_pos (= 0)
vfs_write(..., &pos)
vfs_write(..., &pos)
file->f_pos = pos (= 1)
file->f_pos = pos (= 1)One of the two bytes is overwritten. Two threads writing 100000 bytes each, one at a time, to a memfd end up with a file that is far shorter than 200000 bytes, while the same program on a tmpfs file never loses a byte.
Set the flag when the memfd is created. As for any other regular file the lock is only taken if the file is reachable in more than one way, and nothing a memfd does in read or write waits for another operation on the same file. This cannot be done for all alloc_file_pseudo() files: anon inode files such as eventfd are S_IFREG as well, and a blocked read holding ->f_pos_lock would lock out the write that is supposed to wake it.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/memfd.c | 2 ++ 1 file changed, 2 insertions(+)
mm/memfd.c +2 -0
@@ -324,6 +324,8 @@ SYSCALL_DEFINE2(memfd_create, goto err_fd; } file->f_mode |=FMODE_LSEEK |FMODE_PREAD |FMODE_PWRITE ; +/* a regular file like any other: POSIX.1-2008/SUSv4 Section XSI 2.9.7 */ + file->f_mode |=FMODE_ATOMIC_POS ; file->f_flags |=O_LARGEFILE ;if (flags &MFD_ALLOW_SEALING ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1231/2857 mm/filemap: dont lose a folio lock wakeup to a signal
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 8ccb6ded6a47b59b4907ed4f8c293cf8122de889 ]
An exclusive waiter in folio_wait_bit_common() can leave the wait loop because of a fatal signal, then be woken by folio_unlock() before finish_wait(). If the waker did not hand over the lock, the waiter returns -EINTR without trying to acquire it.
folio_wake_bit() stops after waking the first exclusive waiter, so this loses the wakeup and can leave other waiters asleep indefinitely on an unlocked folio.
After finish_wait(), let a waiter woken without a lock handoff try once more to acquire the lock. If successful, return success so the caller's eventual unlock wakes the next waiter. Otherwise, the current lock owner will do so.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/filemap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
mm/filemap.c +15 -3
@@ -1370,10 +1370,22 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,* return value based on that state without races. * * Also note that WQ_FLAG_WOKEN is sufficient for a non-exclusive -* waiter, but an exclusive one requires WQ_FLAG_DONE. +* waiter, but an exclusive one must also acquire the bit. */ -if (behavior ==EXCLUSIVE ) -return wait->flags &WQ_FLAG_DONE ?0 : -EINTR ; +if (behavior ==EXCLUSIVE ) { +if (wait->flags &WQ_FLAG_DONE ) +return 0 ; +/* +* We might have just been woken up and the waker will not +* wake up anybody else. If we ignore that now, the remaining +* waiters may not get woken up: take the bit now if it is +* still free. +*/ +if ((wait->flags &WQ_FLAG_WOKEN ) && + !test_and_set_bit (bit_nr,folio_flags (folio,0 ))) +return 0 ; +return -EINTR ; + }return wait->flags &WQ_FLAG_WOKEN ?0 : -EINTR ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1232/2857 drm/v3d: Initialize timedout_batches when running a CSD job
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jose Maria Casanova Crespo <[email protected]>
[ Upstream commit 0afdbdd5b1af729108de8f893d179c3b99eac29d ]
v3d_csd_job_timedout() decides whether a compute job made progress by comparing CSD_CURRENT_CFG4, the number of batches the dispatcher still has to start, against the value saved at the previous timeout. That saved value is never initialized, so it is zero on the first timeout.
On V3D 7.1.6 and later, CFG4 counts down to zero once the dispatcher has started the last batch, but the dispatch keeps running until the batches in flight complete. If the first timeout fires in that window, the handler sees no change and resets the GPU while the job is about to complete. For example, this happens with long dispatches that only keep a single supergroup in flight.
Initialize timedout_batches to the value programmed in CFG4 when the job is started. The register does not return to it once a batch has started:
it counts down to zero on V3D 7.1.6 and later (CFG4 holds the number of batches), and to 0xffffffff on V3D 4.2 (CFG4 holds the number of batches minus one).
--- drivers/gpu/drm/v3d/v3d_sched.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/v3d/v3d_sched.c +2 -0
@@ -260,6 +260,8 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)dma_fence_put (job->base.irq_fence); job->base.irq_fence =dma_fence_get (fence); + job->timedout_batches = job->args.cfg[4 ]; +trace_v3d_submit_csd (dev,to_v3d_fence (fence)->seqno);v3d_switch_perfmon (v3d, &job->base);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1233/2857 vhost-vdpa: fix pinned page leak in vhost_vdpa_pa_map() error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit fd1462c96bafe2cb14e88c837b270f8990b717b5 ]
When pin_user_pages() or vhost_vdpa_map() fails, vhost_vdpa_pa_map() is supposed to unpin the pages pinned after the last successfully mapped chunk, i.e. the range [map_pfn, last_pfn]. The unpin is guarded by nchunks, but nchunks is reset to 0 every time a chunk is mapped from inside the current page list, so a failure after any such boundary leaves that pending range pinned forever. With physically scattered memory nearly every page list contains a boundary, so the leak happens on practically every failed IOTLB update.
The pending range is non-empty exactly when a page has been pinned, which last_pfn already tells us, so drop nchunks and test last_pfn.
Message-ID: <[email protected]>
--- drivers/vhost/vdpa.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/vhost/vdpa.c +2 -6
@@ -922,7 +922,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,unsigned long list_size =PAGE_SIZE /sizeof (struct page *);unsigned int gup_flags =FOLL_LONGTERM ;unsigned long npages, cur_base, map_pfn, last_pfn =0 ; -unsigned long lock_limit, sz2pin, nchunks, i; +unsigned long lock_limit, sz2pin, i;unsigned long page_offset;u64 start = iova;long pinned;
@@ -958,7 +958,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, cur_base = uaddr &PAGE_MASK ; iova &=PAGE_MASK ; - nchunks =0 ;while (npages) { sz2pin = min_t(unsigned long, npages, list_size);
@@ -973,7 +972,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, } goto out; } - nchunks++;if (!last_pfn) map_pfn =page_to_pfn (page_list[0 ]);
@@ -1004,7 +1002,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, map_pfn = this_pfn; iova += csize; - nchunks =0 ; } last_pfn = this_pfn;
@@ -1019,7 +1016,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, PFN_PHYS(map_pfn), perm, NULL); out:if (ret) { -if (nchunks) { +if (last_pfn) {unsigned long pfn;/*
@@ -1031,7 +1028,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,* the corresponding unpinning will be handled by * vdpa_unmap(). */ -WARN_ON (!last_pfn);for (pfn = map_pfn; pfn <= last_pfn; pfn++)unpin_user_page (pfn_to_page (pfn)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1234/2857 vringh: bound top-level re-entry into indirect tables
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fang Xieyan <[email protected]>
[ Upstream commit f898439ace7f89922e853b43bcbfcd26ea2e0a98 ]
In __vringh_iov(), the F_INDIRECT branch descends into the indirect table and continues before the descriptor accounting runs. A top-level indirect descriptor is therefore never charged to count. If such a descriptor sets NEXT to point back at itself, returning from the indirect table resumes at the same top-level descriptor, which is again not counted, so the walk never makes forward progress.
Because count stays flat and indirect_count is reset to 0 on every return to the top-level table, neither bound in the loop check trips. A guest can spin the vringh worker at 100% CPU inside __vringh_iov(), an uninterruptible host DoS.
Move the descriptor accounting above the indirect switch so that a top-level indirect descriptor is charged one top-level traversal step before the walk descends into its table, bringing this re-entry under the existing vrh->vring.num bound. Each top-level descriptor is still charged at most one step and indirect_count still bounds a single table, so legitimate chains (including the multiple-indirect case in tools/virtio/vringh_test.c) stay within vring.num, while a cyclic indirect descriptor is now rejected with -ELOOP.
Message-ID: <[email protected]>
--- drivers/vhost/vringh.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/vhost/vringh.c +11 -11
@@ -334,6 +334,17 @@ __vringh_iov(struct vringh *vrh, u16 i,if (unlikely (err)) goto fail; +if (up_next ==-1 ) + count++; +else + indirect_count++; + +if (count > vrh->vring.num || indirect_count > desc_max) { +vringh_bad ("Descriptor loop in %p" , descs); + err = -ELOOP ; + goto fail; + } +if (unlikely (desc.flags &cpu_to_vringh16 (vrh,VRING_DESC_F_INDIRECT ))) {u64 a =vringh64_to_cpu (vrh, desc.addr);
@@ -359,17 +370,6 @@ __vringh_iov(struct vringh *vrh, u16 i,continue ; } -if (up_next ==-1 ) - count++; -else - indirect_count++; - -if (count > vrh->vring.num || indirect_count > desc_max) { -vringh_bad ("Descriptor loop in %p" , descs); - err = -ELOOP ; - goto fail; - } -if (desc.flags &cpu_to_vringh16 (vrh,VRING_DESC_F_WRITE )) iov = wiov;else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1235/2857 vringh: reject empty / undersized indirect descriptor tables
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fang Xieyan <[email protected]>
[ Upstream commit 60a792b97933a686316737838cd007d27963011e ]
move_to_indirect() validates an indirect descriptor table only with "len % sizeof(struct vring_desc)". A descriptor flagged VRING_DESC_F_INDIRECT with len == 0 passes that test, so *desc_max is set to 0 while *descs points at the empty table. __vringh_iov() then copies one struct vring_desc from descs[0] -- 16 bytes past the end of the table -- before the "indirect_count > desc_max" loop detection aborts the walk. The over-read value is discarded when the walk aborts and is never used to map anything, but the access itself is out of bounds.
Reject any len smaller than one descriptor, alongside the existing stride check, so an empty table is refused with -EINVAL and no descriptor is ever fetched from it.
Message-ID: <[email protected]>
--- drivers/vhost/vringh.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/vhost/vringh.c +3 -2
@@ -197,8 +197,9 @@ static int move_to_indirect(const struct vringh *vrh, } len =vringh32_to_cpu (vrh, desc->len); -if (unlikely (len %sizeof (struct vring_desc ))) { -vringh_bad ("Strange indirect len %u" , desc->len); +if (unlikely (len <sizeof (struct vring_desc ) || + len %sizeof (struct vring_desc ))) { +vringh_bad ("Invalid indirect len %u" , desc->len);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1236/2857 veth: keep carrier off when resizing channels with a down peer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xia Yan <[email protected]>
[ Upstream commit 2d02191779345b13de91048db441191b20264d16 ]
veth_set_channels() temporarily turns carrier off while reconfiguring a running interface. It then turns carrier on for both ends without checking whether the peer is administratively up. If only one end is up, changing its channel counts therefore reports LOWER_UP even though the peer remains down.
For example, after creating a pair with two RX and TX queues per end:
ip link set vca up
ethtool -L vca rx 1 tx 1
vca incorrectly reports LOWER_UP while vcb is still down.
Only restore carrier when the peer has IFF_UP, matching veth_open(). The local interface is already known to be running at this point.
Found during LLM-assisted source review and reproduced with a veth pair in network namespaces, without kernel instrumentation or error injection. The companion veth.sh test reproduces the two mixed up/down failures before the fix and passes after it.
--- drivers/net/veth.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/veth.c +3 -2
@@ -1301,9 +1301,10 @@ static int veth_set_channels(struct net_device *dev,* to identify the range we have to disable */ veth_disable_range_safe (dev, new_rx_count, old_rx_count); -netif_carrier_on (dev); -if (peer) +if (peer && (peer->flags &IFF_UP )) { +netif_carrier_on (dev);netif_carrier_on (peer); + } }return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1237/2857 hwmon: (corsair-cpro) Cache fan target only after a successful command
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baek Kyu, Kim <[email protected]>
[ Upstream commit e2c26431b4e47892378582a414b4bbaa9edf1798 ]
set_target() updates the cached fan target before sending the command. If the command fails, subsequent fanN_target reads report the failed request instead of the previous value. For example, after successfully setting 1200 RPM, a rejected request for 1800 RPM returns an error but leaves fanN_target reporting 1800. A failed request also replaces -ENODATA when no target has been successfully set.
Update the target cache under the existing mutex only after send_usb_cmd() succeeds, as set_pwm() already does when invalidating the target. Preserve the previous cached value and return the original error on failure.
--- drivers/hwmon/corsair-cpro.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/corsair-cpro.c +2 -1
@@ -208,10 +208,11 @@ static int set_target(struct ccp_device *ccp, int channel, long val)int ret; val =clamp_val (val,0 ,0xFFFF ); - ccp->target[channel] = val;mutex_lock (&ccp->mutex); ret =send_usb_cmd (ccp,CTL_SET_FAN_TARGET , channel, val >>8 , val); +if (!ret) + ccp->target[channel] = val;mutex_unlock (&ccp->mutex);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1238/2857 hwmon: (asus_wmi_sensors) Avoid global struct mutation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 59d586c9e47d1205563bc9b5a5d443adc3ba5bc5 ]
In the asus_wmi_sensors driver, device-managed memory allocated in asus_wmi_configure_sensor_setup() is assigned to a global static structure, leading to a potential use-after-free when the device is unbound. The driver defines a single global asus_wmi_chip_info structure to register with the hwmon core. During probe, it dynamically allocates the .info channel array using devm_kcalloc() and assigns it directly to this global structure. When a device is unbound, its device-managed memory is automatically freed, leaving asus_wmi_chip_info.info as a dangling pointer. Furthermore, if multiple WMI devices are probed sequentially, each probe overwrites the same global pointer, forcing all registered hwmon instances to reference the channel information of the most recently probed device.
While it is unlikely if not impossible that multiple WMI devices of the same kind exist, modifying a global static data structure is undesirable. Remove the static data structure and allocate it as part of struct asus_wmi_sensors to avoid the potential problem.
--- drivers/hwmon/asus_wmi_sensors.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/hwmon/asus_wmi_sensors.c +5 -8
@@ -164,6 +164,7 @@ struct asus_wmi_wmi_info {struct asus_wmi_sensors {struct asus_wmi_wmi_info wmi; +struct hwmon_chip_info chip_info;/* lock access to internal cache */ struct mutex lock; };
@@ -496,11 +497,6 @@ static const struct hwmon_ops asus_wmi_hwmon_ops = { .read_string = asus_wmi_hwmon_read_string, }; -static struct hwmon_chip_info asus_wmi_chip_info = { - .ops = &asus_wmi_hwmon_ops, - .info =NULL , -}; -static int asus_wmi_configure_sensor_setup (struct device *dev,struct asus_wmi_sensors *sensor_data) {
@@ -508,7 +504,7 @@ static int asus_wmi_configure_sensor_setup(struct device *dev,struct hwmon_channel_info *asus_wmi_hwmon_chan;int nr_count[hwmon_max] = {}, nr_types =0 ;struct asus_wmi_sensor_info *temp_sensor; -const struct hwmon_chip_info *chip_info; +struct hwmon_chip_info *chip_info;enum hwmon_sensor_types type;struct device *hwdev;int i, idx;
@@ -549,8 +545,9 @@ static int asus_wmi_configure_sensor_setup(struct device *dev,if (!ptr_asus_wmi_ci)return -ENOMEM ; - asus_wmi_chip_info.info = ptr_asus_wmi_ci; - chip_info = &asus_wmi_chip_info; + chip_info = &sensor_data->chip_info; + chip_info->ops = &asus_wmi_hwmon_ops; + chip_info->info = ptr_asus_wmi_ci; sensor_data->wmi.info_by_id = devm_kcalloc(dev, sensor_data->wmi.sensor_count, sizeof(*sensor_data->wmi.info_by_id),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1239/2857 hwmon: (lm87) Fix drvdata type confusion in vrm_show() and vrm_store()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 5b51ff0887b9f88d042b92dd07fcdda4132f0ebc ]
When an LM87 or ADM1024 device is probed with VID support enabled, reading from or writing to the vrm sysfs attribute triggers a driver data type confusion in vrm_show() and vrm_store() in drivers/hwmon/lm87.c.
In lm87_probe(), the driver stores the struct lm87_data pointer on the I2C client via i2c_set_clientdata() and passes the struct i2c_client pointer as the drvdata argument to devm_hwmon_device_register_with_groups(), which attaches the attribute groups to the registered hwmon device with client as its driver_data. Unlike the other sysfs callbacks that retrieve client via dev_get_drvdata() and then obtain data via i2c_get_clientdata(), vrm_show() and vrm_store() assign dev_get_drvdata(dev) directly to struct lm87_data *. Dereferencing data->vrm therefore accesses the struct i2c_client instance at offsetof(struct lm87_data, vrm), causing vrm_show() to leak an unrelated byte from struct i2c_client to userspace and vrm_store() to corrupt a byte within struct i2c_client while failing to update the actual VRM value.
Fix the problem by assigning the return value from dev_get_drvdata(dev) to struct i2c_client *client and using i2c_get_clientdata() to get the actual client data.
--- drivers/hwmon/lm87.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/hwmon/lm87.c +5 -2
@@ -600,13 +600,16 @@ static DEVICE_ATTR_RO(cpu0_vid);static ssize_t vrm_show (struct device *dev,struct device_attribute *attr,char *buf) { -struct lm87_data *data =dev_get_drvdata (dev); +struct i2c_client *client =dev_get_drvdata (dev); +struct lm87_data *data =i2c_get_clientdata (client); +return sprintf (buf,"%d\n" , data->vrm); }static ssize_t vrm_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) { -struct lm87_data *data =dev_get_drvdata (dev); +struct i2c_client *client =dev_get_drvdata (dev); +struct lm87_data *data =i2c_get_clientdata (client);unsigned long val;int err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1240/2857 hwmon: (nct6683) Fix incorrect struct cast in show_pwm() and store_pwm()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit c4a01c2a80b203ab5f80885f6994346fe217f19c ]
On big-endian architectures, reading or writing the pwm[1-8] sysfs attributes in the nct6683 hardware monitoring driver always redirects to channel 0 due to an incorrect struct downcast in show_pwm() and store_pwm().
The driver defines the PWM sysfs attributes using SENSOR_TEMPLATE(), which initializes them as struct sensor_device_attribute (where the index is a 32-bit int). However, the sysfs callbacks show_pwm() and store_pwm() incorrectly downcast the attribute to a struct sensor_device_attribute_2 (where the index is an 8-bit u8). Because both structs start with struct device_attribute, container_of() resolves to the same base address. On big-endian architectures, reading the 8-bit index field from the memory layout of a 32-bit int fetches the most significant byte (which is 0), rather than the intended channel number.
This type mismatch causes all PWM reads to return data for channel 0, and any writes intended to configure other channels will silently overwrite the duty cycle of PWM channel 0 instead.
Fix the type casts in show_pwm() and store_pwm() to solve the problem.
--- drivers/hwmon/nct6683.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/nct6683.c +2 -2
@@ -911,7 +911,7 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, char *buf) { struct nct6683_data *data = nct6683_update_device(dev); -struct sensor_device_attribute_2 *sattr =to_sensor_dev_attr_2 (attr); +struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr);int index = sattr->index;return sprintf (buf,"%d\n" , data->pwm[index]);
@@ -921,7 +921,7 @@ static ssize_t store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);struct nct6683_data *data =dev_get_drvdata (dev);int index = sattr->index;unsigned long val;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1241/2857 hwmon: (peci/dimmtemp) Fix devres leak and UAF on concurrent unbind
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 61bc4514b8e99e9733c04de028885f6fc906d628 ]
When a peci_dimmtemp device is unbound concurrently with its delayed initialization work (detect_work), newly allocated devm resources and the hwmon device are leaked, leading to a use-after-free when reading the lingering hwmon sysfs attributes.
In peci_dimmtemp_probe(), detect_work is registered for cancellation via devm_delayed_work_autocancel(). During driver detach, devres_release_all() first moves all existing entries from dev->devres_head onto a local todo list before invoking their release callbacks in reverse order. If create_dimm_temp_info_delayed() is already running when devm_delayed_work_drop() calls cancel_delayed_work_sync(), create_dimm_temp_info() can allocate dimmtemp_label strings via devm_kzalloc()/devm_kasprintf() and register the hwmon device via devm_hwmon_device_register_with_info(), appending new devres entries to the now-empty dev->devres_head. Once the work finishes, devres_release_all() frees priv and priv->name from the local todo list without re-evaluating dev->devres_head, leaving the late devres allocations and registered hwmon device behind with a dangling priv pointer.
Cancel detect_work synchronously in a driver .remove() callback instead of relying on devm_delayed_work_autocancel() so that the work is fully drained before devres_release_all() detaches dev->devres_head, allowing any devm resources registered by the delayed work to be released in proper reverse order. Also only schedule detect_work when check_populated_dimms() returns -EAGAIN so that probe failure paths do not leave delayed work pending.
--- drivers/hwmon/peci/dimmtemp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/hwmon/peci/dimmtemp.c +14 -7
@@ -4,7 +4,6 @@#include <linux/auxiliary_bus.h> #include <linux/bitfield.h> #include <linux/bitops.h> -#include <linux/devm-helpers.h> #include <linux/hwmon.h> #include <linux/jiffies.h> #include <linux/module.h>
@@ -327,11 +326,13 @@ static int create_dimm_temp_info(struct peci_dimmtemp *priv)if (ret == -ENODEV ) {dev_dbg (priv->dev,"No DIMMs found\n" );return 0 ; - }else if (ret) { + } +if (ret == -EAGAIN ) {schedule_delayed_work (&priv->detect_work,DIMM_MASK_CHECK_DELAY_JIFFIES );dev_dbg (priv->dev,"Deferred populating DIMM temp info\n" ); -return ret; } +if (ret) +return ret; channels = priv->gen_info->chan_rank_max * priv->gen_info->dimm_idx_max;
@@ -401,10 +402,8 @@ static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct auxil"Unexpected PECI revision %#x, some features may be unavailable\n" , peci_dev->info.peci_revision); - ret =devm_delayed_work_autocancel (priv->dev, &priv->detect_work, - create_dimm_temp_info_delayed); -if (ret) -return ret; +auxiliary_set_drvdata (adev, priv); +INIT_DELAYED_WORK (&priv->detect_work, create_dimm_temp_info_delayed); ret =create_dimm_temp_info (priv);if (ret && ret != -EAGAIN ) {
@@ -415,6 +414,13 @@ static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct auxilreturn 0 ; } +static void peci_dimmtemp_remove (struct auxiliary_device *adev) +{ +struct peci_dimmtemp *priv =auxiliary_get_drvdata (adev); + +cancel_delayed_work_sync (&priv->detect_work); +} +static int read_thresholds_hsx (struct peci_dimmtemp *priv,int dimm_order,int chan_rank,u32 *data) {
@@ -603,6 +609,7 @@ MODULE_DEVICE_TABLE(auxiliary, peci_dimmtemp_ids);static struct auxiliary_driver peci_dimmtemp_driver = { .probe = peci_dimmtemp_probe, + .remove = peci_dimmtemp_remove, .id_table = peci_dimmtemp_ids, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1242/2857 hwmon: (pmbus/q54sj108a2) Add missing NULL pointer check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit a5802c587da97a4ff85c04aad6043fa26640fc9b ]
When CONFIG_DEBUG_FS is enabled and per-client PMBus debugfs directory creation fails during pmbus_do_probe(), q54sj108a2_probe() passes the NULL pointer returned by pmbus_get_debugfs_dir() to debugfs_create_dir() without validation, creating its debugfs directory at the debugfs root instead of under the client directory.
If pmbus_init_debugfs() fails to create the client directory, data->debugfs is left as NULL or an ERR_PTR, which pmbus_get_debugfs_dir() converts to NULL. Passing a NULL parent to debugfs_create_dir() places q54sj108a2_dir in the root of the debugfs filesystem and populates it with attribute files whose private data pointers reference psu->debugfs_entries. Because this root-level directory is outside the client debugfs hierarchy, PMBus core cleanup does not remove it on device unbind, leaking the debugfs entries and causing a use-after-free of the devm-allocated struct q54sj108a2_data if the orphaned files are accessed via q54sj108a2_debugfs_read() or q54sj108a2_debugfs_write() after device removal.
Fix the problem by adding the missing NULL pointer check.
--- drivers/hwmon/pmbus/q54sj108a2.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/pmbus/q54sj108a2.c +2 -0
@@ -342,6 +342,8 @@ static int q54sj108a2_probe(struct i2c_client *client) psu->client = client; debugfs =pmbus_get_debugfs_dir (client); +if (!debugfs) +return 0 ; q54sj108a2_dir =debugfs_create_dir (client->name, debugfs);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1243/2857 hwmon: (pmbus) Release devres allocated memory after devm_thermal_of_zone_register error
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 9aa6cc563e881c3cad96ea36926cadceee151f32 ]
In pmbus_thermal_add_sensor(), a devres memory leak occurs when a PMBus temperature sensor is initialized but no thermal zone is configured for it.
The function allocates a pmbus_thermal_data structure using devm_kzalloc(). It then attempts to register the sensor with the thermal subsystem via devm_thermal_of_zone_register(). If this registration returns -ENODEV (e.g., when no thermal zone is mapped in the Device Tree or CONFIG_THERMAL_OF is disabled), the function intentionally catches the error and returns 0 to allow device probing to continue.
Because devm_kfree() is not called on the -ENODEV path, the unused tdata structure remains allocated on the device's managed resource list. Since most PMBus temperature sensors are not attached to thermal zones, this results in an accumulation of unused objects that needlessly consume kernel memory for the lifetime of the PMBus device.
Add the missing call to devm_kfree() to fix the problem.
--- drivers/hwmon/pmbus/pmbus_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus_core.c +3 -1
@@ -1328,8 +1328,10 @@ static int pmbus_thermal_add_sensor(struct pmbus_data *pmbus_data,* If CONFIG_THERMAL_OF is disabled, this returns -ENODEV, * so ignore that error but forward any other error. */ -if (IS_ERR (tzd) && (PTR_ERR (tzd) != -ENODEV )) +if (IS_ERR (tzd) && (PTR_ERR (tzd) != -ENODEV )) { +devm_kfree (dev, tdata);return PTR_ERR (tzd); + }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1244/2857 hwmon: (pmbus) Fix return value check from thermal zone registration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 4fc79634af8cdf734e0a633923ba4817e30d29ad ]
The PMBus core used to call devm_thermal_zone_of_sensor_register() to register thermal zones. Commit 613ed3f676092 ("hwmon: pm_bus: core:
Switch to new of thermal API") changed this to call devm_thermal_of_zone_register() instead. The code subsequently checks if the call failed because the thermal subsystem is not configured. devm_thermal_zone_of_sensor_register() used to return -ENODEV in this case. devm_thermal_of_zone_register() returns -ENOTSUPP. The code currently still checks for -ENOVEV. This results in driver instantiation failures if the thermal subsystem is disabled.
Check for -ENOTSUPP to fix the problem. Keep checking for -ENODEV because this indicates that no thermal zone is configured for the sensor, which is acceptable for the driver and must not cause a registration failure.
--- drivers/hwmon/pmbus/pmbus_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +4 -3
@@ -1325,10 +1325,11 @@ static int pmbus_thermal_add_sensor(struct pmbus_data *pmbus_data, tzd =devm_thermal_of_zone_register (dev, index, tdata, &pmbus_thermal_ops);/* -* If CONFIG_THERMAL_OF is disabled, this returns -ENODEV, -* so ignore that error but forward any other error. +* If CONFIG_THERMAL_OF is disabled, devm_thermal_of_zone_register() +* returns -ENOTSUPP. If no thermal zone is configured for the sensor, +* it returns -ENODEV. Ignore those errors but forward any other error. */ -if (IS_ERR (tzd) && (PTR_ERR (tzd) != -ENODEV )) { +if (IS_ERR (tzd) &&PTR_ERR (tzd) != -ENODEV &&PTR_ERR (tzd) != -ENOTSUPP ) {devm_kfree (dev, tdata);return PTR_ERR (tzd); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1245/2857 KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit b2691b3a6cd230209736c89684dab90d939aa56b ]
Conditionally reschedule when retrying a guest PTE walk because the CMPXCHG to update A/D bits failed, e.g. because a different task/vCPU modified the relevant gPTEs. On kernels without involuntary preemption of some kind, a misbehaving guest can "capture" a pCPU effectively indefinitely and trigger soft lockups by continuously modifying its gPTEs such that the result of the walk is remains valid.
Message-ID: <[email protected]>
--- arch/x86/kvm/mmu/paging_tmpl.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu/paging_tmpl.h +10 -1
@@ -321,6 +321,13 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,gpa_t real_gpa;gfn_t gfn; +/* +* KVM might sleep/resched when retrying the walk if the updating A/D +* fails because the gPTE changed between reading the gPTE and trying +* the CMPXHG to set A/D bits. +*/ +might_sleep (); +trace_kvm_mmu_pagetable_walk (addr, access); retry_walk: walker->level = mmu->cpu_role.base.level;
@@ -452,8 +459,10 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, addr, write_fault);if (unlikely (ret <0 )) goto error; -else if (ret) +else if (ret) { +cond_resched (); goto retry_walk; + } } pgprintk("%s: pte %llx pte_access %x pt_access %x\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1246/2857 KVM: x86: Conditionally resched when restarting REP string emulation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit ae85ac25eb671d174811cc3101549448671fd505 ]
When restarting emulation, e.g. of a REP-prefixed string instruction, conditionally reschedule as emulating guest writes can be deceptively slow and expensive, e.g. when shadow paging is in use and each write can trigger write tracking.
In a perfect world, restarting emulation (or not) would be less arbitrary, e.g. would honor not only host events (NEED_RESCHED, signals, etc.) but also guest events (e.g. by checking kvm_vcpu_has_events()). Unfortunately, as pointed out by Sashiko, pio_in_emulated()'s read-ahead logic is baked into the restart logic, as KVM relies on restarting emulation to drain the cache and avoid duplicate reads from the I/O port. I.e. re-entering the guest on kvm_vcpu_has_events() or __xfer_to_guest_mode_work_pending() would introduce architecturally-incorrect, guest-visible changes.
Message-ID: <[email protected]>
--- arch/x86/kvm/x86.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +4 -2
@@ -9062,10 +9062,12 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, }else if (vcpu->arch.complete_userspace_io) { writeback = false; r =0 ; - }else if (r ==EMULATION_RESTART ) + }else if (r ==EMULATION_RESTART ) { +cond_resched (); goto restart; -else + }else { r =1 ; + } writeback:if (writeback) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1247/2857 KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit c33ef9d334059f7cb167569ed7b4779752fe4425 ]
Add a missing "break" in the inner for-loop of the open coded mess that unwinds MSRs back to the pre-VM-Enter state when VMLAUNCH/VMRESUME VM-Fails due to a consistency check that is caught by hardware but missed by KVM. I.e. move on to the next MSR in the VM-Entry load list after performing a write using a value found in the VM-Exit load list. Processing *every* matching entry in the VM-Exit load list makes the processing quadratic, which is problematic if the load lists are full of MSRs that are expensive to emulate. E.g. writing APIC_BASE triggers kvm_recalculate_apic_map() and a whole pile of unnecessary work.
Functionally, arbitrarily restoring the value of the first matching entry is "fine", because none of this is architecturally correct: the load lists are never supposed to have been used in the first place. In practice, it's likely a moot point as no well-behaved VMM will have multiple, diverging entries in the load lists.
Message-ID: <[email protected]>
--- arch/x86/kvm/vmx/nested.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/vmx/nested.c +1 -0
@@ -4766,6 +4766,7 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu) __func__, j, h.index, h.value); goto vmabort; } +break ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1248/2857 KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit)
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit e4558c3d7198ed9a0adc3304681f561f4e4d80e1 ]
When potentially reusing a shadow page, zap the shadow page if its number of parent PTEs exceeds KVM's (mostly) arbitrary rmap recycling threshold. Letting the guest create a (mostly) unbounded number of parent PTEs allows the guest to coerce KVM into creating lists containing millions of PTEs, effectively bounded only by the maximum number of shadow pages.
Because PTE lists are simple singly linked lists, removal is O(n). Even worse, if a list is constructed just so, teardown can be O(n^2), e.g. if SPTEs are built such that zapping child SPTEs always zaps the last entry in the list. To cap things off, all paths that walk PTE lists do so while holding mmu_lock, without conditionally rescheduling.
Using a doubly linked list would not address the issue, as removal would remain O(n) since KVM still wouldn't know where in the list to remove from. Removal could be made O(1) by storing a per-SPTE pointer, but that would largely defeat the purpose of reusing SPs, and would penalize well-behaved guests, especially for nested TDP where aliasing page tables is uncommon.
So, cap the maximum number of parent PTEs at the rmap limit. In practice, well-behaved guests will likely never run afoul of the limit. E.g. when running Linux as L1 with TDP, the number of parent PTEs for a single SP tops out at under 200 (though undoubtedly obscure workloads can push it higher). Deliberately use a "greater than or equal" as opposed to rmap's strictly "greater than", as the rmap code checks the threshold immediately *after* inserting into the list, i.e. the limit is 1000 for rmaps, KVM just very briefly blows past it.
Apply the check to both indirect and direct SPs, because while a fully direct MMU naturally limits the number of parent PTEs to '1', direct SPs in indirect MMUs have no such constraint. E.g. if the guest maps a huge PTE into many locations in its page tables, and KVM is backing the hugepage with a direct SP, i.e. with a series of smaller pages, then KVM could end up with a direct SP with many parents.
Note, shadow_mmu_try_split_huge_pages() always restarts the rmap walk or bails entirely if it gets to the point where it tries to grab a SP, i.e. there is *no* pre-existing bug that would be tripped by zapping a SP and thus rmaps when getting a SP.
Message-ID: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kvm/mmu/mmu.c +10 -0
@@ -2068,6 +2068,16 @@ static struct kvm_mmu_page *kvm_mmu_find_shadow_page(struct kvm *kvm,continue ; } +/* +* Note! Unlike fully direct MMUs, direct SPs in indirect MMUs +* can have an arbitrary number of parents, e.g if the guest is +* mapping a huge PTE at many points in its page tables. +*/ +if (pte_list_count (&sp->parent_ptes) >=RMAP_RECYCLE_THRESHOLD ) { +kvm_mmu_prepare_zap_page (kvm, sp, &invalid_list); +break ; + } +/* unsync and write-flooding only apply to indirect SPs. */ if (sp->role.direct) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1249/2857 KVM: x86: Unconditionally reset MMU context when emulating INIT
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit c7c288d178cb0b78d3464a616b16b1aa0b316049 ]
Force an MMU reset when emulating an INIT even if paging was already disabled, as the MMU page role includes guest_mode (L2), i.e. an INIT while L2 is running with CR0.PG=0 will result in KVM running L1 with a stale MMU context.
Alternatively, the reset could be scoped strictly to paging being enabled or L2 being active, but SMM is also encoded in the page role. Even though it _should_ be impossible for the vCPU to be INIT'd while SMM is active, there's zero value in not handling SMM. At that point, the only scenario where KVM _doesn't_ need to reset the MMU context is on an INIT with the vCPU running in Real Mode or Unpaged Protect Mode, and while INIT in those modes is somewhat common, it's far from a hot path and re-initializing the MMU is not expensive, especially when the role isn't changing (KVM elides most of the re-configuration in that case).
Note, like the Fixes commit, this bug only affects nested SVM as INIT is an unconditional intercept on VMX, i.e. it's impossible to emulate INIT while L2 is active.
Temporarily keep the guest TLB flush when CR0.PG is being cleared even though it is fully redundant with the flush that is emitted on all INIT events (KVM itself only does RESET when a vCPU is being created, i.e. when CR0.PG must be '0').
Message-ID: <[email protected]>
--- arch/x86/kvm/x86.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
arch/x86/kvm/x86.c +15 -10
@@ -12307,18 +12307,23 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)static_call (kvm_x86_set_efer)(vcpu,0 );static_call (kvm_x86_update_exception_bitmap)(vcpu); +if (old_cr0 &X86_CR0_PG ) +kvm_make_request (KVM_REQ_TLB_FLUSH_GUEST , vcpu); +/* -* On the standard CR0/CR4/EFER modification paths, there are several -* complex conditions determining whether the MMU has to be reset and/or -* which PCIDs have to be flushed. However, CR0.WP and the paging-related -* bits in CR4 and EFER are irrelevant if CR0.PG was '0'; and a reset+flush -* is needed anyway if CR0.PG was '1' (which can only happen for INIT, as -* CR0 will be '0' prior to RESET). So we only need to check CR0.PG here. +* Unconditionally reset the MMU, even though super strictly speaking, +* a MMU reset is only necessary if and only one of the page role bits +* is changing. All of the CR0/CR4/EFER bits effectively get covered +* by checking CR0.PG=1, as CR0.WP and the paging-related bits in CR4 +* and EFER are irrelevant if CR0.PG was '0'. Subtly, if the vCPU was +* in guest mode (L2) or SMM (although emulating INIT in SMM _should_ +* be impossible), an MMU reset is also necessary as "guest mode" and +* "smm" are both encoded in the shadow page role. As a result, the +* only scenarios where an MMU reset is *not* needed is if the vCPU is +* in Real Mode or Unpaged Protected Mode, and micro-optimizing those +* paths are not worth the risk of running with a stale MMU context. */ -if (old_cr0 &X86_CR0_PG ) { -kvm_make_request (KVM_REQ_TLB_FLUSH_GUEST , vcpu); -kvm_mmu_reset_context (vcpu); - } +kvm_mmu_reset_context (vcpu);/* * Intel's SDM states that all TLB entries are flushed on INIT. AMD's
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1250/2857 Bluetooth: hci_sync: re-enable legacy advertising on resume
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valentin Kindschi <[email protected]>
[ Upstream commit 737139f4157d302292a6b937d96922879ecabfa3 ]
hci_resume_advertising_sync() never re-enables advertising on a controller without extended advertising.
It restores HCI_ADVERTISING from advertising_old_state, then calls hci_schedule_adv_instance_sync(), which starts with:
if (hci_dev_test_flag(hdev, HCI_ADVERTISING) && !ext_adv_capable(hdev))
return -EPERM;The flag it tests was set a few lines earlier by the resume itself, so the call returns -EPERM without sending anything. The return value is discarded by every caller, so the failure is silent: advertising_paused is cleared, HCI_ADVERTISING is set, and the controller is not advertising.
Observed on a BCM43455 (no extended advertising) after an active scan:
btmon shows the pause disabling advertising and no re-enable in the ten seconds that follow, the device does not appear in another controller's scan, and btmgmt info still reports "advertising" in current settings.
Enable instance 0x00 directly in that case, the way reenable_adv_sync() already does for the same situation. Instances continue to go through hci_schedule_adv_instance_sync() so the software rotation loop is rearmed.
This affects every caller of hci_resume_advertising_sync(), not only the scan path: address resolution changes, accept list updates, discovery stop, suspend/resume and the end of an LE connection attempt all leave advertising disabled on such a controller today.
The resume does nothing when the controller is already advertising, as it is after directed advertising was started for a peripheral connection, so it does not replace that advertising.
err is initialised because the extended branch leaves it unset when adv_instances is empty and HCI_LE_ADV_0 is clear.
--- net/bluetooth/hci_sync.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/bluetooth/hci_sync.c +8 -2
@@ -2734,7 +2734,7 @@ static int hci_pause_advertising_sync(struct hci_dev *hdev)static int hci_resume_advertising_sync (struct hci_dev *hdev) {struct adv_info *adv, *tmp; -int err; +int err =0 ;/* If advertising has not been paused there is nothing to do. */ if (!hdev->advertising_paused)
@@ -2767,13 +2767,19 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev)*/ if (hci_dev_test_and_clear_flag (hdev,HCI_LE_ADV_0 )) err =hci_enable_ext_advertising_sync (hdev,0x00 ); - }else { + }else if (hdev->cur_adv_instance) {/* Schedule for most recent instance to be restarted and begin * the software rotation loop */ err =hci_schedule_adv_instance_sync (hdev, hdev->cur_adv_instance, true); + }else if (hci_dev_test_flag (hdev,HCI_ADVERTISING ) && + !hci_dev_test_flag (hdev,HCI_LE_ADV )) { +/* hci_schedule_adv_instance_sync() rejects instance 0x00 while +* HCI_ADVERTISING is set, so enable it directly. +*/ + err =hci_start_adv_sync (hdev,0x00 ); } hdev->advertising_paused = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1251/2857 mm: make swapoff interruptible when unusing mms/shmem
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Down <[email protected]>
[ Upstream commit 740128dd1a3f2bd81a80314d079b6b03c39ba3af ]
try_to_unuse() only checks for a pending signal between mms, and shmem_unuse() doesn't check at all. That means that once swapoff gets to a process or a shmem file with a lot swapped out, nothing can interrupt it until every last page of it has been read back in.
Just as one example of where this can concretely show up, freezing tasks for suspend or hibernation has to wait for swapoff to notice the freezer's fake signal, and gives up after freeze_timeout_msecs (20 seconds by default).
Here's a facetious example where one swaps out 2GiB of one process to a swap file on ext4, starts swapoff, and half a second later tries to freeze with pm_test=freezer. Writing to /sys/power/state then fails with EBUSY and this in dmesg:
Freezing user space processes failed after 20.003 seconds (1 tasks refusing to freeze, wq_busy=0):
task:swapoff state:D stack:0 pid:3175 tgid:3175 ppid:2955 task_flags:0x400100 flags:0x00000419
Call trace:
[...]
io_schedule+0x44/0x70
folio_wait_bit_common+0x1ec/0x3d0
__folio_lock+0x24/0x40
unuse_pte_range+0x2d0/0x348
unuse_vma+0x158/0x248
unuse_mm+0xfc/0x150
try_to_unuse+0x104/0x3f8
__do_sys_swapoff+0x220/0x5d8
[...]The same goes for anything else that wants swapoff to stop, like an admin hitting ^C in a panic, of course.
Prior to commit b56a2d8af914 ("mm: rid swapoff of quadratic complexity") try_to_unuse() was driven by find_next_to_unuse() which checks for a signal before every entry, so let's restore that behaviour.
Just as an example of the improvements, here's how long freezing takes in the same test while swapoff is happening on my computer:
before after
400MiB anon 8.925s 0.028s
400MiB shmem 1.639s 0.003s
2GiB anon failed after 20.003s 0.011s--- mm/shmem.c | 4 ++++ mm/swapfile.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
mm/shmem.c +4 -0
@@ -1317,6 +1317,10 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type)if (ret <0 )break ; +if (signal_pending (current)) { + ret = -ERESTARTSYS ; +break ; + } start = indices[folio_batch_count (&fbatch) -1 ]; }while (true);
mm/swapfile.c +3 -1
@@ -1927,6 +1927,8 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, pmd =pmd_offset (pud, addr); do { cond_resched(); + if (signal_pending(current)) + return -ERESTARTSYS; next = pmd_addr_end(addr, end); if (pmd_none_or_trans_huge_or_clear_bad(pmd)) continue;
@@ -2139,7 +2141,7 @@ static int try_to_unuse(unsigned int type)if (READ_ONCE (si->inuse_pages)) {if (!signal_pending (current)) goto retry; -return -EINTR ; +return -ERESTARTSYS ; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1252/2857 openrisc: export __mulsi3 for modules
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Morton <[email protected]>
[ Upstream commit 8ff981aa283a0ce516c2dc65a48a185ed336c657 ]
OpenRISC configurations without hardware multiplication fail to build modules which contain compiler-generated calls to __mulsi3. The failure is widespread, affecting filesystems, drivers and KUnit tests at modpost.
When CONFIG_OPENRISC_HAVE_INST_MUL is disabled, the architecture Makefile passes -msoft-mul to GCC. The multiplication helper is supplied by the libgcc archive linked into vmlinux, but or32_ksyms.c does not export it. Built-in callers can therefore link while module callers cannot resolve the symbol.
Export __mulsi3 alongside the other compiler-generated helpers.
The omission predates 7c3f4d699f34 ("resource, kunit: stop selecting GET_FREE_REGION"), which the robot identified when reporting an additional failing module. It was already present in the initial OpenRISC export list.
--- arch/openrisc/kernel/or32_ksyms.c | 1 + 1 file changed, 1 insertion(+)
arch/openrisc/kernel/or32_ksyms.c +1 -0
@@ -35,6 +35,7 @@ DECLARE_EXPORT(__divsi3);DECLARE_EXPORT (__umodsi3);DECLARE_EXPORT (__modsi3);DECLARE_EXPORT (__muldi3); +DECLARE_EXPORT (__mulsi3);DECLARE_EXPORT (__ashrdi3);DECLARE_EXPORT (__ashldi3);DECLARE_EXPORT (__lshrdi3);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1253/2857 ocfs2: find the xattr entry again after defragmenting a bucket
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 9a40c050f58344615a0604701b5d299519833163 ]
ocfs2_xattr_set_entry_bucket() hands loc.xl_entry to ocfs2_xa_set() twice:
once for the bucket as it stands, and, if that reports -ENOSPC, once more after ocfs2_defrag_xattr_bucket() has packed the name/value pairs down.
Defragmenting ends by sorting the entry array on xe_name_hash. Buckets are kept sorted, so the sort only permutes entries that share a hash, but lib/sort.c is an unstable heapsort and it does permute them. loc.xl_entry is an address inside xh_entries[], so afterwards it denotes whichever entry landed in that slot rather than the one the search found.
The second ocfs2_xa_set() then works on the wrong entry. Nothing on that path compares the entry's name with xi->xi_name, so what happens depends on how the two entries compare in size: ocfs2_xa_reuse_entry() trips its BUG_ON() when the padded name sizes differ, and otherwise the new value is written into the neighbouring attribute's value slot while the attribute being set is left untouched. setxattr() reports success either way.
Remember the entry's hash before defragmenting and look the entry up again afterwards, the way ocfs2_xattr_bucket_find() does. An entry that cannot be found again means the bucket no longer holds what the search found, so fail with -EFSCORRUPTED rather than writing through the stale pointer.
--- fs/ocfs2/xattr.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +29 -1
@@ -5579,13 +5579,18 @@ static int ocfs2_xattr_set_entry_bucket(struct inode *inode,struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { - int ret; + int ret, found = 0; +u16 xe_index; +u32 name_hash;struct ocfs2_xa_loc loc;trace_ocfs2_xattr_set_entry_bucket (xi->xi_name);ocfs2_init_xattr_bucket_xa_loc (&loc, xs->bucket, xs->not_found ?NULL : xs->here); +/* Defragmenting below may move this entry, so remember its hash. */ + name_hash = loc.xl_entry ?le32_to_cpu (loc.xl_entry->xe_name_hash) :0 ; + ret =ocfs2_xa_set (&loc, xi, ctxt);if (!ret) { xs->here = loc.xl_entry;
@@ -5604,6 +5609,29 @@ static int ocfs2_xattr_set_entry_bucket(struct inode *inode, goto out; } +/* +* ocfs2_defrag_xattr_bucket() sorts the entries by name hash and +* lib/sort.c is not stable, so entries sharing a hash may have traded +* slots. Look the entry up again before writing through it. +*/ +if (loc.xl_entry) { + ret =ocfs2_find_xe_in_bucket (inode, xs->bucket, + xi->xi_name_index, xi->xi_name, + name_hash, &xe_index, &found); +if (ret) { +mlog_errno (ret); + goto out; + } +if (!found) { +mlog (ML_ERROR ,"xattr entry not found in bucket %llu after defrag\n" , + (unsigned long long )bucket_blkno (xs->bucket)); + ret = -EFSCORRUPTED ; + goto out; + } + loc.xl_entry = &bucket_xh (xs->bucket)->xh_entries[xe_index]; + xs->here = loc.xl_entry; + } + ret =ocfs2_xa_set (&loc, xi, ctxt);if (!ret) { xs->here = loc.xl_entry;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1254/2857 ocfs2: find the xattr entry again after converting a block to a bucket
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 9c191a7a44882487e291e09f095d2ae4d7cca146 ]
ocfs2_xattr_create_index_block() turns a non-indexed xattr block into a tree by copying it into a bucket, and the copy sorts the entries: a block holds them in insertion order, a bucket by name hash. ocfs2_xattr_update_xattr_search() nevertheless relocates the caller's search by the index the entry had in the block, so unless the two orders agreed it points at an unrelated entry, and nothing between there and the write compares that entry's name with the one being set.
Setting an xattr whose new value no longer fits the block arrives here with xs->not_found clear. The block gave up because ocfs2_xa_block_can_reuse() wants an exact namevalue size match, while ocfs2_xa_bucket_can_reuse() only wants an entry at least as large as the new one, so the bucket accepts a pair the block rejected and the update lands on whichever entry the sort left at that index. Equal padded name lengths get that other attribute's value replaced in place and its name left alone, so setxattr returns success while the attribute asked for keeps its old value. A longer one trips ocfs2_xa_reuse_entry()'s BUG_ON, and a shorter one is refused by the bucket as well, so ocfs2_xa_prepare_entry() wipes the entry and writes the new name over it, leaving xe_name_hash describing a name that is no longer there.
Find the entry again by the name being set, matching the type as well. The copy carries every entry and every name over unchanged, and (type, name) pairs are unique within a block, so the match is exact. The type matters because the handlers strip their prefix before calling ocfs2_xattr_set(), so user.foo and trusted.foo share a stored name, a stored length and a hash, and both can sit in the same block.
The name has to come from xi rather than from xs->here: a failed set can remove the entry xs->here names, and only the "growing" caller sets ctxt->set_abort, which is what stops the conversion. Scan every entry rather than narrowing on the hash the way ocfs2_find_xe_in_bucket() does, since an existing entry keeps the hash it was stored under, which a kernel that sign-extended the name bytes made different from the one computed now. An empty result means the entry did not survive the failed set and this has become an insert; leaving xs->here alone would keep it pointing into the block, which is rewritten as a tree root before the caller reads it again.
--- fs/ocfs2/xattr.c | 54 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +44 -10
@@ -260,6 +260,7 @@ static int ocfs2_xattr_tree_list_index_block(struct inode *inode, size_t buffer_size);static int ocfs2_xattr_create_index_block (struct inode *inode, +struct ocfs2_xattr_info *xi,struct ocfs2_xattr_search *xs,struct ocfs2_xattr_set_ctxt *ctxt);
@@ -2999,7 +3000,7 @@ static int ocfs2_xattr_block_set(struct inode *inode,else if ((ret != -ENOSPC ) || ctxt->set_abort) goto end;else { - ret =ocfs2_xattr_create_index_block (inode, xs, ctxt); + ret =ocfs2_xattr_create_index_block (inode, xi, xs, ctxt);if (ret) goto end; }
@@ -4283,13 +4284,10 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,* real place of the xattr. */ static void ocfs2_xattr_update_xattr_search (struct inode *inode, -struct ocfs2_xattr_search *xs, -struct buffer_head *old_bh) +struct ocfs2_xattr_info *xi, +struct ocfs2_xattr_search *xs) { -char *buf = old_bh->b_data; -struct ocfs2_xattr_block *old_xb = (struct ocfs2_xattr_block *)buf; -struct ocfs2_xattr_header *old_xh = &old_xb->xb_attrs.xb_header; -int i; +int i, count; xs->header =bucket_xh (xs->bucket); xs->base =bucket_block (xs->bucket,0 );
@@ -4298,11 +4296,47 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode,if (xs->not_found)return ; - i = xs->here - old_xh->xh_entries; - xs->here = &xs->header->xh_entries[i]; +/* +* A block holds its entries in insertion order while a bucket holds +* them by name hash, so ocfs2_cp_xattr_block_to_bucket() sorted the +* copies and the index this entry had in the block no longer says +* where it is. It copied every entry and every name unchanged, and +* (type, name) pairs are unique within a block, so find it again by +* name. +* +* Search for the name being set, not for the name xs->here carries. +* A failed set may have removed that entry, and ocfs2_xa_remove_entry() +* then memmoves its successor into the slot. Comparing every entry +* rather than narrowing on the hash also finds an entry stored under +* the legacy signed hash, which ocfs2_find_xe_in_bucket() would skip. +*/ + count =le16_to_cpu (xs->header->xh_count); +for (i =0 ; i < count; i++) { +struct ocfs2_xattr_entry *xe = &xs->header->xh_entries[i]; + +if (ocfs2_xattr_get_type (xe) != xi->xi_name_index) +continue ; +if (xe->xe_name_len != xi->xi_name_len) +continue ; +if (!memcmp (xs->base +le16_to_cpu (xe->xe_name_offset), + xi->xi_name, xi->xi_name_len)) { + xs->here = xe; +return ; + } + } + +/* +* The entry did not survive the failed set, so this has become an +* insert. Point xs->here back inside the bucket: it still refers to +* the block being converted, which is about to be rewritten as a tree +* root. +*/ + xs->not_found = -ENODATA ; + xs->here = xs->header->xh_entries; }static int ocfs2_xattr_create_index_block (struct inode *inode, +struct ocfs2_xattr_info *xi,struct ocfs2_xattr_search *xs,struct ocfs2_xattr_set_ctxt *ctxt) {
@@ -4369,7 +4403,7 @@ static int ocfs2_xattr_create_index_block(struct inode *inode,ocfs2_cp_xattr_block_to_bucket (inode, xb_bh, xs->bucket);ocfs2_xattr_bucket_journal_dirty (handle, xs->bucket); -ocfs2_xattr_update_xattr_search (inode, xs, xb_bh); +ocfs2_xattr_update_xattr_search (inode, xi, xs);/* Change from ocfs2_xattr_header to ocfs2_xattr_tree_root */ memset(&xb->xb_attrs, 0, inode->i_sb->s_blocksize -
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1255/2857 ocfs2: do not index before the entry array when dividing an empty bucket
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 7133a0d0954c109f1764ebf8ab32d7e757a6c587 ]
ocfs2_divide_xattr_bucket() appends an empty bucket carrying a sentinel hash when the source bucket has no divide position, taking that hash from xh_entries[start - 1]. ocfs2_xattr_find_divide_pos() returns count when every entry shares one hash, and its loop does not run at all for count < 2, so an empty bucket comes back with start == count == 0 and the read is xh_entries[-1].
That is outside the __counted_by_le(xh_count) bounds of xh_entries[] and lands on the header, so the value picked up isxh_count | xh_free_start << 16. One above it is written into the new bucket's xh_entries[0] and committed, which leaves a bucket whose first hash does not follow the bucket before it. ocfs2_xattr_bucket_find() binary searches on xh_entries[0], so the broken key hides the range the sentinel was meant to cover: getxattr() answers -ENODATA for an attribute that is stored, and an insert can go to the wrong bucket and leave two copies of a name. The cross cluster divide hands the same value back as a tree record's e_cpos, which then claims a hash range it does not cover.
Read xh_entries[0] instead. The branch is only reached when every entry shares one hash, so for a non-empty bucket it holds the same value, and for an empty one it is the slot that carries the bucket key.
An empty bucket reaches the divide from ocfs2_check_xattr_bucket_collision(), which reports no collision for one, through ocfs2_add_new_xattr_bucket() and ocfs2_extend_xattr_bucket(). It does not take a failed set to get
there: a divide that finds no position is itself what leaves an empty sentinel bucket behind, and a later extend can pick it as the target.
--- fs/ocfs2/xattr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +9 -1
@@ -4756,7 +4756,15 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, start =ocfs2_xattr_find_divide_pos (xh);if (start == count) { - xe = &xh->xh_entries[start-1 ]; +/* +* start == count means every entry shares one hash, so the +* first of them carries it too. An empty bucket has no +* entries[start - 1], but its entries[0] still carries the +* bucket key: either the hash ocfs2_xa_remove_entry() +* deliberately leaves behind, or the sentinel a previous +* divide wrote. +*/ + xe = &xh->xh_entries[0 ];/* * initialized a new empty bucket here.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1256/2857 ocfs2: do not read the entry array of an empty xattr block
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit cd7c3563a98fe8c984463d83772e518cb7e68356 ]
ocfs2_cp_xattr_block_to_bucket() sizes the name and value area it has to carry over from the block's last entry, so an empty block makes it read xh_entries[-1]. That lands on the header, where xe_name_offset overlaps xh_name_value_len, and block storage never maintains that field, so it reads as 0 and the copy runs from the header to the end of the block.
The bucket that comes out has xh_count 0 but a name_value_len of blocksize less the header, and a matching xh_free_start that claims those bytes are in use -- nearly the whole bucket with the common 4K block size -- while the last block of the bucket holds a copy of the old block's bytes. Nothing but a trace event reads xh_name_value_len, the copied bytes came from the same inode and were wiped before the entry was removed, and ocfs2_defrag_xattr_bucket() recomputes xh_free_start, so this corrupts the header rather than leaking anything.
Leave the bucket empty instead, carrying over the hash the block was keyed by, since ocfs2_add_new_xattr_bucket() and ocfs2_xattr_bucket_find() both read xh_entries[0] of an empty bucket. That read is the exception ocfs2_xa_remove_entry() documents rather than a new out of bounds access.
A block reaches the conversion empty when truncating an external value back fails partway through: the "reusing" and "overwriting" callers of ocfs2_xa_cleanup_value_truncate() remove the entry without setting ctxt->set_abort, so ocfs2_xattr_block_set() sees a plain -ENOSPC and converts. The "growing" caller does set it, and the block form makes a single attempt with no defragment and retry in between, so that is the only route here.
--- fs/ocfs2/xattr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
fs/ocfs2/xattr.c +15 -0
@@ -4238,6 +4238,21 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,for (i =0 ; i < blks; i++)memset (bucket_block (bucket, i),0 , blocksize); +/* +* An empty block has no names or values to carry over, and the +* xh_entries[count - 1] below would be xh_entries[-1]. Leave the +* bucket empty, but carry over the hash ocfs2_xa_remove_entry() left +* in the block's xh_entries[0] so that the bucket still holds the key +* it is looked up by. +*/ +if (!count) { + xh->xh_num_buckets =cpu_to_le16 (1 ); + xh->xh_free_start =cpu_to_le16 (OCFS2_XATTR_BUCKET_SIZE ); + xh->xh_entries[0 ].xe_name_hash = + xb_xh->xh_entries[0 ].xe_name_hash; +return ; + } +/* * Since the xe_name_offset is based on ocfs2_xattr_header, * there is a offset change corresponding to the change of
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1257/2857 fat: hold truncate_lock in fat_write_failed()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matheus Alves de Almeida <[email protected]>
[ Upstream commit 7b90009546f5d3f3ac9428040cd7ffbdfd60f2eb ]
The current fat_write_failed() implementation calls into fat_truncate_blocks() without holding truncate_lock.
A failed or short extending write racing with FIBMAP can spuriously make a FAT filesystem read-only. FIBMAP bounds its lookup by i_blocks, so it can walk allocated clusters beyond i_size while fat_write_failed() is removing them. If the chain is shortened during the walk, the mapper can report a bogus "request beyond EOF" error, triggering the default read-only error policy. Hold truncate_lock for write around the block cleanup to serialize it with _fat_bmap().
For comparison, fat_setattr() correctly holds truncate_lock during truncation:
down_write(&MSDOS_I(inode)->truncate_lock); truncate_setsize(inode, attr->ia_size); fat_truncate_blocks(inode, attr->ia_size); up_write(&MSDOS_I(inode)->truncate_lock);
Make it so ->truncate_lock is held exclusive while truncating.
--- fs/fat/inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/fat/inode.c +2 -0
@@ -221,7 +221,9 @@ static void fat_write_failed(struct address_space *mapping, loff_t to)if (to > inode->i_size) {truncate_pagecache (inode, inode->i_size); +down_write (&MSDOS_I (inode)->truncate_lock);fat_truncate_blocks (inode, inode->i_size); +up_write (&MSDOS_I (inode)->truncate_lock); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1258/2857 ocfs2: keep locking_state within the cluster connection lifetime
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 5bdef466851e39ba752634cbea68e5ea24ccfb24 ]
The locking_state reader calls ocfs2_dlm_lvb() through the selected cluster stack. Its debug-object reference keeps the tracking list alive, but does not keep that stack selected without a cluster connection.
DLM initialization publishes the file before establishing its connection, and DLM shutdown drops the connection while the file still exists. Both the mount error unwind in ocfs2_mount_volume() and ocfs2_dismount_volume() remove the debugfs subtree only after ocfs2_dlm_shutdown() has returned. Whenever the disconnect releases the last stack reference, which is the case for a failed mount and for any unmount without a pending hangup, a concurrent reader dereferences a NULL active_stack:
Mount error unwind Debugfs reader
------------------ --------------
ocfs2_mount_volume(): out_dlm
ocfs2_dlm_shutdown()
disconnect last cluster
clear active_stack
read locking_state
ocfs2_dlm_seq_show()
ocfs2_dlm_lvb()
dereference active_stack fill_super(): out_debugfs
remove debugfs subtree
Publish the debug files only after the connection and the mount lock resources are initialized, so a failed DLM initialization has no debug reference to drop. Remove them again in the common DLM shutdown helper before the connection is dropped: debugfs removal waits for readers that are inside the file operations, and the parent directory is still present at that point in every caller. This covers the mount error unwind, the ocfs2_fill_super() failures after a successful mount that dismount with mnt_err set, and unmounts whose disconnect releases the stack directly.
Only the relevant frames of the report are kept:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:ocfs2_dlm_lvb+0x38/0xf0 Call Trace: <TASK> ocfs2_dlm_seq_show+0x36a/0xb70 seq_read_iter+0x480/0x1110 seq_read+0x362/0x5a0 full_proxy_read+0x11f/0x180 vfs_read+0x1a0/0xc20 ksys_read+0x111/0x200 </TASK>
--- fs/ocfs2/dlmglue.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
fs/ocfs2/dlmglue.c +13 -5
@@ -3337,6 +3337,14 @@ static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb) {struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug; +/* +* Drain the readers before the cluster stack goes away: the +* locking_state reader resolves ocfs2_dlm_lvb() through the +* stack. Every caller removes the parent directory later. +*/ +debugfs_lookup_and_remove ("locking_state" , osb->osb_debug_root); +debugfs_lookup_and_remove ("locking_filter" , osb->osb_debug_root); +if (dlm_debug)ocfs2_put_dlm_debug (dlm_debug); }
@@ -3351,8 +3359,6 @@ int ocfs2_dlm_init(struct ocfs2_super *osb) goto local; } -ocfs2_dlm_init_debug (osb); -/* launch downconvert thread */ osb->dc_task =kthread_run (ocfs2_downconvert_thread, osb,"ocfs2dc-%s" , osb->uuid_str);
@@ -3392,9 +3398,10 @@ int ocfs2_dlm_init(struct ocfs2_super *osb)ocfs2_orphan_scan_lock_res_init (&osb->osb_orphan_scan.os_lockres, osb); osb->cconn = conn; +if (conn) +ocfs2_dlm_init_debug (osb); bail:if (status <0 ) { -ocfs2_dlm_shutdown_debug (osb);if (osb->dc_task)kthread_stop (osb->dc_task); }
@@ -3424,10 +3431,11 @@ void ocfs2_dlm_shutdown(struct ocfs2_super *osb,ocfs2_lock_res_free (&osb->osb_orphan_scan.os_lockres);if (osb->cconn) { +/* The disconnect below may release the selected stack. */ +ocfs2_dlm_shutdown_debug (osb); +ocfs2_cluster_disconnect (osb->cconn, hangup_pending); osb->cconn =NULL ; - -ocfs2_dlm_shutdown_debug (osb); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1259/2857 ocfs2/dlm: serialize migration MLE cleanup on failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 61469249aab03799b0d3294b7a0cd25dd303017a ]
A migration MLE has a base reference for the mastering answer and an in-use reference held by dlm_migrate_lockres(). The finishing assertion consumes the base reference, but migration failure drops it again without checking whether the assertion already consumed it.
The target queues its migration worker before it acknowledges the ALL_DONE packet, so its finishing assertion can be handled while the sender still waits for the status. If the connection fails before the status arrives, dlm_send_one_lockres() returns an error for a migration that the target has already completed:
Old-master sender Finishing assertion
----------------- -------------------
publish MLE; take in-use reference
send ALL_DONE; wait for status
take lookup reference unlink MLE
put lookup and base references
send returns a connection error
put base reference again; free MLE
put in-use reference; access freed MLE
dlm_assert_master_handler() holds dlm->spinlock from the MLE lookup to the final puts, and it takes dlm->master_lock around the unlink and the puts. Decide under the same locks: if the MLE is already unhashed, the assertion consumed the base reference, so drop only the sender's in-use reference. Otherwise unlink it before consuming the base reference so a later assertion no longer finds it.
An assertion that got there first has also made the target the owner and cleared DLM_LOCK_RES_MIGRATING. Treating the attempt as failed at that point would leave the lockres owned by the target while this node still holds the other nodes' locks and refmap bits, so it could neither be purged nor migrated again. Finish our side as a completed migration does instead: drop those locks under res->spinlock if the target still owns the lockres, and recalculate its usage.
Use the same cleanup for the pre-send failure, the send failure and the target-death failure paths. The sender's in-use reference keeps the MLE alive until its final put outside the nested locks. Successful migration retains its existing in-use-only put.
A target that has died cannot assert after the sender has seen its death. The o2net node-down callback runs before the DLM one; it disconnects the node and flushes the workqueue that runs the message handlers, so an assertion already received has been handled by the time the DLM removes the node from the domain map. A node that leaves the domain cleanly sends its exit message only after its assertions have been answered.
Two windows of the hand-over itself are left as they are: the handler switches the owner and the sender drops the other nodes' locks moments later, and an assertion from a live target that arrives after the sender has given up still meets the owner check in the handler. Waiting for the target before giving up would only stretch the first window into the time in which recovery of the target can observe it.
KASAN report, only the relevant frames are kept:
BUG: KASAN: slab-use-after-free in dlm_put_mle_inuse+0xce/0xe0 Read of size 8 at addr ffff8881190e3c20 by task umount/593 Call Trace: <TASK> dlm_put_mle_inuse+0xce/0xe0 dlm_migrate_lockres+0x16af/0x20d0 dlm_empty_lockres+0x60a/0xbd0 dlm_unregister_domain+0x53b/0x11d0 o2cb_cluster_disconnect+0xa5/0x110 ocfs2_cluster_disconnect+0x73/0xc0 ocfs2_dlm_shutdown+0x311/0x440 ocfs2_dismount_volume+0x696/0x940 generic_shutdown_super+0x15f/0x490 kill_block_super+0x40/0xa0 deactivate_locked_super+0xae/0x120 deactivate_super+0xa2/0xc0 cleanup_mnt+0x217/0x450 task_work_run+0x144/0x230 </TASK> Allocated by task 593: kmem_cache_alloc_noprof+0x20b/0x5c0 dlm_migrate_lockres+0x20e/0x20d0 dlm_empty_lockres+0x60a/0xbd0 dlm_unregister_domain+0x53b/0x11d0 o2cb_cluster_disconnect+0xa5/0x110 ocfs2_cluster_disconnect+0x73/0xc0 ocfs2_dlm_shutdown+0x311/0x440 ocfs2_dismount_volume+0x696/0x940 Freed by task 593: kmem_cache_free+0x242/0x580 __dlm_put_mle+0x4b2/0x660 dlm_migrate_lockres+0x1690/0x20d0 dlm_empty_lockres+0x60a/0xbd0 dlm_unregister_domain+0x53b/0x11d0 o2cb_cluster_disconnect+0xa5/0x110 ocfs2_cluster_disconnect+0x73/0xc0 ocfs2_dlm_shutdown+0x311/0x440 The buggy address belongs to the object at ffff8881190e3c00 which belongs to the cache o2dlm_mle of size 480
The buggy address is located 32 bytes inside of
freed 480-byte region [ffff8881190e3c00, ffff8881190e3de0)
--- fs/ocfs2/dlm/dlmmaster.c | 70 ++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 9 deletions(-)
fs/ocfs2/dlm/dlmmaster.c +61 -9
@@ -2537,6 +2537,52 @@ static int dlm_is_lockres_migratable(struct dlm_ctxt *dlm,*/ +/* +* Drop the sender's references on a migration MLE after the attempt has +* failed. The finishing assert from the target may already have unlinked +* the MLE and consumed its base reference; decide under the locks the +* assert handler holds, and only drop the base reference while the MLE is +* still hashed. Returns true when the assert got there first: the target +* has become the master, so the caller must complete the migration. +*/ +static bool dlm_put_migration_mle (struct dlm_ctxt *dlm, +struct dlm_master_list_entry *mle) +{ +bool asserted; + +spin_lock (&dlm->spinlock); +spin_lock (&dlm->master_lock); +__dlm_mle_detach_hb_events (dlm, mle); + asserted =hlist_unhashed (&mle->master_hash_node); +if (!asserted) { +__dlm_unlink_mle (dlm, mle); +__dlm_put_mle (mle); + } +spin_unlock (&dlm->master_lock); +spin_unlock (&dlm->spinlock); + +dlm_put_mle_inuse (mle); +return asserted; +} + +/* +* The finishing assert got there first: it switched the owner to the +* target and cleared DLM_LOCK_RES_MIGRATING. Drop the other nodes' locks +* as a completed migration does, unless recovery has taken the lockres +* over since, and let the usage be recalculated. +*/ +static void dlm_migrate_lockres_asserted (struct dlm_ctxt *dlm, +struct dlm_lock_resource *res, +u8 target) +{ +spin_lock (&res->spinlock); +if (res->owner == target) +dlm_remove_nonlocal_locks (dlm, res); +spin_unlock (&res->spinlock); + +dlm_lockres_calc_usage (dlm, res); +} +static int dlm_migrate_lockres (struct dlm_ctxt *dlm,struct dlm_lock_resource *res,u8 target) {
@@ -2621,9 +2667,10 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm,if (ret <0 ) {if (mle_added) { -dlm_mle_detach_hb_events (dlm, mle); -dlm_put_mle (mle); -dlm_put_mle_inuse (mle); +if (dlm_put_migration_mle (dlm, mle)) { +dlm_migrate_lockres_asserted (dlm, res, target); + ret =0 ; + } }else if (mle) {kmem_cache_free (dlm_mle_cache, mle); mle =NULL ;
@@ -2652,9 +2699,11 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm,mlog (0 ,"migration to node %u failed with %d\n" , target, ret);/* migration failed, detach and clean up mle */ -dlm_mle_detach_hb_events (dlm, mle); -dlm_put_mle (mle); -dlm_put_mle_inuse (mle); +if (dlm_put_migration_mle (dlm, mle)) { +dlm_migrate_lockres_asserted (dlm, res, target); + ret =0 ; + goto leave; + }spin_lock (&res->spinlock); res->state &= ~DLM_LOCK_RES_MIGRATING ; wake =1 ;
@@ -2698,9 +2747,12 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm, res->lockname.name, target); ret = -EINVAL ;/* migration failed, detach and clean up mle */ -dlm_mle_detach_hb_events (dlm, mle); -dlm_put_mle (mle); -dlm_put_mle_inuse (mle); +if (dlm_put_migration_mle (dlm, mle)) { +dlm_migrate_lockres_asserted (dlm, res, + target); + ret =0 ; + goto leave; + }spin_lock (&res->spinlock); res->state &= ~DLM_LOCK_RES_MIGRATING ; wake =1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1260/2857 ocfs2: stop recovery before shutting down local allocators
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 126429e2f503ade63502978beb0c519066442250 ]
Recovery completion needs the local allocators until it has finished reclaiming a failed node's allocation window and truncate log. During unmount, quota recovery is stopped first, but that leaves recovery_state at OCFS2_REC_QUOTA_DISABLED. New non-quota recovery can still start.
ocfs2_truncate_log_shutdown() drains existing completion work and releases osb_tl_bh before ocfs2_recovery_exit() closes that publication path:
Unmount Recovery
------- --------
stop quota recovery; disable quotas truncate_log_shutdown()
flush existing completion work
recover another failed node
queue completion
flush local log; release buffer
complete_truncate_log_recovery()
use released osb_tl_bh
recovery_exit(): disable and drain
An extra buffer reference alone would still let completion append new records after the final truncate-log flush.
Split stopping and draining recovery from freeing its state. Stop all recovery producers and drain completion work before shutting down either local allocator. Keep recovery-state release at its existing later point, so its lifetime relative to other teardown users stays unchanged. The second stop at recovery_exit() is harmless once recovery is disabled.
KASAN report as below:
BUG: KASAN: slab-use-after-free in ocfs2_truncate_log_needs_flush+0x23d/0x360
Read of size 8 at addr ffff8881093711e8 by task kworker/u16:3/53
CPU: 0 UID: 0 PID: 53 Comm: kworker/u16:3 Not tainted 7.3.0-rc4-next-20260921-pmb-ocfs2-functional-v1+ #1 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: ocfs2_wq ocfs2_complete_recovery
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? ocfs2_truncate_log_needs_flush+0x23d/0x360
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20e/0x420
? ocfs2_truncate_log_needs_flush+0x23d/0x360
kasan_report+0xe0/0x110
? ocfs2_truncate_log_needs_flush+0x23d/0x360
ocfs2_truncate_log_needs_flush+0x23d/0x360
? __pfx_ocfs2_truncate_log_needs_flush+0x10/0x10
? __pfx_down_write+0x10/0x10
ocfs2_complete_truncate_log_recovery+0x315/0x780
? trace_hardirqs_on+0x18/0x160
? __pfx_ocfs2_complete_truncate_log_recovery+0x10/0x10
? ocfs2_complete_recovery+0x666/0x11b0
? srso_alias_return_thunk+0x5/0xfbef5
? kfree+0x308/0x580
ocfs2_complete_recovery+0x676/0x11b0
? __pfx_ocfs2_complete_recovery+0x10/0x10
? reacquire_held_locks+0xdd/0x200
? process_one_work+0x7c8/0x1b40
? srso_alias_return_thunk+0x5/0xfbef5
? lock_acquire+0x190/0x300
? __pfx_autoremove_wake_function+0x10/0x10
? process_one_work+0x834/0x1b40
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x290
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x9a8/0x1b40
? __pfx_process_one_work+0x10/0x10
? lock_acquire+0x190/0x300
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? srso_alias_return_thunk+0x5/0xfbef5
? __kthread_parkme+0x177/0x220
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_worker_thread+0x10/0x10
kthread+0x351/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf70
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Allocated by task 538:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_slab_alloc+0x89/0x90
kmem_cache_alloc_noprof+0x20b/0x5c0
alloc_buffer_head+0x26/0x120
folio_alloc_buffers+0x122/0x1d0
bdev_getblk+0x299/0x4f0
ocfs2_read_blocks_sync+0x513/0xbc0
ocfs2_iget+0x9cd/0x1a00
ocfs2_get_system_file_inode+0x25e/0x7a0
ocfs2_fill_super+0x1b05/0x3930
get_tree_bdev_flags+0x35d/0x5f0
vfs_get_tree+0x93/0x320
fc_mount+0x1d/0x200
path_mount+0x592/0x1e00
__x64_sys_mount+0x24b/0x2d0
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 553:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kmem_cache_free+0x242/0x580
free_buffer_head+0x4b/0xc0
try_to_free_buffers+0x1dc/0x330
ocfs2_truncate_log_shutdown+0x789/0x1290
ocfs2_dismount_volume+0x1da/0x940
generic_shutdown_super+0x15f/0x490
kill_block_super+0x40/0xa0
deactivate_locked_super+0xae/0x120
deactivate_super+0xa2/0xc0
cleanup_mnt+0x217/0x450
task_work_run+0x144/0x230
exit_to_user_mode_loop+0x17d/0x570
do_syscall_64+0x4d1/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff8881093711c0
which belongs to the cache buffer_head of size 160
The buggy address is located 40 bytes inside of
freed 160-byte region [ffff8881093711c0, ffff888109371260)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x109371
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881008883c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000120012 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888109371080: 00 00 00 00 fc fc fc fc fc fc fc fc 00 00 00 00
ffff888109371100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff888109371180: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
^
ffff888109371200: fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
ffff888109371280: fc fc fc fc 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================--- fs/ocfs2/journal.c | 15 ++++++++++++--- fs/ocfs2/journal.h | 1 + fs/ocfs2/super.c | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-)
fs/ocfs2/journal.c +12 -3
@@ -232,13 +232,22 @@ void ocfs2_recovery_disable_quota(struct ocfs2_super *osb)ocfs2_recovery_disable (osb,OCFS2_REC_QUOTA_WANT_DISABLE ); } +/* Stop producers and drain completion work without freeing recovery state. */ +void ocfs2_recovery_stop (struct ocfs2_super *osb) +{ +ocfs2_recovery_disable (osb,OCFS2_REC_WANT_DISABLE ); +} +void ocfs2_recovery_exit (struct ocfs2_super *osb) {struct ocfs2_recovery_map *rm; -/* disable any new recovery threads and wait for any currently -* running ones to exit. Do this before setting the vol_state. */ -ocfs2_recovery_disable (osb,OCFS2_REC_WANT_DISABLE ); +/* +* Disable producers and drain work before freeing recovery state. +* Do this before setting vol_state to VOLUME_DISMOUNTED: completion +* work may still be waiting in __ocfs2_wait_on_mount(). +*/ +ocfs2_recovery_stop (osb);/* * Now that recovery is shut down, and the osb is about to be
fs/ocfs2/journal.h +1 -0
@@ -147,6 +147,7 @@ void ocfs2_complete_recovery(struct work_struct *work);void ocfs2_wait_for_recovery (struct ocfs2_super *osb);int ocfs2_recovery_init (struct ocfs2_super *osb); +void ocfs2_recovery_stop (struct ocfs2_super *osb);void ocfs2_recovery_exit (struct ocfs2_super *osb);void ocfs2_recovery_disable_quota (struct ocfs2_super *osb);
fs/ocfs2/super.c +3 -0
@@ -1886,6 +1886,9 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)/* Wait for worker to be done with the work structure in osb */ cancel_work_sync (&osb->dquot_drop_work); +/* Stop recovery producers before releasing their local allocators. */ +ocfs2_recovery_stop (osb); +ocfs2_shutdown_local_alloc (osb);ocfs2_truncate_log_shutdown (osb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1261/2857 ocfs2/cluster: unlink socket containers before releasing resources
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 0988f0c0c7c908f0ff77fd8b90ce9918a1f41479 ]
A socket container's node and socket must remain alive while the container is on sock_containers. The debugfs formatter reads sc_node and sc_sock under o2net_debug_lock without taking their references, but sc_kref_release() releases both before taking that lock to unlink the container.
With CONFIG_DEBUG_FS enabled, a synchronous sender can retain its last socket-container reference after o2net_disconnect_node() has detached the connection and flushed o2net_wq. The caller runs outside that workqueue. After the sender removes its configfs dependency, node removal can proceed without waiting for the sender's final sc_put():
Sender (final sc_put) Configfs rmdir Debugfs reader
-------------------- -------------- --------------
o2nm_undepend_item()
Drop node item refs
o2nm_node_put()
[node can be freed]
sc_seq_show()
Lock debug lock Read sc_node->nd_name Unlock debug lock
sc_node = NULL
o2net_debug_del_sc()
The earlier socket release has a similar window. The container is still selectable while its socket has been released and sc_sock has not yet been cleared:
Sender (final sc_put) Debugfs reader
-------------------- --------------
sock_release(sc->sc_sock)
[socket can be freed]
sc_seq_show()
Lock debug lock Read sc_sock->sk fields Unlock debug lock
sc_sock = NULL
...
o2net_debug_del_sc()
Move o2net_debug_del_sc() before releasing either resource. Unlinking under the existing debug lock waits for an active formatter to finish and prevents later readers from selecting the container. This covers both socket fields and node fields, including nd_num in the stats formatter.
KASAN report as below:
BUG: KASAN: slab-use-after-free in string+0x42b/0x470
Read of size 1 at addr ffff88810f56fc90 by task python3/506
CPU: 0 UID: 0 PID: 506 Comm: python3 Not tainted 7.3.0-rc4-next-20260921-pmb-ocfs2-functional-v1+ #1 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
kasan_report+0xe0/0x110
string+0x42b/0x470
vsnprintf+0x330/0x1110
seq_printf+0x1a8/0x260
sc_seq_show+0x604/0x9f0
seq_read_iter+0x480/0x1110
seq_read+0x362/0x5a0
full_proxy_read+0x11f/0x180
vfs_read+0x1a0/0xc20
ksys_read+0x111/0x200
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f(User register dump omitted.)
</TASK>
Allocated by task 497:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x28d/0x610
o2nm_node_group_make_item+0xea/0x1a0
configfs_mkdir+0x762/0xca0
vfs_mkdir+0x399/0x7e0
filename_mkdirat+0x129/0x450
__x64_sys_mkdir+0x70/0xa0
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 505:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x308/0x580
config_item_cleanup+0x14b/0x230
config_item_put+0x79/0x90
sc_put+0x454/0x6e0
o2net_send_message_vec+0x63d/0x1560
o2net_send_message+0xa6/0xe0
validation_send_write+0x17f/0x1d0
full_proxy_write+0x11f/0x180
vfs_write+0x25a/0x1010
ksys_write+0x111/0x200
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff88810f56fc00
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 144 bytes inside of
freed 512-byte region [ffff88810f56fc00, ffff88810f56fe00)(Page and shadow-memory dumps omitted.)
--- fs/ocfs2/cluster/tcp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/tcp.c +3 -2
@@ -390,6 +390,9 @@ static void sc_kref_release(struct kref *kref)sclog (sc,"releasing\n" ); +/* Unlink before freeing anything the debugfs readers dereference. */ +o2net_debug_del_sc (sc); +if (sc->sc_sock) {sock_release (sc->sc_sock); sc->sc_sock =NULL ;
@@ -399,8 +402,6 @@ static void sc_kref_release(struct kref *kref)o2nm_node_put (sc->sc_node); sc->sc_node =NULL ; -o2net_debug_del_sc (sc); -if (sc->sc_page)__free_page (sc->sc_page);kfree (sc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1262/2857 ocfs2: wait for filecheck kobject release after a failed add
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit a25c02af29c3e95128e4343fceb4bdace8e480a0 ]
The filecheck kobject and its release completion are embedded in ocfs2_super, so the osb must outlive the kobject. On a failed kobject_init_and_add(), creation clears fs_fcheck and calls kobject_put(), but returns without waiting for the release callback.
With CONFIG_DEBUG_KOBJECT_RELEASE, the last put queues delayed cleanup. Mount failure can then free the containing osb before the embedded release timer expires:
Mount failure Delayed cleanup
------------- ---------------
ocfs2_filecheck_create_sysfs()
kobject_init_and_add() fails
fs_fcheck = NULL
kobject_put()
queue delayed release
return to mount error cleanup
ocfs2_dismount_volume()
remove_sysfs() skips the wait
kfree(osb)
expire embedded release timer
access freed osb
The normal removal path waits for fs_kobj_unregister, but it returns early when fs_fcheck is NULL. The failed-add path therefore leaves the delayed work and its completion in freed storage.
Wait for the existing release completion after the failed-add kobject_put(), before returning to mount error cleanup. This keeps the enclosing osb alive until the kobject has finished releasing, matching the normal teardown path.
KASAN report as below:
BUG: KASAN: slab-use-after-free in __run_timers+0xa6d/0xa90
Write of size 8 at addr ffff8881178a5658 by task swapper/0/0
CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.3.0-rc4-next-20260921-pmb-ocfs2-functional-v1+ #1 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<IRQ>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? __run_timers+0xa6d/0xa90
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20e/0x420
? __run_timers+0xa6d/0xa90
kasan_report+0xe0/0x110
? __run_timers+0xa6d/0xa90
__run_timers+0xa6d/0xa90
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx___run_timers+0x10/0x10
? __lock_acquire+0x5a3/0x2140
? __pfx_do_raw_spin_lock+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
timer_expire_remote+0xfa/0x160
? __pfx_timer_expire_remote+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on+0x18/0x160
tmigr_handle_remote_up+0x4ba/0x9d0
? __pfx_tmigr_handle_remote_up+0x10/0x10
? tmigr_handle_remote+0x21a/0x340
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x290
? __pfx_tmigr_handle_remote_up+0x10/0x10
__walk_groups_from+0x5a/0x160
tmigr_handle_remote+0x24f/0x340
? __pfx_tmigr_handle_remote+0x10/0x10
? lock_acquire+0x190/0x300
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x290
run_timer_softirq+0x222/0x270
? __pfx_run_timer_softirq+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? lockdep_hardirqs_on_prepare+0xb8/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
handle_softirqs+0x1fa/0x8d0
? __pfx_handle_softirqs+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? _raw_spin_unlock+0x23/0x40
? srso_alias_return_thunk+0x5/0xfbef5
? __hrtimer_rearm_deferred+0x1fb/0x5d0
__irq_exit_rcu+0x113/0x1e0
irq_exit_rcu+0xe/0x20
sysvec_apic_timer_interrupt+0x6c/0x80
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20
RIP: 0010:pv_native_safe_halt+0xf/0x20
Code: fa 18 01 e9 ee 37 ff fa 0f 1f 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa eb 07 0f 00 2d 23 c7 14 00 fb f4 <e9> c7 37 ff fa 66 2e 0f 1f 84 00 00 00 00 00 66 90 90 90 90 90 90
RSP: 0018:ffffffff87c07cf8 EFLAGS: 00000206
RAX: 0000000000045d0f RBX: ffffffff87c2d4c0 RCX: ffffffff86111e95
RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff815b508e
RBP: fffffbfff0f85a98 R08: 0000000000000001 R09: ffffed10310c68ba
R10: ffff8881886345d3 R11: 0000000000000000 R12: 0000000000000001
R13: 0000000000000000 R14: 1ffffffff0f80fa4 R15: dffffc0000000000
? ct_kernel_exit.constprop.0+0xc5/0xf0
? do_idle+0x3ae/0x650
default_idle+0x9/0x10
default_idle_call+0x6c/0xb0
do_idle+0x3ae/0x650
? __pfx___schedule+0x10/0x10
? __pfx_do_idle+0x10/0x10
? rest_init+0x1cd/0x330
? srso_alias_return_thunk+0x5/0xfbef5
cpu_startup_entry+0x54/0x60
rest_init+0x1e1/0x330
? __pfx_acpi_read_bit_register+0x10/0x10
? __pfx_rest_init+0x10/0x10
? acpi_os_write_port+0x23/0xb0
? __pfx_kernel_init+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? acpi_ut_status_exit+0xd6/0x180
? srso_alias_return_thunk+0x5/0xfbef5
? acpi_ut_status_exit+0xd6/0x180
? srso_alias_return_thunk+0x5/0xfbef5
? acpi_enable_subsystem+0x2b0/0x4e0
? __pfx_x86_late_time_init+0x10/0x10
start_kernel+0x417/0x4b0
x86_64_start_reservations+0x18/0x30
x86_64_start_kernel+0x111/0x120
common_startup_64+0x13e/0x158
</TASK>
Allocated by task 494:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x28d/0x610
ocfs2_initialize_super.isra.0+0xab/0x3070
ocfs2_fill_super+0x801/0x3920
get_tree_bdev_flags+0x35d/0x5f0
vfs_get_tree+0x93/0x320
fc_mount+0x1d/0x200
path_mount+0x592/0x1e00
__x64_sys_mount+0x24b/0x2d0
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 494:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x308/0x580
ocfs2_dismount_volume+0x43c/0x9b0
ocfs2_fill_super+0x258f/0x3920
get_tree_bdev_flags+0x35d/0x5f0
vfs_get_tree+0x93/0x320
fc_mount+0x1d/0x200
path_mount+0x592/0x1e00
__x64_sys_mount+0x24b/0x2d0
do_syscall_64+0x114/0x620
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff8881178a4000
which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 5720 bytes inside of
freed 8192-byte region [ffff8881178a4000, ffff8881178a6000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1178a0
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000000040(head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000040 ffff888100043880 dead000000000122 0000000000000000
raw: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000
head: 0200000000000040 ffff888100043880 dead000000000122 0000000000000000
head: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000
head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8881178a5500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881178a5580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8881178a5600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8881178a5680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881178a5700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================--- fs/ocfs2/filecheck.c | 2 ++ 1 file changed, 2 insertions(+)
fs/ocfs2/filecheck.c +2 -0
@@ -189,6 +189,8 @@ int ocfs2_filecheck_create_sysfs(struct ocfs2_super *osb)/* Mount failure still calls ocfs2_filecheck_remove_sysfs(). */ entry->fs_fcheck =NULL ;kobject_put (&entry->fs_kobj); +/* Keep ocfs2_super alive until the kobject is released. */ +wait_for_completion (&entry->fs_kobj_unregister);kfree (fcheck);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1263/2857 xfs: fix temporary cursor leak in btree shift corruption paths
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianyun Gao <[email protected]>
[ Upstream commit 2bbca049deeb1699cafd966cb2793fee576ee409 ]
In xfs_btree_lshift and xfs_btree_rshift, when XFS_IS_CORRUPT detects an invalid firstrec/lastrec result after xfs_btree_dup_cursor has successfully allocated a temporary cursor, the error path jumps to error0 which returns without freeing tcur. This leaks the cursor memory, the xfs_group reference, and the per-level buffer references held by the duplicated cursor. Jump to error1 instead, which calls xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR) to properly release all resources.
--- fs/xfs/libxfs/xfs_btree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_btree.c +2 -2
@@ -2468,7 +2468,7 @@ xfs_btree_lshift( i =xfs_btree_firstrec (tcur, level);if (XFS_IS_CORRUPT (tcur->bc_mp, i !=1 )) { error = -EFSCORRUPTED ; - goto error0; + goto error1; } error =xfs_btree_decrement (tcur, level, &i);
@@ -2638,7 +2638,7 @@ xfs_btree_rshift( i =xfs_btree_lastrec (tcur, level);if (XFS_IS_CORRUPT (tcur->bc_mp, i !=1 )) { error = -EFSCORRUPTED ; - goto error0; + goto error1; } error =xfs_btree_increment (tcur, level, &i);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1264/2857 net/sched: sch_qfq: prevent aggregate self-replacement
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 2e54b3e187300893688c2c7517894f5d96732e05 ]
qfq_change_class() snapshots the current aggregate settings while holding the qdisc tree lock, but drops the lock before selecting the destination aggregate. During that gap, qfq_enqueue() can move the class to an aggregate matching the requested settings.
When qfq_change_class() resumes, qfq_find_agg() then returns cl->agg. If it is a singleton, qfq_deact_rm_from_agg() frees the aggregate before qfq_add_to_agg() immediately accesses the same pointer, causing a use-after-free.
While holding the tree lock, skip the replacement when the destination is already the current aggregate. Any estimator replacement has already completed, so the class change can finish normally.
--- net/sched/sch_qfq.c | 3 +++ 1 file changed, 3 insertions(+)
net/sched/sch_qfq.c +3 -0
@@ -521,11 +521,14 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,sch_tree_lock (sch);qfq_init_agg (q, new_agg, lmax, weight); } +if (existing && new_agg == cl->agg) + goto unlock;if (existing)qfq_deact_rm_from_agg (q, cl);else qdisc_class_hash_insert (&q->clhash, &cl->common);qfq_add_to_agg (q, new_agg, cl); +unlock:sch_tree_unlock (sch);qdisc_class_hash_grow (sch, &q->clhash);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1265/2857 iommu/virtio: Reset device before deleting virtqueues on probe failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 1f8efac19a0870cdfdf8477e447e5a07ddce9623 ]
viommu_probe() marks the device DRIVER_OK before populating the event virtqueue and registering the IOMMU device in sysfs. viommu_fill_evtq() hands the device a set of device-writable buffers through virtqueue_add_inbuf(), so from that point on the device may write into them and into the rings.
If either step fails, the error path deletes the virtqueues without resetting the device first. The event buffers are allocated with devm_kmalloc_array() and are released as probe unwinds, so the device can go on writing to memory that has been freed.
Reset the device before deleting the virtqueues, the way viommu_remove() already does.
Message-ID: <[email protected]>
--- drivers/iommu/virtio-iommu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/virtio-iommu.c +4 -2
@@ -1174,12 +1174,12 @@ static int viommu_probe(struct virtio_device *vdev)/* Populate the event queue with buffers */ ret =viommu_fill_evtq (viommu);if (ret) - goto err_free_vqs; + goto err_reset_vdev; ret =iommu_device_sysfs_add (&viommu->iommu, dev,NULL ,"%s" ,virtio_bus_name (vdev));if (ret) - goto err_free_vqs; + goto err_reset_vdev;iommu_device_register (&viommu->iommu, &viommu_ops, parent_dev);
@@ -1191,6 +1191,8 @@ static int viommu_probe(struct virtio_device *vdev)return 0 ; +err_reset_vdev: +virtio_reset_device (vdev); err_free_vqs: vdev->config->del_vqs (vdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1266/2857 drm/bridge: nwl-dsi: Cleanup endpoint mux control selection
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 8dad0ebd822f54102aadc6ca4f0f8777112d175d ]
Using the endpoint define values makes it more clear that the argument to mux_control_try_select() must be valid state integers, and not something that looks like a boolean.
The endpoint value is kept, as it will be used in a following patch that changes behavior slightly based on which endpoint is selected.
--- drivers/gpu/drm/bridge/nwl-dsi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/nwl-dsi.c +6 -4
@@ -110,6 +110,8 @@ struct nwl_dsi {int error;struct nwl_dsi_transfer *xfer; + +unsigned int endpoint; };static const struct regmap_config nwl_dsi_regmap_config = {
@@ -1089,13 +1091,12 @@ static int nwl_dsi_parse_dt(struct nwl_dsi *dsi)static int nwl_dsi_select_input (struct nwl_dsi *dsi) {struct device_node *remote; -u32 use_dcss =1 ;int ret; remote =of_graph_get_remote_node (dsi->dev->of_node,0 ,NWL_DSI_ENDPOINT_LCDIF );if (remote) { - use_dcss =0 ; + dsi->endpoint =NWL_DSI_ENDPOINT_LCDIF ; }else { remote =of_graph_get_remote_node (dsi->dev->of_node,0 ,NWL_DSI_ENDPOINT_DCSS );
@@ -1104,11 +1105,12 @@ static int nwl_dsi_select_input(struct nwl_dsi *dsi) "No valid input endpoint found\n");return -EINVAL ; } + dsi->endpoint =NWL_DSI_ENDPOINT_DCSS ; }DRM_DEV_INFO (dsi->dev,"Using %s as input source\n" , - (use_dcss) ?"DCSS" :"LCDIF" ); - ret =mux_control_try_select (dsi->mux, use_dcss); + (dsi->endpoint ==NWL_DSI_ENDPOINT_DCSS ) ?"DCSS" :"LCDIF" ); + ret =mux_control_try_select (dsi->mux, dsi->endpoint);if (ret <0 )DRM_DEV_ERROR (dsi->dev,"Failed to select input: %d\n" , ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1267/2857 drm/bridge: nwl-dsi: Limit LCDIF specific sync override
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 54a88d9afcca66221d14f438d0960472984968ec ]
When using DCSS with NWL, overriding the mode flags to enforce active high sync is preventing the use of active low with downstream bridges, such as ti-sn65dsi83, which will not see such mode flags set by the panel.
--- drivers/gpu/drm/bridge/nwl-dsi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/nwl-dsi.c +5 -2
@@ -824,10 +824,13 @@ static int nwl_dsi_bridge_atomic_check(struct drm_bridge *bridge, struct drm_connector_state *conn_state) {struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; +struct nwl_dsi *dsi =bridge_to_dsi (bridge);/* At least LCDIF + NWL needs active high sync */ - adjusted_mode->flags |= (DRM_MODE_FLAG_PHSYNC |DRM_MODE_FLAG_PVSYNC ); - adjusted_mode->flags &= ~(DRM_MODE_FLAG_NHSYNC |DRM_MODE_FLAG_NVSYNC ); +if (dsi->endpoint ==NWL_DSI_ENDPOINT_LCDIF ) { + adjusted_mode->flags |= (DRM_MODE_FLAG_PHSYNC |DRM_MODE_FLAG_PVSYNC ); + adjusted_mode->flags &= ~(DRM_MODE_FLAG_NHSYNC |DRM_MODE_FLAG_NVSYNC ); + }/* * Do a full modeset if crtc_state->active is changed to be true.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1268/2857 inotify: do not coalesce rename events
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 581230d2ec3c0380917d1255792508851e7c4627 ]
inotify compares the mask, watch descriptor and name when coalescing adjacent unread events, but ignores their rename cookies. Distinct IN_MOVED_FROM events can therefore be coalesced, losing the cookie needed to match a later IN_MOVED_TO event.
For example, watch two directories with IN_MOVE. Move an entry from the first directory into an unwatched directory, recreate it under the same name, then move it from the first directory into the second watched directory before reading the events. The second IN_MOVED_FROM is merged with the first, while the IN_MOVED_TO retains the second rename's cookie. Userspace can no longer pair the second rename's events.
The original inotify implementation compared cookies before coalescing. The fsnotify conversion lost this comparison. Do not coalesce IN_MOVED_FROM or IN_MOVED_TO events, which carry the identity of their respective renames. Leave coalescing of other event types unchanged.
--- fs/notify/inotify/inotify_fsnotify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/notify/inotify/inotify_fsnotify.c +1 -1
@@ -36,7 +36,7 @@ static bool event_compare(struct fsnotify_event *old_fsn, old =INOTIFY_E (old_fsn); new =INOTIFY_E (new_fsn); -if (old->mask &FS_IN_IGNORED ) +if (old->mask & (FS_IN_IGNORED |FS_MOVE ))return false; if ((old->mask == new->mask) && (old->wd == new->wd) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1269/2857 block: Return the soft block size for compat BLKBSZGET
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 57cd1a08717690e5ea01d7ac7a96bb33a2dca117 ]
BLKBSZGET returns the block device's soft block size, while BLKSSZGET returns its logical sector size. The compat BLKBSZGET_32 handler uses bdev_logical_block_size(), so it returns the wrong value when these sizes differ.
For example, on an x86_64 kernel a native query of a RAM or loop device with 512-byte logical sectors returns the initial soft block size of 4096 bytes, but an i386 process gets 512 bytes. This makes 32-bit blockdev --getbsz and the BSZ column of --report disagree with native queries, even without a preceding BLKBSZSET.
Use block_size() as the native handler and the pre-regression compat handler do, and correct the case comment to describe the soft size.
--- block/ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/ioctl.c +2 -2
@@ -672,8 +672,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)return compat_put_ulong (argp,bdev_nr_sectors (bdev));/* The data is compatible, but the command number is different */ -case BLKBSZGET_32 :/* get the logical block size (cf. BLKSSZGET) */ -return put_int (argp,bdev_logical_block_size (bdev)); +case BLKBSZGET_32 :/* get the soft block size (cf. BLKSSZGET) */ +return put_int (argp,block_size (bdev));case BLKBSZSET_32 :return blkdev_bszset (bdev, mode, argp);case BLKGETSIZE64_32 :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1270/2857 xfs: fix wrong compat fields in xfs_ioctl32_bstat_copyin()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Reid Downing <[email protected]>
[ Upstream commit b7eb276a39b14e685c2fe578f8ac22fc48ff9e6c ]
bs_blocks and bs_xflags were both read from bstat32->bs_size. Read each one from its own field instead.
--- fs/xfs/xfs_ioctl32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_ioctl32.c +2 -2
@@ -122,8 +122,8 @@ xfs_ioctl32_bstat_copyin(xfs_ioctl32_bstime_copyin (&bstat->bs_atime, &bstat32->bs_atime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_mtime, &bstat32->bs_mtime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_ctime, &bstat32->bs_ctime) || -get_user (bstat->bs_blocks, &bstat32->bs_size) || -get_user (bstat->bs_xflags, &bstat32->bs_size) || +get_user (bstat->bs_blocks, &bstat32->bs_blocks) || +get_user (bstat->bs_xflags, &bstat32->bs_xflags) ||get_user (bstat->bs_extsize, &bstat32->bs_extsize) ||get_user (bstat->bs_extents, &bstat32->bs_extents) || get_user(bstat->bs_gen, &bstat32->bs_gen) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1271/2857 blk-iocost: account flush sequence latency only once
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhe Liu <[email protected]>
[ Upstream commit e9804489e27dd6e33aec5511fe3780ff3009f57f ]
A flush sequence with a DATA phase can complete its original request twice. Both completions invoke ioc_rqos_done(), causing the request to contribute two latency samples and adding the same queue wait time twice. This gives such requests disproportionate weight compared to ordinary writes, distorting the device-wide latency and queue wait feedback used to adjust iocost's virtual time rate.
Skip requests marked RQF_FLUSH_SEQ in ioc_rqos_done(). The flag is set when the request enters the flush machinery and is still set when the data phase completes; blk_flush_restore_request() clears it before the final completion, so accounting happens only once, after the whole sequence finishes. The remaining sample covers the request's lifetime through any postflush, and its queue wait time is accumulated only once.
--- block/blk-iocost.c | 3 +++ 1 file changed, 3 insertions(+)
block/blk-iocost.c +3 -0
@@ -2797,6 +2797,9 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq)if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns)return ; +if (unlikely (rq->rq_flags &RQF_FLUSH_SEQ )) +return ; +switch (req_op (rq)) {case REQ_OP_READ : pidx =QOS_RLAT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1272/2857 xfs: mark the inode preallocated for pNFS write layouts past EOF
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 8b8e265991556d99b6d721697f148975a7c68767 ]
xfs_fs_map_blocks() marks the inode XFS_DIFLAG_PREALLOC only when it allocates blocks for a write layout. A write layout past EOF can also hand out allocated blocks, such as speculative preallocation. blockgc then frees them under the layout, and another file may get them.
Mark the inode whenever a write mapping ends past EOF.
--- fs/xfs/xfs_pnfs.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
fs/xfs/xfs_pnfs.c +25 -9
@@ -101,7 +101,15 @@ xfs_fs_map_update_inode( ip->i_diflags |=XFS_DIFLAG_PREALLOC ;xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); -return xfs_trans_commit (tp); + error =xfs_trans_commit (tp); +if (error) +return error; + +/* +* Force the log so that the blocks handed out to the client are +* guaranteed to be present even after a server crash. +*/ +return xfs_log_force_inode (ip); }/*
@@ -126,6 +134,7 @@ xfs_fs_map_blocks(uint lock_flags;int error =0 ;u64 seq; +bool update_inode = false;if (xfs_is_shutdown (mp))return -EIO ;
@@ -194,20 +203,27 @@ xfs_fs_map_blocks( end_fsb - offset_fsb, 0, &imap, &seq);if (error) goto out_unlock; + update_inode = true; + }else { +xfs_iunlock (ip, lock_flags);/* -* Ensure the next transaction is committed synchronously so -* that the blocks allocated and handed out to the client are -* guaranteed to be present even after a server crash. +* Blocks past EOF that were allocated for buffered writes, such +* as speculative preallocation, can be freed by +* xfs_free_eofblocks() without breaking the layout unless the +* inode is marked as preallocated. Mark it before handing them +* out for writing, as for blocks allocated above. */ +if (write && !(ip->i_diflags &XFS_DIFLAG_PREALLOC ) && + imap.br_startoff + imap.br_blockcount > +XFS_B_TO_FSB (mp,XFS_ISIZE (ip))) + update_inode = true; + } + +if (update_inode) { error =xfs_fs_map_update_inode (ip); -if (!error) - error =xfs_log_force_inode (ip);if (error) goto out_unlock; - - }else { -xfs_iunlock (ip, lock_flags); }xfs_iunlock (ip,XFS_IOLOCK_EXCL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1273/2857 xfs: clamp a pNFS LAYOUTCOMMIT extent before computing its end
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit d8c2bc88460f89e543ab3af622fc8f34c7011d71 ]
xfs_fs_commit_blocks() adds the client's length to the offset before it clamps the end to the file size. A large length wraps the sum and reaches xfs_iomap_write_unwritten() unclamped. With the previous two patches the LAYOUTCOMMIT then fails with -EIO and converts nothing.
Clamp the length first.
--- fs/xfs/xfs_pnfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/xfs/xfs_pnfs.c +1 -3
@@ -302,9 +302,7 @@ xfs_fs_commit_blocks(if (start > size)continue ; - end = start + maps[i].length; -if (end > size) - end = size; + end = start +min_t (u64, maps[i].length, size - start); length = end - start;if (!length)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1274/2857 xfs: cap the block count of xfs_iomap_write_direct() at one extent
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 66d1ce09ebd72709f8d739630c39f440445173fd ]
xfs_iomap_write_direct() reserves blocks for the whole count in an unsigned int. For a pNFS layout the client chooses that count, and an RW LAYOUTGET for 16 TiB wraps the reservation and shuts XFS down.
xfs_bmapi_write() maps at most XFS_MAX_BMBT_EXTLEN blocks here, so cap the count at that. nfsd asks again for the rest. The other callers get the same mapping as before.
--- fs/xfs/xfs_iomap.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/xfs/xfs_iomap.c +8 -0
@@ -245,6 +245,14 @@ xfs_iomap_write_direct(ASSERT (count_fsb >0 ); +/* +* xfs_bmapi_write() maps at most XFS_MAX_BMBT_EXTLEN blocks in one +* mapping, so don't reserve blocks for more. A pNFS layout range +* comes from a client, and its block count may not even fit the +* 32-bit reservation. The caller maps the rest with a later call. +*/ + count_fsb =min_t (xfs_filblks_t, count_fsb,XFS_MAX_BMBT_EXTLEN ); + resaligned =xfs_aligned_fsb_count (offset_fsb, count_fsb,xfs_get_extsz_hint (ip));if (unlikely (XFS_IS_REALTIME_INODE (ip))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1275/2857 xfs: clamp the pNFS layout range to the maximum file size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 29f3c1be4e554c9dbc66e13333034e0947477cb6 ]
xfs_fs_map_blocks() lets two bad layout ranges through. An offset of 2^63 or more is negative and passes "offset > limit". A length above the limit, such as NFS4_UINT64_MAX, wraps "offset > limit - length" and stays unclamped. With NFS4_UINT64_MAX, a read layout is built from an uninitialized mapping.
Reject a negative offset and one at the limit, and clamp the length. This needs "xfs: cap the block count of xfs_iomap_write_direct() at one extent".
--- fs/xfs/xfs_pnfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/xfs/xfs_pnfs.c +2 -3
@@ -168,10 +168,9 @@ xfs_fs_map_blocks(if (!write) limit =max (limit,round_up (i_size_read (inode), inode->i_sb->s_blocksize)); -if (offset > limit) +if (offset <0 || offset >= limit) goto out_unlock; -if (offset > limit - length) - length = limit - offset; + length =min_t (u64, length, limit - offset); error =filemap_write_and_wait (inode->i_mapping);if (error)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1276/2857 xfs: fix recovery of partial attr removals
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 30bb61651d2da5a502cf504bcdad16c093c1bb08 ]
When running xfs/753 on parent pointer-enabled file systems with DEBUG enabled, log recovery will eventually crash after a few dozen iterations due to an ASSERT that XFS_ATTR_INCOMPLETE is not already set when xfs_attr3_leaf_setflag is called:
XFS: Assertion failed: (entry->flags & XFS_ATTR_INCOMPLETE) == 0, file: fs/xfs/libxfs/xfs_attr_leaf.c, line: 3045
This is because parent pointer use logged attributes, and the attribute intents do not track the work that has been done as the transaction rolls, and the recovery mechanism is to run the operation from scratch. Because of this various places check for XFS_DA_OP_RECOVERY skip work already done. But while recovery tolerates an attribute already fully removed, it currently trips the above assert for an attribute that already has the INCOMPLETE bit set, but still exists. Fix this by handling the case like all the others.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr_leaf.c +8 -1
@@ -2931,7 +2931,14 @@ xfs_attr3_leaf_setflag(#endif entry = &xfs_attr3_leaf_entryp (leaf)[args->index]; -ASSERT ((entry->flags &XFS_ATTR_INCOMPLETE ) ==0 ); +if (entry->flags &XFS_ATTR_INCOMPLETE ) { +if (!(args->op_flags &XFS_DA_OP_RECOVERY )) { +ASSERT (args->op_flags &XFS_DA_OP_RECOVERY ); +return -EFSCORRUPTED ; + } +return 0 ; + } + entry->flags |=XFS_ATTR_INCOMPLETE ;xfs_trans_log_buf (args->trans, bp,XFS_DA_LOGRANGE (leaf, entry,sizeof (*entry)));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1277/2857 can: isotp: check the frame type, not just the length
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kaixuan Li <[email protected]>
[ Upstream commit 933bf0fcb325e67b19c86c9c4da7f029878d5170 ]
isotp_rcv() separates Classic CAN from CAN FD by skb->len alone:
if (skb->len != so->ll.mtu) return; cf = (struct canfd_frame *)skb->data;
A CAN XL frame with cxl->len 4 is CAN_MTU bytes, so it passes, and is then read as a canfd_frame whose len comes out of canxl_frame.flags: at least 0x80.
Of the paths that follow, only the flow control one uses that length without bounding it first, so check_pad() walks to 255 over a 16-byte frame and the caller reports EBADMSG on an unrelated socket.
bcm_rx_handler(), j1939_can_recv(), can_can_gw_rcv() and raw_rcv() check the frame type here, and can_dropped_invalid_skb() switches on skb->protocol on the transmit side. isotp_rcv() is the gap.
--- net/can/isotp.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/can/isotp.c +8 -0
@@ -722,6 +722,14 @@ static void isotp_rcv(struct sk_buff *skb, void *data)if (skb->len != so->ll.mtu)return ; +/* check for correct CAN CC/FD frame content */ +if (so->ll.mtu ==CAN_MTU ) { +if (!can_is_can_skb (skb)) +return ; + }else if (!can_is_canfd_skb (skb)) { +return ; + } + cf = (struct canfd_frame *)skb->data;/* if enabled: check reception of my configured extended address */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1278/2857 can: dev: can_put_echo_skb(): free skb on invalid echo index
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cunhao Lu <[email protected]>
[ Upstream commit b4ebcbbf66ba6c5816dfe229effb4641c46e4b4c ]
can_put_echo_skb() consumes the skb on all paths except when the echo index is out of bounds. This leaves ownership with the caller on -EINVAL, unlike the other error paths, and can leak the skb if the caller expects consistent semantics.
Free the skb before returning -EINVAL so that all return paths consume it.
---
FAQ:
Q: can_skb_init_valid() directly modifies skb->data without checking if
the SKB is cloned or shared. Is this violating SKB shared buffer rules and causing data corruption?
A: The finding about can_skb_init_valid() modifying skb->data on a
potentially shared buffer is not relevant for this (correct) patch.
The FDF-flag write in can_skb_init_valid() only matters for PF_PACKET
use: PF_CAN allocators already set CANFD_FDF. The write exists to normalize frames for PF_PACKET observers (tcpdump/Wireshark) so they can distinguish classic CAN from CAN FD at the netdev level, and to compensate for PF_PACKET senders that omit the bit. That normalization is functionally required.
The shared-buffer concern only becomes realistic through a specific
chain: a PF_PACKET sender injects a CANFD-sized frame, the CAN driver's loopback puts an echo skb back into can_rcv(), and cgw (without modfuncs) clones it for forwarding to another interface. Only on that second can_skb_init_valid() call is the skb cloned. By then the bit was already set on the exclusive skb during the initial xmit path, so the flags |= CANFD_FDF write is strictly idempotent for any parallel consumer of the shared buffer - no memory-safety or information-disclosure consequence. It's a formal violation of the skb sharing rules without an observable effect, so the current code can stay as-is.
--- drivers/net/can/dev/skb.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/can/dev/skb.c +1 -0
@@ -52,6 +52,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,if (idx >= priv->echo_skb_max) {netdev_err (dev,"%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n" , __func__, idx, priv->echo_skb_max); +dev_kfree_skb_any (skb);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1279/2857 can: isotp: check the return values of can_rx_register() in isotp_bind()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
[ Upstream commit 874f5f14cf626f72477071eff381c8485554250d ]
isotp_bind() ignores the return values of can_rx_register() for the RX and the echo receiver and binds the socket anyway. When a receiver can not be allocated, bind() succeeds without this receiver, so the socket does not receive frames or its transmissions time out. isotp_release() and isotp_notify() later try to remove the missing receiver, which triggers the "receive list entry not found" warning in can_rx_unregister().
As the device has been checked before and RTNL prevents a namespace change during bind(), only -ENOMEM can be returned here.
Check the return values and register the RX receiver as the last step. The echo receiver is registered first, as it only handles the socket's own echo frames and does nothing while no transmission is in progress. So a failed RX registration only needs to remove the echo receiver, and isotp_rcv() has never processed a frame for this socket.
Set so->ifindex before the registrations, so that a First Frame received before so->bound is set can be answered with a Flow Control frame and the RX timeout is started as usual. As the RX receiver is registered last, this can only happen for a bind() that succeeds. Reset so->ifindex when bind() fails.
Check IFF_UP only after the receivers have been registered, so that a bind() that fails on a down device does not report ENETDOWN. As bind() holds RTNL, the device state can not change in between.
--- net/can/isotp.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-)
net/can/isotp.c +27 -15
@@ -1488,7 +1488,6 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)struct sock *sk = sock->sk;struct isotp_sock *so =isotp_sk (sk);struct net *net =sock_net (sk); -int ifindex;struct net_device *dev;canid_t tx_id = addr->can_addr.tp.tx_id;canid_t rx_id = addr->can_addr.tp.rx_id;
@@ -1565,26 +1564,36 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) err = -EINVAL ; goto out_put_dev; } -if (!(dev->flags &IFF_UP )) - notify_enetdown =1 ; - ifindex = dev->ifindex; - -if (isotp_register_rxid (so)) -can_rx_register (net, dev, rx_id,SINGLE_MASK (rx_id), - isotp_rcv, sk,"isotp" , sk); +/* switch to new settings */ + so->ifindex = dev->ifindex; + so->rxid = rx_id; + so->txid = tx_id;/* no consecutive frame echo skb in flight */ WRITE_ONCE (so->cfecho,0 ); -/* register for echo skb's */ -can_rx_register (net, dev, tx_id,SINGLE_MASK (tx_id), - isotp_rcv_echo, sk,"isotpe" , sk); +/* register for echo skb's first (no echo traffic at this point) */ + err =can_rx_register (net, dev, tx_id,SINGLE_MASK (tx_id), + isotp_rcv_echo, sk,"isotpe" , sk); +if (err) + goto out_put_dev; + +if (isotp_register_rxid (so)) { + err =can_rx_register (net, dev, rx_id,SINGLE_MASK (rx_id), + isotp_rcv, sk,"isotp" , sk); +if (err) { +/* unregister echo skb subscription */ +can_rx_unregister (net, dev, tx_id,SINGLE_MASK (tx_id), + isotp_rcv_echo, sk); + goto out_put_dev; + } + } + +/* report a down device only for a successful bind() */ +if (!(dev->flags &IFF_UP )) + notify_enetdown =1 ; -/* switch to new settings */ - so->ifindex = ifindex; - so->rxid = rx_id; - so->txid = tx_id; so->bound =1 ;/* bind() ok -> hold a reference for so->dev so that isotp_release()
@@ -1595,6 +1604,9 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)dev_hold (so->dev); out_put_dev: +if (err) + so->ifindex =0 ;/* reset on failed bind() */ +/* remove potential reference from dev_get_by_index() */ dev_put (dev); out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1280/2857 can: proc: reset pkg_stats atomics individually
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 12297f855bbd943847cb8893a3614caef5a9c2a8 ]
Commit 80b5f90158d1 ("can: statistics: use atomic access in hot path") converted several members of struct can_pkg_stats to atomic_long_t and updated the hot TX/RX and procfs read paths to use atomic_long_*() helpers. However, can_init_stats() still clears the whole struct with memset().
can_init_stats() is reached from can_stat_update() in timer context and also from the procfs reset path. Those paths can run while the TX/RX hot paths are concurrently updating rx_frames, tx_frames, matches and their *_delta counters. Hitting the whole-struct memset() in that window performs plain writes to fields that otherwise follow an atomic_long_t access contract, which can lose or mix live statistics updates.
This issue was found by source-level API-misuse analysis looking for whole-object resets left behind after atomic_long_t conversions, then manually audited on Linux v6.18.21.
Replace the whole-struct memset() with a helper that resets the atomic_long_t counters via atomic_long_set() and clears the derived scalar statistics explicitly. This preserves the existing reset semantics for scalar fields while restoring atomic access discipline for the live counters.
Build-tested by compiling net/can/proc.o on x86_64 netdev/main. Runtime-tested with a QEMU + vcan setup on Linux v6.18.21 by driving concurrent traffic and reset_stats reads, which reproduced inconsistent exported statistics before the fix.
[Hartkopp] can_stat_update() also read the *_delta counters at the beginning and cleared them with atomic_long_set() at the end. Increments from the hot path in between were lost for both the current and the next interval. Use atomic_long_xchg() to fetch and clear the *_delta counters in one atomic step instead.
On x86_64 atomic_long_set() is a plain store like memset(), so the memset() is an actual problem only on architectures with lock-based atomics (e.g. parisc). The inconsistencies seen on x86_64 come from the *_delta handling and from the stale snapshots, which are fixed in "can:
proc: skip stats calculation after reset in can_stat_update()". As before, the counters are reset one at a time and the derived scalar statistics use plain stores.
--- net/can/proc.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-)
net/can/proc.c +29 -10
@@ -76,16 +76,39 @@ static const char rx_list_name[][8] = {* af_can statistics stuff */ +static void can_reset_pkg_stats (struct can_pkg_stats *pkg_stats) +{ +atomic_long_set (&pkg_stats->rx_frames,0 ); +atomic_long_set (&pkg_stats->tx_frames,0 ); +atomic_long_set (&pkg_stats->matches,0 ); + + pkg_stats->total_rx_rate =0 ; + pkg_stats->total_tx_rate =0 ; + pkg_stats->total_rx_match_ratio =0 ; + + pkg_stats->current_rx_rate =0 ; + pkg_stats->current_tx_rate =0 ; + pkg_stats->current_rx_match_ratio =0 ; + + pkg_stats->max_rx_rate =0 ; + pkg_stats->max_tx_rate =0 ; + pkg_stats->max_rx_match_ratio =0 ; + +atomic_long_set (&pkg_stats->rx_frames_delta,0 ); +atomic_long_set (&pkg_stats->tx_frames_delta,0 ); +atomic_long_set (&pkg_stats->matches_delta,0 ); +} +static void can_init_stats (struct net *net) {struct can_pkg_stats *pkg_stats = net->can.pkg_stats;struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;/* -* This memset function is called from a timer context (when +* This stats reset is called from a timer context (when * can_stattimer is active which is the default) OR in a process * context (reading the proc_fs when can_stattimer is disabled). */ -memset (pkg_stats,0 ,sizeof (struct can_pkg_stats )); +can_reset_pkg_stats (pkg_stats); pkg_stats->jiffies_init = jiffies; rcv_lists_stats->stats_reset++;
@@ -121,9 +144,10 @@ void can_stat_update(struct timer_list *t)long rx_frames =atomic_long_read (&pkg_stats->rx_frames);long tx_frames =atomic_long_read (&pkg_stats->tx_frames);long matches =atomic_long_read (&pkg_stats->matches); -long rx_frames_delta =atomic_long_read (&pkg_stats->rx_frames_delta); -long tx_frames_delta =atomic_long_read (&pkg_stats->tx_frames_delta); -long matches_delta =atomic_long_read (&pkg_stats->matches_delta); +/* fetch and clear values for 'current rate' calculation */ +long rx_frames_delta =atomic_long_xchg (&pkg_stats->rx_frames_delta,0 ); +long tx_frames_delta =atomic_long_xchg (&pkg_stats->tx_frames_delta,0 ); +long matches_delta =atomic_long_xchg (&pkg_stats->matches_delta,0 );/* restart counting in timer context on user request */ if (user_reset)
@@ -172,11 +196,6 @@ void can_stat_update(struct timer_list *t)if (pkg_stats->max_rx_match_ratio < pkg_stats->current_rx_match_ratio) pkg_stats->max_rx_match_ratio = pkg_stats->current_rx_match_ratio; -/* clear values for 'current rate' calculation */ -atomic_long_set (&pkg_stats->tx_frames_delta,0 ); -atomic_long_set (&pkg_stats->rx_frames_delta,0 ); -atomic_long_set (&pkg_stats->matches_delta,0 ); -/* restart timer (one second) */ mod_timer (&net->can.stattimer,round_jiffies (jiffies +HZ )); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1281/2857 can: proc: skip stats calculation after reset in can_stat_update()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
[ Upstream commit 01b19ed9fa031a649f3dd103ebe6e0102602e542 ]
Commit 80b5f90158d1 ("can: statistics: use atomic access in hot path") introduced local snapshots of the statistics counters at the beginning of can_stat_update(). When can_init_stats() resets the statistics, these stale pre-reset snapshots are still used for the following total/current /max calculations and overwrite the freshly reset values. Additionally a jiffies tick between the snapshot and the reset could trigger a second can_init_stats() call.
Merge the reset conditions into a single check and skip the calculation for the current interval when the statistics have been reset.
--- net/can/proc.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
net/can/proc.c +12 -18
@@ -149,25 +149,18 @@ void can_stat_update(struct timer_list *t)long tx_frames_delta =atomic_long_xchg (&pkg_stats->tx_frames_delta,0 );long matches_delta =atomic_long_xchg (&pkg_stats->matches_delta,0 ); -/* restart counting in timer context on user request */ -if (user_reset) -can_init_stats (net); - -/* restart counting on jiffies overflow */ -if (j < pkg_stats->jiffies_init) -can_init_stats (net); - -/* prevent overflow in calc_rate() */ -if (rx_frames > (LONG_MAX /HZ )) -can_init_stats (net); - -/* prevent overflow in calc_rate() */ -if (tx_frames > (LONG_MAX /HZ )) -can_init_stats (net); - -/* matches overflow - very improbable */ -if (matches > (LONG_MAX /100 )) +/* +* Restart counting in timer context on user request, on jiffies +* overflow or to prevent overflows in calc_rate() and in the +* match ratio calculation. The local snapshots are stale after +* the reset, so skip the calculation for this interval. +*/ +if (user_reset || j < pkg_stats->jiffies_init || + rx_frames > (LONG_MAX /HZ ) || tx_frames > (LONG_MAX /HZ ) || + matches > (LONG_MAX /100 )) {can_init_stats (net); + goto out; + }/* calc total values */ if (rx_frames)
@@ -196,6 +189,7 @@ void can_stat_update(struct timer_list *t)if (pkg_stats->max_rx_match_ratio < pkg_stats->current_rx_match_ratio) pkg_stats->max_rx_match_ratio = pkg_stats->current_rx_match_ratio; +out:/* restart timer (one second) */ mod_timer (&net->can.stattimer,round_jiffies (jiffies +HZ )); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1282/2857 can: dev: can_fill_info(): dont wake up controller if interface is down
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: ChunYuZhiQiang <[email protected]>
[ Upstream commit 75332c410c8190d61499001c5516af977ca426c3 ]
If the interface is down, the CAN controller might be powered down and its clocks gated. Don't call do_get_berr_counter() to read the bus error counters if the interface is down, and adjust can_get_size() to match.
This removes one trigger for a synchronous external abort seen on i.MX8QXP when "ip link show" is run on a flexcan interface that was never brought up. The underlying cause is platform-specific: on i.MX8QXP the CAN clocks are gated through the SCU LPCG and the subsystem shares the IMX_SC_R_CAN_0 power domain, and there is a window after pm_runtime_resume_and_get() returns where the clock has not reached the module yet. This patch avoids the netlink query path while the interface is down, but does not root-cause the LPCG window itself.
As a result, IFLA_CAN_BERR_COUNTER is no longer reported for down interfaces. Userspace must treat the attribute as optional.
The issue was triggered on an i.MX8QXP board by running "ip link show" without ever bringing the interface up:
Internal error: synchronous external abort: 0000000096000210
pc : flexcan_read_le+0x0/0x18
lr : flexcan_get_berr_counter+0x4c/0x8c
Call trace:
flexcan_read_le+0x0/0x18
flexcan_get_berr_counter+0x4c/0x8c
can_fill_info+0x1f8/0x434
rtnl_fill_ifinfo+0x8fc/0xbb4
rtnl_dump_ifinfo+0x364/0x448This is the same class of problem fixed for m_can in commit 91a55c72a821 ("can: m_can: m_can_get_berr_counter(): don't wake up controller if interface is down").
--- drivers/net/can/dev/netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/dev/netlink.c +2 -2
@@ -419,7 +419,7 @@ static size_t can_get_size(const struct net_device *dev) size +=nla_total_size (sizeof (u32));/* IFLA_CAN_STATE */ size +=nla_total_size (sizeof (struct can_ctrlmode ));/* IFLA_CAN_CTRLMODE */ size +=nla_total_size (sizeof (u32));/* IFLA_CAN_RESTART_MS */ -if (priv->do_get_berr_counter)/* IFLA_CAN_BERR_COUNTER */ +if (priv->do_get_berr_counter &&netif_running (dev))/* IFLA_CAN_BERR_COUNTER */ size +=nla_total_size (sizeof (struct can_berr_counter ));if (priv->data_bittiming.bitrate)/* IFLA_CAN_DATA_BITTIMING */ size +=nla_total_size (sizeof (struct can_bittiming ));
@@ -539,7 +539,7 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)nla_put (skb,IFLA_CAN_CTRLMODE ,sizeof (cm), &cm) ||nla_put_u32 (skb,IFLA_CAN_RESTART_MS , priv->restart_ms) || - (priv->do_get_berr_counter && + (priv->do_get_berr_counter &&netif_running (dev) && !priv->do_get_berr_counter (dev, &bec) && nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1283/2857 can: peak_usb: pcan_usb_fd_decode_buf(): accept short uCAN end-of-list records
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Changjie <[email protected]>
[ Upstream commit 2d4c272e816a5b784f1fc7899256f8826df34edb ]
A PCAN-USB FD v2 running firmware 3.2.0 sends a 16-byte status record followed by a four-byte zero-size end marker.
Since commit 93fcab2c6968 ("can: peak_usb: validate uCAN receive record lengths") these transfers cause repeated receive-buffer dumps while the interface is up.
This has been observed on Linux 7.2.11-arch1-1 with matching kernel headers:
- Classic CAN, 500 kbit/s: 25 decoder errors in 5 s before the fix; none in 15 s after.
- CAN FD, 500 kbit/s nominal and 2 Mbit/s data: 26 decoder errors in 5 s before the fix; none in 60 s after.
- Three additional down/up cycles: no decoder errors.
pcan_usb_fd_decode_buf() requires a complete 12-byte struct pucan_msg before checking the size field, so it rejects the end marker with -EBADMSG.
Check that the size field is present before testing for an end marker. Require the full header for nonzero-size records and keep the remaining record and payload length checks.
This patch was created with LLM assistance.
---
Built and tested the original and patched peak_usb modules on Arch Linux 7.2.11-arch1-1 with matching kernel headers.
- Classic CAN, 500 kbit/s: 25 decoder errors in 5 s before the fix; none in 15 s after.
- CAN FD, 500 kbit/s nominal and 2 Mbit/s data: 26 decoder errors in 5 s before the fix; none in 60 s after.
- Three additional down/up cycles: no decoder errors.
USB captures during the patched tests contained 406 packets with short end markers. Neither receive-buffer dump recurred.
The CAN bus was disconnected; external TX/RX was not tested. One startup "can_change_state: oops, state did not change" message and an RX dropped count reaching 2 were observed during the patched tests. Their causes remain undetermined.
--- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/can/usb/peak_usb/pcan_usb_fd.c +6 -1
@@ -708,7 +708,7 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)u16 rx_msg_type, rx_msg_size;size_t rx_msg_min_size; -if (msg_end - msg_ptr <sizeof (*rx_msg)) { +if (msg_end - msg_ptr <sizeof (rx_msg->size)) { err = -EBADMSG ;break ; }
@@ -719,6 +719,11 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)break ; } +if (msg_end - msg_ptr <sizeof (*rx_msg)) { + err = -EBADMSG ; +break ; + } + rx_msg_size =le16_to_cpu (rx_msg->size); rx_msg_type =le16_to_cpu (rx_msg->type);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1284/2857 mm/gup: fix out-of-bounds write for nr_pages == 0 in GUP-fast
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 1dfe4b276c23189394afb42d114ee8a54cc3aff2 ]
With nr_pages == 0, GUP-fast still enters its page table walk and can write past the caller's page array. The old end <= start check caught empty ranges, but was replaced with an overflow check.
Users such as OrangeFS can pass a zero page count derived from a userspace-supplied length. So let's return zero for nr_pages == 0 before starting the walk, just like GUP-slow.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/gup.c | 3 +++ 1 file changed, 3 insertions(+)
mm/gup.c +3 -0
@@ -3055,6 +3055,9 @@ static int internal_get_user_pages_fast(unsigned long start, FOLL_FAST_ONLY | FOLL_NOFAULT)))return -EINVAL ; +if (unlikely (!nr_pages)) +return 0 ; +if (gup_flags &FOLL_PIN )mm_set_has_pinned_flag (¤t->mm->flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1285/2857 mm/mmu_gather: fix flushing ranges with 4 GiB or larger
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 64ae7959a1df8af8eec504e31df2ec9670424a4e ]
__tlb_adjust_range() takes the size of the range which has to be flushed as an unsigned int. Its callers, tlb_flush_{pte,pmd,pud,p4d}_range(), get and pass an unsigned long. Consequently, a range that is 4 GiB or larger gets truncated, possibly to 0.
On arm64 with hugetlb, a 64k kernel can have 16 GiB hugetlb folios mapped contiguously at the PMD level and flush them when unmapping, and a 16k kernel can flush 64 GiB PUDs through tlb_unshare_pmd_ptdesc(). So at least these two scenarios are affected.
Fix it by flushing the proper range instead of the truncated one by properly using "unsigned long" for range_size.
Fix generated by an LLM and sent by Josef Bacik in private.
--- include/asm-generic/tlb.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/asm-generic/tlb.h +1 -2
@@ -340,8 +340,7 @@ struct mmu_gather {void tlb_flush_mmu (struct mmu_gather *tlb);static inline void __tlb_adjust_range (struct mmu_gather *tlb, -unsigned long address, -unsigned int range_size) +unsigned long address,unsigned long range_size) { tlb->start =min (tlb->start, address); tlb->end =max (tlb->end, address + range_size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1286/2857 mm/mmu_notifier: set ->mm only after mmgrab()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 5ad9e4b0f1104f5dbfb41125c34bb30ea6dc7a94 ]
Radeon uses a non-NULL notifier->mm to decide whether to call mmu_interval_notifier_remove() when freeing a buffer object. __mmu_interval_notifier_insert() sets ->mm before validating the range, so a wrapping userptr range can leave ->mm set after insertion fails. Cleanup then tries to remove an unregistered notifier for which no mm reference was acquired.
Set ->mm only after mmgrab(), once insertion can no longer fail. While we could fix radeon's code instead, setting ->mm on success only makes the code more robust.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/mmu_notifier.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
mm/mmu_notifier.c +5 -2
@@ -915,7 +915,6 @@ static int __mmu_interval_notifier_insert( struct mmu_notifier_subscriptions *subscriptions, unsigned long start, unsigned long length, const struct mmu_interval_notifier_ops *ops) { - interval_sub->mm = mm; interval_sub->ops = ops;RB_CLEAR_NODE (&interval_sub->interval_tree.rb); interval_sub->interval_tree.start = start;
@@ -932,8 +931,12 @@ static int __mmu_interval_notifier_insert(if (WARN_ON (atomic_read (&mm->mm_users) <=0 ))return -EINVAL ; -/* pairs with mmdrop in mmu_interval_notifier_remove() */ +/* +* Pairs with mmdrop in mmu_interval_notifier_remove(). Drivers take a +* non-NULL ->mm for "registered", so set it only with the reference. +*/ mmgrab (mm); + interval_sub->mm = mm;/* * If some invalidate_range_start/end region is going on in parallel
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1287/2857 mm: fix unmap_mapping_range() beyond 4 GiB on 32-bit
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 7a81bc23dade8082187be6d9cc36e4be4b7207e2 ]
Commit 9eab0421fa94 ("mm: fix unmap_mapping_range high bits shift bug") made holebegin and holelen unsigned before they are shifted, by casting them to pgoff_t. That is an unsigned long: on a 32-bit kernel the cast cuts off the upper half of the two loff_t values, so a hole which begins at 4 GiB or beyond is taken for one in the first 4 GiB of the file.
truncate_pagecache() passes the new size of the file and asks for private COWed pages to be unmapped as well. If a file of 6 GiB is truncated to 5 GiB, everything from 1 GiB on is unmapped, and what a process has written to a private mapping of the range between 1 GiB and 5 GiB is
lost: it reads the contents of the file again.
Where the range has an end, the wrong range is unmapped instead of the right one. The page cache copes with that, as it unmaps every folio that it removes. The callers which only have unmap_mapping_range() to get rid of user mappings do not, for example drm_vma_node_unmap(), whose fake offsets reach beyond 4 GiB on 32-bit, and revoke_iomem() with physical addresses of more than 32 bits.
Cast to u64 instead. Nothing changes for 64-bit kernels.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +2 -2
@@ -3634,8 +3634,8 @@ EXPORT_SYMBOL_GPL(unmap_mapping_pages);void unmap_mapping_range (struct address_space *mapping,loff_t const holebegin,loff_t const holelen,int even_cows) { -pgoff_t hba = (pgoff_t)(holebegin) >>PAGE_SHIFT ; -pgoff_t hlen = ((pgoff_t)(holelen) +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +pgoff_t hba = (u64 )holebegin >>PAGE_SHIFT ; +pgoff_t hlen = ((u64 )holelen +PAGE_SIZE -1 ) >>PAGE_SHIFT ;/* Check for overflow. */ if (sizeof (holelen) >sizeof (hlen)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1288/2857 mm/ksm: reset the unstable trees of all nodes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 890e118e95bfc2aae4432ec2a95192d6f9193211 ]
Each full scan resets ksm_nr_node_ids unstable tree roots. Enabling merge_across_nodes resets this count to 1, even if per-node roots were previously allocated.
So when toggling "merge_across_nodes" 0 -> 1 -> 0, a scan that starts while the setting is 1 and continues after switching back to 0 can encounter stale unstable tree roots, resulting in UAF.
Only root is allowed to change "merge_across_nodes", and the documented sequence is: "merge_across_nodes setting can be changed only when there are no ksm shared pages in the system: set run 2 to unmerge pages first, then to 1 after changing merge_across_nodes, to remerge according to the new setting."
Let's fix it by tracking in ksm_nr_node_ids the actual number of allocated tree roots.
remove_all_stable_nodes() and ksm_check_stable_tree() will now scan more tree roots (skipping the empty ones), which is harmless.
--- mm/ksm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/ksm.c +3 -3
@@ -278,6 +278,7 @@ static bool ksm_use_zero_pages __read_mostly;#ifdef CONFIG_NUMA /* Zeroed when merging across nodes is not allowed */ static unsigned int ksm_merge_across_nodes =1 ; +/* Number of allocated stable and unstable tree roots. */ static int ksm_nr_node_ids =1 ;#else #define ksm_merge_across_nodes 1U
@@ -3093,14 +3094,13 @@ static ssize_t merge_across_nodes_store(struct kobject *kobj,else { root_stable_tree = buf; root_unstable_tree = buf + nr_node_ids; + ksm_nr_node_ids = nr_node_ids;/* Stable tree is empty but not the unstable */ root_unstable_tree[0 ] = one_unstable_tree[0 ]; } } -if (!err) { +if (!err) ksm_merge_across_nodes = knob; - ksm_nr_node_ids = knob ?1 : nr_node_ids; - } }mutex_unlock (&ksm_thread_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1289/2857 ipv6: fix device binding after failed datagram connect
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xia Yan <[email protected]>
[ Upstream commit bc53aab4881adc134f495092034e9e7c0791d84c ]
__ip6_datagram_connect() can change sk_bound_dev_if when connecting to an address that needs a scope ID. If ip6_datagram_dst_update() fails, the old peer address and port are restored, but the new device binding is left behind.
A UDP socket can then keep reporting its original peer while sends and attempts to reconnect to that peer fail with ENETUNREACH. Replies to the socket are also dropped by the device match. The same problem occurs when a scoped multicast destination picks up np->mcast_oif.
Save the original binding before processing the scope and restore it along with the peer information on failure. This completes the rollback in commit 2f987a76a977 ("net: ipv6: keep sk status consistent after datagram connect failure") and preserves the new binding on success.
Found while reviewing scope-ID handling in __ip6_datagram_connect().
Confirmed by exchanging UDP traffic over ::1, then attempting a link-local connect with a nonexistent scope ifindex or a down interface. After that connect fails, the original peer is still reported but communication and reconnecting to it fail.
Tested before and after the fix in UML for three rounds, covering explicit scopes, multicast interface fallback, initially unconnected sockets and existing bindings. With the fix, the old binding and peer are retained, and traffic and reconnection to the original peer work. Also built on x86_64 with W=1 using adjusted allmodconfig and allyesconfig configurations, with no new warnings.
--- net/ipv6/datagram.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/datagram.c +4 -0
@@ -146,6 +146,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr,__be32 fl6_flowlabel =0 ;__be32 old_fl6_flowlabel;__be16 old_dport; +int old_bound_dev_if;int addr_type;int err;
@@ -216,6 +217,8 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, goto out; } + old_bound_dev_if = sk->sk_bound_dev_if; +if (__ipv6_addr_needs_scope_id (addr_type)) {if (addr_len >=sizeof (struct sockaddr_in6 ) && usin->sin6_scope_id) {
@@ -258,6 +261,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, sk->sk_v6_daddr = old_daddr; np->flow_label = old_fl6_flowlabel; inet->inet_dport = old_dport; +WRITE_ONCE (sk->sk_bound_dev_if, old_bound_dev_if); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1290/2857 net/sched: clamp skb->queue_mapping before indexing the tx queue
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit f19f2b308beb158d0e6f6eb806ced636e4ebf6ce ]
This issue was caught by Sashiko (nipa). A producer-side path cap is already merged (ea4d4b5dddb5); this patch adds the matching consumer-side caps.
The issue:
The tx queue is picked and capped in netdev_core_pick_tx() before the __dev_xmit_skb() qdisc enqueue path. A tc BPF program running inside an egress qdisc (not clsact) can then change __sk_buff->queue_mapping; that store is never re-checked. bpf_convert_ctx_access() bounds it only by NO_QUEUE_MAPPING, not by the device's queue count.
Two consumers read the stale value:
- On dequeue, qdisc_restart() calls netdev_get_tx_queue(), which indexes dev->_tx[]. netdev_get_tx_queue() guards it with just a DEBUG_NET_WARN_ON_ONCE, so sch_direct_xmit() takes the out-of-bounds txq->_xmit_lock and writes txq->xmit_lock_owner past the end of the allocation on non-lltx devices such as ifb. Drivers that index their rings from skb_get_queue_mapping() (ex: ifb) go out of range the same way.
- On enqueue, taprio_enqueue() indexes q->qdiscs[] with the same value; the array is sized dev->num_tx_queues. A duplicating netem on a child qdisc clones the skb and re-enqueues the clone at the taprio root (qdisc_root_bh()) through a direct rootq->enqueue() call, so the value reaches taprio_enqueue() before any dequeue cap runs.
The Fix:
Cap the mapping at the consumers and write the capped value back, so the qdisc's _tx[] lookup, the taprio q->qdiscs[] lookup and any later driver read stay in range.
On the dequeue side the cap folds into the dequeue path instead of a separate walk over the returned list: dequeue_skb() caps the head, and each bulk helper caps the element it appends. For a qdisc that is not TCQ_F_ONETXQUEUE, netdev_cap_txqueue() logs a ratelimited notice and selects queue 0.
A TCQ_F_ONETXQUEUE qdisc is bound to a single tx queue: dequeue_skb() uses q->dev_queue for the frozen check, the BQL limit and the trace point, while qdisc_restart() transmits on the skb's queue. Capping an out-of-range mapping to queue 0 would therefore send a per-queue child's skb through a different queue than the one it was dequeued for. On mq, mqprio, taprio and htb offload children, a stopped queue 0 could then park the list in q->gso_skb, and the later wake would schedule queue 0's own child instead of this qdisc. Pin a TCQ_F_ONETXQUEUE mapping to the qdisc's own queue to keep the documented invariant.
The pin covers every mapping, not only an out-of-range one: an in-range mapping that a filter sets on one of those per-queue children is rewritten to the child's own queue, and this path does not call netdev_cap_txqueue(), so it logs no notice. On a single-queue device qdisc_create() sets TCQ_F_ONETXQUEUE, so the one-queue trigger described below also takes this branch and is corrected without a notice.
That also keeps a bulk list on one queue by construction: every element of a TCQ_F_ONETXQUEUE qdisc, including a follower changed by a filter, is pinned to q->dev_queue before it is appended. The fast bulk helper therefore needs no head comparison and no skb_bad_txq requeue; the slow helper, used only by non-ONETXQUEUE qdiscs, still compares and requeues a mismatched follower, where a wake on any queue reschedules q.
On the enqueue side taprio_enqueue() caps the mapping against real_num_tx_queues and writes it back before selecting q->qdiscs[queue], so a duplicating child cannot steer the clone out of the array.
Conditions to recreate the bug:
The dequeue path: load a SCHED_CLS or SCHED_ACT program that stores __sk_buff->queue_mapping (a tc BPF action is enough), attach it to a transmit qdisc (for example a matchall filter on a prio root), and send a packet. With a 1-queue device a store of 1 indexes one past dev->_tx[]. Under KASAN with panic_on_warn=1 the unfixed kernel faults with "BUG:
KASAN: slab-out-of-bounds in sch_direct_xmit". Loading the program needs
CAP_BPF/CAP_SYS_ADMIN, so the trigger is root.
The enqueue path: on a multi-queue device, install a software taprio root, graft a prio child with a duplicating netem on every class, and store an out-of-range queue_mapping from a matchall+bpf filter on the prio. The duplicate is re-enqueued at the taprio root and indexes q->qdiscs[] past dev->num_tx_queues; the unfixed kernel faults in taprio_enqueue_one(). Same CAP_BPF/CAP_SYS_ADMIN requirement.
--- net/sched/sch_generic.c | 41 ++++++++++++++++++++++++++++++++++++----- net/sched/sch_taprio.c | 5 +++++ 2 files changed, 41 insertions(+), 5 deletions(-)
net/sched/sch_generic.c +36 -5
@@ -69,9 +69,34 @@ static void qdisc_maybe_clear_missed(struct Qdisc *q,#define SKB_XOFF_MAGIC ((struct sk_buff *)1UL) +/* Re-cap a stale queue_mapping; an ONETXQUEUE qdisc pins q->dev_queue. */ +static u16 qdisc_cap_skb_tx_queue (struct Qdisc *q,struct sk_buff *skb) +{ +u16 queue =skb_get_queue_mapping (skb); +struct net_device *dev =qdisc_dev (q); +u16 capped; + +if (q->flags &TCQ_F_ONETXQUEUE ) + capped = q->dev_queue -netdev_get_tx_queue (dev,0 ); +else + capped =netdev_cap_txqueue (dev, queue); + +if (unlikely (capped != queue)) +skb_set_queue_mapping (skb, capped); + +return capped; +} + +static struct netdev_queue *skb_cap_tx_queue (struct Qdisc *q, +struct sk_buff *skb) +{ +return netdev_get_tx_queue (qdisc_dev (q), +qdisc_cap_skb_tx_queue (q, skb)); +} +static inline struct sk_buff *__skb_dequeue_bad_txq (struct Qdisc *q) { -const struct netdev_queue *txq = q->dev_queue; +const struct netdev_queue *txq;spinlock_t *lock =NULL ;struct sk_buff *skb;
@@ -83,7 +108,8 @@ static inline struct sk_buff *__skb_dequeue_bad_txq(struct Qdisc *q) skb =skb_peek (&q->skb_bad_txq);if (skb) {/* check the reason of requeuing without tx lock first */ - txq =skb_get_tx_queue (txq->dev, skb); +/* re-cap: real_num_tx_queues may have shrunk */ + txq =skb_cap_tx_queue (q, skb);if (!netif_xmit_frozen_or_stopped (txq)) { skb =__skb_dequeue (&q->skb_bad_txq);if (qdisc_is_percpu_stats (q)) {
@@ -197,6 +223,8 @@ static void try_bulk_dequeue_skb(struct Qdisc *q,if (!nskb)break ; +/* Every element of an ONETXQUEUE qdisc is pinned to q->dev_queue. */ +qdisc_cap_skb_tx_queue (q, nskb); bytelimit -= nskb->len;/* covers GSO len */ skb->next = nskb; skb = nskb;
@@ -214,7 +242,6 @@ static void try_bulk_dequeue_skb_slow(struct Qdisc *q,struct sk_buff *skb, int *packets) { - int mapping = skb_get_queue_mapping(skb); struct sk_buff *nskb;int cnt =0 ;
@@ -222,7 +249,9 @@ static void try_bulk_dequeue_skb_slow(struct Qdisc *q, nskb = q->dequeue (q);if (!nskb)break ; -if (unlikely (skb_get_queue_mapping (nskb) != mapping)) { +/* A tc BPF store may have changed the mapping; cap it. */ +if (unlikely (qdisc_cap_skb_tx_queue (q, nskb) != +skb_get_queue_mapping (skb))) {qdisc_enqueue_skb_bad_txq (q, nskb);break ; }
@@ -267,7 +296,7 @@ static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate,if (xfrm_offload (skb)) *validate = true;/* check the reason of requeuing without tx lock first */ - txq =skb_get_tx_queue (txq->dev, skb); + txq =skb_cap_tx_queue (q, skb);if (!netif_xmit_frozen_or_stopped (txq)) { skb =__skb_dequeue (&q->gso_skb);if (qdisc_is_percpu_stats (q)) {
@@ -303,6 +332,8 @@ static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate, skb = q->dequeue (q);if (skb) { bulk: +/* cap the head; the bulk helpers cap every appended element */ +qdisc_cap_skb_tx_queue (q, skb);if (qdisc_may_bulk (q))try_bulk_dequeue_skb (q, skb, txq, packets, budget);else
net/sched/sch_taprio.c +5 -0
@@ -453,6 +453,11 @@ static int taprio_enqueue(struct sk_buff *skb, struct Qdisc *sch,int queue; queue =skb_get_queue_mapping (skb); +if (unlikely (queue >=qdisc_dev (sch)->real_num_tx_queues)) { +/* A tc BPF program may have stored an out-of-range mapping. */ + queue =netdev_cap_txqueue (qdisc_dev (sch), queue); +skb_set_queue_mapping (skb, queue); + } child = q->qdiscs[queue];if (unlikely (!child))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1291/2857 drm/amdgpu: parse CS IBs at the BO offset their VA mapping starts at
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 63a59637517682a920f86da1a189a3e639dd4fb3 ]
For rings which parse or patch the IBs on the CPU, like JPEG and VCN, the CS looks the IB up through its VA mapping and maps the BO, but ignores the offset in the BO the mapping starts at. It then parses other data than the GPU executes. On navi31, an IB of JPEG NOPs in the second page of a BO, mapped with offset_in_bo 4096, is parsed from the zeros in the first page and rejected:
amdgpu 0000:03:00.0: Invalid packet [0x00000000]!
while the same IB submitted through a mapping of the whole BO works.
Add the mapping offset when locating the IB in the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -1071,7 +1071,7 @@ static int amdgpu_cs_patch_ibs(struct amdgpu_cs_parser *p,if (r)return r; - kptr += va_start - (m->start *AMDGPU_GPU_PAGE_SIZE ); + kptr += va_start - (m->start *AMDGPU_GPU_PAGE_SIZE ) + m->offset;if (ring->funcs->parse_cs) {memcpy (ib->ptr, kptr, ib->length_dw *4 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1292/2857 drm/amdgpu: clear RB_OVERFLOW bit when enabling interrupts for navi10_ih
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Milan Milicevic <[email protected]>
[ Upstream commit 146b96974b33b8cca52755ffed3cd24a82836013 ]
Port this change to navi10_ih.c:
commit afbf7955ff01 ("drm/amdgpu: clear RB_OVERFLOW bit when enabling interrupts")
Setting IH_RB_WPTR to 0 does not clear RB_OVERFLOW if RB_ENABLE is not set. Pulse WPTR_OVERFLOW_CLEAR after RB_ENABLE (and with WPTR_OVERFLOW_ENABLE) so overflow is cleared when interrupts are enabled.
--- drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +28 -0
@@ -161,6 +161,34 @@ static int navi10_ih_toggle_ring_interrupts(struct amdgpu_device *adev, tmp =RREG32 (ih_regs->ih_rb_cntl); tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,RB_ENABLE , (enable ?1 :0 )); tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,RB_GPU_TS_ENABLE ,1 ); + +if (enable) { +/* Unset the CLEAR_OVERFLOW bit to make sure the next step +* is switching the bit from 0 to 1 +*/ + tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,WPTR_OVERFLOW_CLEAR ,0 ); +if (amdgpu_sriov_vf (adev) &&amdgpu_sriov_reg_indirect_ih (adev)) { +if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) +return -ETIMEDOUT ; + }else { +WREG32_NO_KIQ (ih_regs->ih_rb_cntl, tmp); + } + +/* Clear RB_OVERFLOW bit */ + tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,WPTR_OVERFLOW_CLEAR ,1 ); +if (amdgpu_sriov_vf (adev) &&amdgpu_sriov_reg_indirect_ih (adev)) { +if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) +return -ETIMEDOUT ; + }else { +WREG32_NO_KIQ (ih_regs->ih_rb_cntl, tmp); + } + +/* Unset the CLEAR_OVERFLOW bit immediately so new overflows +* can be detected. +*/ + tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,WPTR_OVERFLOW_CLEAR ,0 ); + } +/* enable_intr field is only valid in ring0 */ if (ih == &adev->irq.ih) tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,ENABLE_INTR , (enable ?1 :0 ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1293/2857 drm/amdgpu: publish IH enabled before PSP programs IH_RB_CNTL
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Milan Milicevic <[email protected]>
[ Upstream commit 9d550dd1a3b4b96da49f3560a84b5c2413a88cd3 ]
On SR-IOV, programming IH_RB_CNTL through PSP is slow enough for the first MSI to arrive before ih->enabled is set. amdgpu_ih_process() then drops the interrupt, rptr stays at 0, and RPTR_REARM never generates another edge, so every ring hits the fence fallback timer.
Set ih->enabled before psp_reg_program() on the indirect IH path for Navi10 and IH v6.0, and clear it if programming fails.
--- drivers/gpu/drm/amd/amdgpu/ih_v6_0.c | 13 ++++++++++++- drivers/gpu/drm/amd/amdgpu/navi10_ih.c | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/ih_v6_0.c +12 -1
@@ -168,8 +168,19 @@ static int ih_v6_0_toggle_ring_interrupts(struct amdgpu_device *adev, tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,ENABLE_INTR , (enable ?1 :0 ));if (amdgpu_sriov_vf (adev) &&amdgpu_sriov_reg_indirect_ih (adev)) { -if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) +/* +* PSP programming of IH_RB_CNTL is slow enough for MSI to +* arrive before this call returns. Publish ih->enabled first +* so amdgpu_ih_process() consumes that IV and rearms. +*/ +if (enable) { + ih->enabled = true; +smp_wmb (); + } +if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) { + ih->enabled = false;return -ETIMEDOUT ; + } }else {WREG32 (ih_regs->ih_rb_cntl, tmp); }
drivers/gpu/drm/amd/amdgpu/navi10_ih.c +12 -1
@@ -194,8 +194,19 @@ static int navi10_ih_toggle_ring_interrupts(struct amdgpu_device *adev, tmp =REG_SET_FIELD (tmp,IH_RB_CNTL ,ENABLE_INTR , (enable ?1 :0 ));if (amdgpu_sriov_vf (adev) &&amdgpu_sriov_reg_indirect_ih (adev)) { -if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) +/* +* PSP programming of IH_RB_CNTL is slow enough for MSI to +* arrive before this call returns. Publish ih->enabled first +* so amdgpu_ih_process() consumes that IV and rearms. +*/ +if (enable) { + ih->enabled = true; +smp_wmb (); + } +if (psp_reg_program (&adev->psp, ih_regs->psp_reg_id, tmp)) { + ih->enabled = false;return -ETIMEDOUT ; + } }else {WREG32 (ih_regs->ih_rb_cntl, tmp); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1294/2857 drm/amd/display: Dont select zero V_TOTAL_MIN/MAX on seamless boot
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kylie C <[email protected]>
[ Upstream commit d13f36e4e055cce03761de590bc8dc6346b1d5c8 ]
Initialize V_TOTAL_MIN/MAX to V_TOTAL before enabling the selectors if they are still 0, as optc1_program_timing() does without seamless boot.
Tested on Renoir (DCN 2.1) eDP with amdgpu.seamless=1.
This removes the flash between the bios logo & plymouth on my laptop.
--- drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c +7 -0
@@ -455,6 +455,13 @@ void optc2_lock_doublebuffer_disable(struct timing_generator *optc)void optc2_setup_manual_trigger (struct timing_generator *optc) {struct optc *optc1 =DCN10TG_FROM_TG (optc); +uint32_t v_total, v_total_max; + +REG_GET (OTG_V_TOTAL_MAX ,OTG_V_TOTAL_MAX , &v_total_max); +if (!v_total_max) { +REG_GET (OTG_V_TOTAL ,OTG_V_TOTAL , &v_total); + optc->funcs->set_vtotal_min_max (optc, v_total, v_total); + } REG_SET_8(OTG_TRIGA_CNTL, 0, OTG_TRIGA_SOURCE_SELECT, 21,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1295/2857 nvmet: dont return memory contents beyond valid data when reading ANA log page
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ewan D. Milne <[email protected]>
[ Upstream commit 29b8758b4700357909f06705a0c48c7a60c556d5 ]
The host side does not know how much valid data will be returned by the target so it will typically provide a buffer larger than the amount of valid data in the ANA log page. The memory allocation used by the target does not guarantee that prior kernel memory contents will not be returned past the end of the valid page data. Fix this to ensure that the SGL is zeroed before copying the data.
--- drivers/nvme/target/admin-cmd.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/nvme/target/admin-cmd.c +9 -0
@@ -280,6 +280,15 @@ static void nvmet_execute_get_log_page_ana(struct nvmet_req *req)u16 ngrps =0 ;u16 status; +/* +* The header and one descriptor per enabled group are the only bytes +* written below; zero the whole transfer first so the unwritten tail +* does not leak stale kernel memory to the host. +*/ + status =nvmet_zero_sgl (req,0 , req->transfer_len); +if (status) + goto out; + status =NVME_SC_INTERNAL ; desc =kmalloc (struct_size (desc, nsids,NVMET_MAX_NAMESPACES ),GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1296/2857 arm64: mm: validate /dev/mem mmap ranges without overflow
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Gongyi <[email protected]>
[ Upstream commit b0958b1397fb5ffdb995c0ccc74349841929c08d ]
An arm64 syzkaller reproducer creates a FUSE character device with major:minor 1:1, so opening it uses the /dev/mem file operations. It maps one page from offset 0xfffffffffffff000 at user address zero. The next openat() with a NULL pathname triggers a synchronous external abort (SEA, ESR 0x96000010) in strncpy_from_user() via do_getname(), panicking the kernel.
valid_mmap_phys_addr_range() checks the exclusive end by adding the mapping size to the starting address. For this offset, the sum wraps to zero and passes the PHYS_MASK test, allowing an out-of-range PFN to reach remap_pfn_range(). The inclusive-end overflow check in mmap_mem_prepare() does not catch it because the end is ULONG_MAX.
Reject starting PFNs outside PHYS_MASK and compare the inclusive length against the remaining physical range without overflowing. This also allows mappings that end exactly at PHYS_MASK, which the old check incorrectly rejects.
--- arch/arm64/mm/mmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/mm/mmap.c +3 -1
@@ -59,7 +59,9 @@ int valid_phys_addr_range(phys_addr_t addr, size_t size)*/ int valid_mmap_phys_addr_range (unsigned long pfn,size_t size) { -return !(((pfn <<PAGE_SHIFT ) + size) & ~PHYS_MASK ); +const phys_addr_t limit =PHYS_MASK +1 ; + +return size <= limit && pfn <= (limit - size) >>PAGE_SHIFT ; }static int __init adjust_protection_map (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1297/2857 drm/nouveau/devinit/gf100-: try to avoid double-running vbios scripts
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilia Mirkin <[email protected]>
[ Upstream commit 2139cb633d48ebbbaec88d2e5a8ebe8e774df4fb ]
Turns out some VBIOSes don't actually set the bit in question in 2240c. Use the nv50-style detection to try avoiding running the vbios twice.
--- .../drm/nouveau/nvkm/subdev/devinit/gf100.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c +20 -0
@@ -27,6 +27,7 @@#include <subdev/bios/init.h> #include <subdev/bios/pll.h> #include <subdev/clk/pll.h> +#include <subdev/vga.h> int gf100_devinit_pll_set (struct nvkm_devinit *init,u32 type,u32 freq)
@@ -101,6 +102,25 @@ gf100_devinit_preinit(struct nvkm_devinit *base)* can use it as a reliable way to know whether we should run devinit. */ base->post = ((nvkm_rd32 (device,0x2240c ) &BIT (1 )) ==0 ); + +/* +* However some VBIOS init sequences miss this bit. So fall back to +* the nv50 method of checking if the bit is not set. Running the +* VBIOS multiple times may have detrimental effects. +*/ +if (base->post) { +u64 disable =nvkm_devinit_disable (base); +/* magic to detect whether or not x86 vbios code has +* executed the devinit scripts to initialise the +* board. only works if there's a display engine. +*/ +if (!(disable & (1ULL <<NVKM_ENGINE_DISP ))) { +if (nvkm_rdvgac (device,0 ,0x00 ) || +nvkm_rdvgac (device,0 ,0x1a )) { + base->post = false; + } + } + } } static const struct nvkm_devinit_func
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1298/2857 ALSA: hda/realtek: Enable bass speakers on Alienware m17 R3
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Simpson <[email protected]>
[ Upstream commit eb296114d5ba4d335a640dbbbbc9618fded0ffe7 ]
The Alienware m17 R3 (ALC289, PCI SSID 1028:09d1) has a second speaker pair, the bass speakers, on pin 0x17, which the BIOS leaves unconnected (0x411111f0). No PCI SSID quirk matches the machine, so it gets ALC269_FIXUP_DELL4_MIC_NO_PRESENCE from the fallback pin quirk table, and only the speakers on pin 0x14 play.
Use ALC289_FIXUP_DUAL_SPK, as on the Alienware x16 R2 and Dell XPS 15 9510/9520: it sets pin 0x17 up as a speaker on DAC 0x02, so one volume control covers both pairs, and chains to ALC269_FIXUP_DELL4_MIC_NO_PRESENCE, so the headset mic setup is unchanged.
Tested on an Alienware m17 R3 (BIOS 1.38.0), Linux 7.3 with this change
applied: the bass speakers play, and volume and mute cover both pairs, also after suspend and resume. Headphones and a headset mic were not tested.
I used Claude Code (Claude Opus 5.5) to find the unused pin, pick the existing fixup and write this patch and changelog; I did the listening tests myself.
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -9860,6 +9860,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1028 ,0x097e ,"Dell Precision" ,ALC289_FIXUP_DUAL_SPK ),SND_PCI_QUIRK (0x1028 ,0x098d ,"Dell Precision" ,ALC233_FIXUP_ASUS_MIC_NO_PRESENCE ),SND_PCI_QUIRK (0x1028 ,0x09bf ,"Dell Precision" ,ALC233_FIXUP_ASUS_MIC_NO_PRESENCE ), +SND_PCI_QUIRK (0x1028 ,0x09d1 ,"Alienware m17 R3" ,ALC289_FIXUP_DUAL_SPK ),SND_PCI_QUIRK (0x1028 ,0x0a2e ,"Dell" ,ALC236_FIXUP_DELL_AIO_HEADSET_MIC ),SND_PCI_QUIRK (0x1028 ,0x0a30 ,"Dell" ,ALC236_FIXUP_DELL_AIO_HEADSET_MIC ), SND_PCI_QUIRK(0x1028, 0x0a38, "Dell Latitude 7520", ALC269_FIXUP_DELL4_MIC_NO_PRESENCE_QUIET),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1299/2857 ALSA: cs46xx: Handle SCB creation failures before dereferencing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Kazinsky <[email protected]>
[ Upstream commit 023d3e1176202339cd94a3d732e3aec74e36ba22 ]
With CONFIG_PM_SLEEP enabled, cs46xx_dsp_create_scb() can return NULL if kmemdup() fails to allocate the SCB data saved for resume. cs46xx_dsp_scb_and_task_init() and _dsp_create_generic_scb() dereference the returned pointer without checking it, causing a NULL pointer dereference on allocation failure.
Check both return values before accessing the SCB descriptors. Return -ENOMEM when creating the null SCB fails and propagate NULL from _dsp_create_generic_scb().
Found by Linux Verification Center (linuxtesting.org) with SVACE static analysis tool.
--- sound/pci/cs46xx/dsp_spos.c | 2 ++ sound/pci/cs46xx/dsp_spos_scb_lib.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
sound/pci/cs46xx/dsp_spos.c +2 -0
@@ -1110,6 +1110,8 @@ int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip) null_scb.entry_point = null_algorithm->address; ins->the_null_scb =cs46xx_dsp_create_scb (chip,"nullSCB" , (u32 *)&null_scb,NULL_SCB_ADDR ); +if (!ins->the_null_scb) +return -ENOMEM ; ins->the_null_scb->task_entry = null_algorithm; ins->the_null_scb->sub_list_ptr = ins->the_null_scb; ins->the_null_scb->next_scb_ptr = ins->the_null_scb;
sound/pci/cs46xx/dsp_spos_scb_lib.c +2 -1
@@ -285,7 +285,8 @@ _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, udev_dbg (chip->card->dev,"dsp_spos: creating SCB <%s>\n" , name); scb =cs46xx_dsp_create_scb (chip,name,scb_data,dest); - +if (!scb) +return NULL ; scb->sub_list_ptr = ins->the_null_scb; scb->next_scb_ptr = ins->the_null_scb;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1300/2857 ALSA: bcd2000: Fix use-after-free of MIDI URBs on file close
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: YuanZhe Liu <[email protected]>
[ Upstream commit f6c7bb1f0799591a62be75b9bcf84245b4f208b7 ]
bcd2000_disconnect() calls snd_card_disconnect(), which only prevents new opens, and then frees the MIDI URBs. A rawmidi file that was already open can still be closed afterwards, and its close callback, bcd2000_midi_output_close(), calls usb_kill_urb() on midi_out_urb.
The URB pointers are cleared on disconnect and their accesses are serialized with midi_lock, but bcd2000_midi_output_close() reads midi_out_urb without that lock. The check can therefore pass just before the pointer is cleared, and usb_kill_urb() then runs on the URB that has already been freed:
BUG: KASAN: slab-use-after-free in usb_kill_urb+0x74/0x80 Read of size 8 at addr ffff8880078e7d40 usb_kill_urb bcd2000_midi_output_close close_substream rawmidi_release_priv snd_rawmidi_release
Allocated by: usb_alloc_urb <- bcd2000_init_midi <- bcd2000_probe
Freed by: usb_free_urb <- bcd2000_midi_free
<- bcd2000_disconnect
Take the lock in bcd2000_midi_output_close() and reference the URB with usb_get_urb() before releasing it. The URB then stays valid until usb_put_urb() after usb_kill_urb() has returned, even if a disconnect frees it in the meantime. usb_kill_urb() itself cannot run under midi_lock, as the completion handler takes the same lock.
--- sound/usb/bcd2000/bcd2000.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
sound/usb/bcd2000/bcd2000.c +17 -3
@@ -183,10 +183,24 @@ static int bcd2000_midi_output_open(struct snd_rawmidi_substream *substream)static int bcd2000_midi_output_close (struct snd_rawmidi_substream *substream) {struct bcd2000 *bcd2k = substream->rmidi->private_data; +struct urb *urb =NULL ; -if (bcd2k->midi_out_active && bcd2k->midi_out_urb) { -usb_kill_urb (bcd2k->midi_out_urb); - bcd2k->midi_out_active =0 ; +/* +* Reference the URB under the lock so that it stays valid until +* usb_kill_urb() returns, even if a disconnect frees it in the +* meantime. usb_kill_urb() cannot run under the lock, as the +* completion handler takes the same lock. +*/ + scoped_guard(spinlock_irqsave, &bcd2k->midi_lock) { +if (bcd2k->midi_out_active && bcd2k->midi_out_urb) { + urb =usb_get_urb (bcd2k->midi_out_urb); + bcd2k->midi_out_active =0 ; + } + } + +if (urb) { +usb_kill_urb (urb); +usb_put_urb (urb); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1301/2857 ALSA: line6: Reject capture buffers smaller than two packets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit db51425c9eb038a8e40e09b837afde015ae9e3ec ]
line6_capture_copy() splits the copy into the ALSA ring buffer once at the buffer end and wraps pos_done once, which is only correct when one packet holds at most buffer_size frames. The packet size comes from the device's endpoint, and the per-device hw structs allow 64-byte periods with periods_min 1, so a packet can be larger than the whole buffer. audio_in_callback() logs an oversized packet and then copies it anyway.
The packet size is known at probe time, so constrain SNDRV_PCM_HW_PARAM_BUFFER_BYTES in snd_line6_capture_open() to at least twice the larger of the two endpoints' packet sizes. Two rather than one, because pos_done advances by the packet and wraps once, so a buffer of exactly one packet leaves the position unchanged after every packet. hw_params then rejects a buffer that cannot hold two packets, and the single wrap is valid for every configuration that gets through. Keep a guard in line6_capture_copy() that drops an oversized packet with a ratelimited error, for the case that should no longer be reachable.
Reproduced on 7.3-rc7 with a USB/IP device presenting the GuitarPort interface layout and 1024-byte packets into a 128-byte buffer: ALSA logged "invalid position: pos = 224, buffer size = 32" and the driver logged "driver bug: len" on every following packet. With this patch a 1024-byte buffer is refused at hw_params, and a 2048-byte buffer streams for 30 s with no report and with the position moving inside the buffer.
--- sound/usb/line6/capture.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
sound/usb/line6/capture.c +29 -0
@@ -94,6 +94,18 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)if (runtime ==NULL )return ; +/* +* snd_line6_capture_open() constrains the buffer to hold at least +* two packets, so this cannot happen for a conforming device. Drop +* the packet rather than overrun the single wrap below. +*/ +if (unlikely (frames > runtime->buffer_size)) { +dev_err_ratelimited (line6pcm->line6->ifcdev, +"packet of %d frames exceeds %lu-frame buffer, dropping\n" , + frames, runtime->buffer_size); +return ; + } +if (line6pcm->in.pos_done + frames > runtime->buffer_size) {/* The transferred area goes over buffer boundary,
@@ -228,6 +240,23 @@ static int snd_line6_capture_open(struct snd_pcm_substream *substream)if (err <0 )return err; +/* +* line6_capture_copy() wraps the ring buffer once per packet and +* advances pos_done by the packet, which only works when the buffer +* holds more than one packet: with exactly one, pos_done gains a +* buffer and loses it again on every packet. The packet size comes +* from the device, so bound the buffer by two packets here. The +* impulse-response path copies a playback URB into this ring, so +* take the larger of the two endpoints. +*/ + err =snd_pcm_hw_constraint_minmax (runtime, +SNDRV_PCM_HW_PARAM_BUFFER_BYTES , +2 *max (line6pcm->max_packet_size_in, + line6pcm->max_packet_size_out), +UINT_MAX ); +if (err <0 ) +return err; +line6_pcm_acquire (line6pcm,LINE6_STREAM_CAPTURE_HELPER , false); runtime->hw = line6pcm->properties->capture_hw;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1302/2857 ALSA: caiaq: free the EP4 URB when input setup fails
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit d21746bafdb8e1a5fc9bdcb86f603d827a500a62 ]
The three controllers that use the EP4 input URB allocate it before checking the endpoint type and before registering the input device. On failure they jump to exit_free_idev, which clears cdev->input_dev but leaves cdev->ep4_in_urb set. The card teardown then calls snd_usb_caiaq_input_free(), which returns early because input_dev is NULL, so the URB is never freed.
Release the URB before dropping the input device on the error path.
--- sound/usb/caiaq/input.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/caiaq/input.c +2 -0
@@ -830,6 +830,8 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev)return 0 ; exit_free_idev: +usb_free_urb (cdev->ep4_in_urb); + cdev->ep4_in_urb =NULL ;input_free_device (input); cdev->input_dev =NULL ;return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1303/2857 ALSA: usx2y: Require a buffer of two URBs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit 4cbb826b3b36df6c275454287ba1df4564a5370b ]
usx2y_urb_capt_retire() wraps the ring buffer once per packet and usx2y_urb_play_prepare() once per URB of nr_of_packs() packets of up to 50 frames. Both assume that the data fits in the buffer, and the hw constraints only require about two 1 ms periods, so a packet larger than the buffer on capture, or a URB larger than the buffer on playback, violates that assumption.
Constrain SNDRV_PCM_HW_PARAM_BUFFER_SIZE in snd_usx2y_pcm_open() to at least two URBs, 2 * nr_of_packs() * 50 frames, for both directions. The bound is in frames and derived from the driver's own packet limit, so it does not read the endpoint, whose altsetting is only selected in prepare. Two URBs rather than one, because the position advances by a URB on playback and only moves when a URB is less than the whole buffer. Keep a guard in usx2y_urb_capt_retire() that drops a packet larger than the buffer, for the case the constraint makes unreachable.
With nrpacks above about 163 (S16_LE) or 109 (S24_3LE) the bound exceeds the 64 KiB buffer the substream preallocates (twice that with the preallocation raised to its 128 KiB maximum), so hw_params fails for those module settings. That is intended: the driver cannot be safe with a URB larger than half the largest buffer.
Reproduced on 7.3-rc7 with a USB/IP device presenting the US-122 interface layout and 1024-byte packets into a 512-byte capture buffer:
BUG: KASAN: out-of-bounds in i_usx2y_urb_complete+0x1285/0x1ac0 Read of size 18446744073709551104 at addr ffff88800e448800 by task vhci_rx/83
Tested on 7.3-rc7 with the same device, S16_LE at 44100 Hz, nrpacks 4, so the bound is 400 frames. A 128-frame capture buffer and a 200-frame playback buffer are refused at hw_params with EINVAL. A 400-frame buffer streams for 30 s in each direction with the position advancing inside the buffer and no KASAN report; the capture guard did not fire. The same 400-frame capture buffer with S24_3LE, which selects altsetting 2 in prepare, streams for 30 s with the same result.
--- sound/usb/usx2y/usbusx2yaudio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
sound/usb/usx2y/usbusx2yaudio.c +24 -0
@@ -50,6 +50,18 @@ static int usx2y_urb_capt_retire(struct snd_usx2y_substream *subs)snd_printd ("0 == len ERROR!\n" );continue ; } +/* +* snd_usx2y_pcm_open() constrains the buffer to hold at least +* two URBs, so this cannot happen for a device that keeps its +* packets at 50 frames. Drop the packet rather than exceed the +* single wrap below. +*/ +if (unlikely (len > runtime->buffer_size)) { +dev_err_ratelimited (&usx2y->dev->dev, +"%s: packet of %i frames exceeds %lu-frame buffer, dropping\n" , + __func__, len, runtime->buffer_size); +continue ; + }/* copy a data chunk */ if ((hwptr_done + len) > runtime->buffer_size) {
@@ -886,6 +898,18 @@ static int snd_usx2y_pcm_open(struct snd_pcm_substream *substream) runtime->private_data = subs; subs->pcm_substream = substream;snd_pcm_hw_constraint_minmax (runtime,SNDRV_PCM_HW_PARAM_PERIOD_TIME ,1000 ,200000 ); +/* +* Capture wraps the ring buffer once per packet and playback once +* per URB of nr_of_packs() packets of at most 50 frames (see +* usx2y_urb_play_prepare()). Playback needs the buffer to hold more +* than one URB and capture more than one packet; use the URB bound +* for both, and two URBs rather than one, because the position only +* advances when a URB is less than the whole buffer. The bound is in +* frames and does not depend on the altsetting, which is selected +* in prepare. +*/ +snd_pcm_hw_constraint_minmax (runtime,SNDRV_PCM_HW_PARAM_BUFFER_SIZE , +2 *nr_of_packs () *50 ,UINT_MAX );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1304/2857 ALSA: usx2y: Guard the playback copy
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit e2c6de52ffacb2c0f4076884ee3fdb744735a4cb ]
usx2y_urb_play_prepare() sums the packet lengths of a whole URB, copies that many frames with a single wrap, and sizes each playback packet from the capture packet's actual_length. Three things are unchecked: that the URB fits in the ring buffer, that a packet fits in the playback endpoint's maxpacksize, from which tmpbuf is allocated, and that actual_length is a whole number of frames. The ISO descriptors take the raw actual_length while transfer_buffer_length and the copies take count * stride, so a packet that is not a multiple of the stride makes the descriptors add up to more than the buffer, by up to stride - 1 bytes per packet.
Return -EPIPE, as the existing packet-size check does, when the URB is larger than the buffer or a packet is larger than maxpacksize, and size each descriptor from whole frames, so the descriptors add up to transfer_buffer_length and each stays within maxpacksize. The buffer case is prevented by the previous patch and this is the guard for it; the other two depend only on the device.
The first case is reachable on the unpatched driver with ordinary
packets: on 7.3-rc7, a USB/IP device presenting the US-122 interface layout and sending 48-frame packets, with a 100-frame playback buffer (two 50-frame periods, inside the stock constraints), KASAN reports:
BUG: KASAN: out-of-bounds in i_usx2y_urb_complete+0x79b/0x1ac0 Read of size 18446744073709551280 at addr ffff88800e6b02e0 by task vhci_rx/80
With both patches, the same device and a 200-frame playback buffer is refused at hw_params with EINVAL, and a 400-frame buffer plays for 30 s with the position advancing inside the buffer, no KASAN report and neither guard message. The maxpacksize check is not exercised: the emulated device reports the same wMaxPacketSize on both endpoints.
The descriptor case is visible with capture packets of 195 bytes at stride 4 (48 frames and 3 bytes): without this change the four descriptors add up to 780 bytes for 768 bytes of data, and USB/IP's completion check refuses the URB ("total length of iso packets 780 not equal to actual length of buffer 768", -EPROTO), after which the driver stops the streams. With this patch every descriptor is 192 bytes, the descriptors add up to the data in every URB for 30 s, the position advances inside the buffer and KASAN reports nothing. The 48-frame playback run above is unchanged.
--- sound/usb/usx2y/usbusx2yaudio.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
sound/usb/usx2y/usbusx2yaudio.c +18 -1
@@ -116,14 +116,31 @@ static int usx2y_urb_play_prepare(struct snd_usx2y_substream *subs,snd_printk (KERN_ERR "should not be here with counts=%i\n" , counts);return -EPIPE ; } +if (counts * usx2y->stride > subs->maxpacksize) { +dev_err_ratelimited (&usx2y->dev->dev, +"%s: packet of %i bytes exceeds maxpacksize %u\n" , + __func__, counts * usx2y->stride, + subs->maxpacksize); +return -EPIPE ; + }/* set up descriptor */ urb->iso_frame_desc[pack].offset = pack ? urb->iso_frame_desc[pack -1 ].offset + urb->iso_frame_desc[pack -1 ].length :0 ; - urb->iso_frame_desc[pack].length = cap_urb->iso_frame_desc[pack].actual_length; + urb->iso_frame_desc[pack].length = counts * usx2y->stride; }if (atomic_read (&subs->state) >=STATE_PRERUNNING ) { +/* +* The copy below wraps once, which needs count <= buffer_size. +* snd_usx2y_pcm_open() guarantees it; guard anyway. +*/ +if (unlikely (count > runtime->buffer_size)) { +dev_err_ratelimited (&usx2y->dev->dev, +"%s: URB of %i frames exceeds %lu-frame buffer, stopping\n" , + __func__, count, runtime->buffer_size); +return -EPIPE ; + }if (subs->hwptr + count > runtime->buffer_size) {/* err, the transferred area goes over buffer boundary. * copy the data to the temp buffer.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1305/2857 net/smc: dont spin in smc_rx_recvmsg() while a pipe holds spliced data
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit 8288ba942cfd20621c05e16978b7c3da91513ae1 ]
While bytes spliced off the RMB are still in a pipe, recvmsg() waits for the pipe to release them before it copies the data behind them. The path to that wait skips the timeout and signal checks, and smc_rx_wait() returns at once on RCV_SHUTDOWN. With a signal pending, after SHUT_RD, or once the peer closes or shuts down writing, recvmsg() spins on a CPU until the pipe is drained, and SIGKILL cannot stop it. MSG_DONTWAIT and an expired SO_RCVTIMEO wait there too instead of returning -EAGAIN.
Check the timeout and signals before that wait, and end it when the pipe releases the data or the connection is killed, not on RCV_SHUTDOWN. A zero-length read returns 0 without waiting for the pipe; a non-blocking one returns -EAGAIN while poll() still reports the socket readable (splice() can still take those bytes). The wait sets SOCKWQ_ASYNC_WAITDATA like smc_rx_wait(), so a byte arriving behind the pipe raises no SIGIO on a reader already asleep for it, and a full barrier orders its wait queue entry before its read of splice_pending, so no wake is lost.
--- net/smc/smc_rx.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
net/smc/smc_rx.c +38 -1
@@ -282,6 +282,27 @@ int smc_rx_wait(struct smc_sock *smc, long *timeo, size_t peeked,return rc; } +/* Wait for the pipe to release the spliced data. Unlike smc_rx_wait() +* it does not end on shutdown or sk_err, the data is already in the +* RMB; smc_conn_kill() wakes it and the caller checks conn->killed. +*/ +static void smc_rx_wait_splice (struct smc_sock *smc,long *timeo) +{ +DEFINE_WAIT_FUNC (wait, woken_wake_function); +struct smc_connection *conn = &smc->conn; +struct sock *sk = &smc->sk; + +sk_set_bit (SOCKWQ_ASYNC_WAITDATA , sk); +add_wait_queue (sk_sleep (sk), &wait); +/* pairs with the smp_mb() in wq_has_sleeper(): the release drops +* splice_pending, then looks for a sleeper +*/ +smp_mb (); +sk_wait_event (sk, timeo, !atomic_read (&conn->splice_pending), &wait); +remove_wait_queue (sk_sleep (sk), &wait); +sk_clear_bit (SOCKWQ_ASYNC_WAITDATA , sk); +} +static int smc_rx_recv_urg (struct smc_sock *smc,struct msghdr *msg,int len,int flags) {
@@ -439,7 +460,23 @@ int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg,/* could be just 1 byte, even after waiting on data above */ readable =smc_rx_data_available (conn, peeked_bytes); splbytes =atomic_read (&conn->splice_pending); -if (!readable || (msg && splbytes)) { +if (msg && splbytes) { +/* a pipe holds bytes ahead of these; the copy path +* skips the timeout and signal checks +*/ +if (!read_remaining) +break ; +if (!timeo ||signal_pending (current)) { +if (!read_done) + read_done = timeo ? +sock_intr_errno (timeo) : + -EAGAIN ; +break ; + } +smc_rx_wait_splice (smc, &timeo); +continue ; + } +if (!readable) {if (splbytes) func = smc_rx_data_available_and_no_splice_pend;else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1306/2857 net: count last skb of each sk_backlog pass in __release_sock()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ray Zhang <[email protected]>
[ Upstream commit c4e4056b21355356f6a95bcdf03a850edd9f49e7 ]
Running 500 concurrent TCPv6 streams (neper "tcp_stream -6 -T 1 -F 500") on a 2-core Cortex-A53 (CONFIG_PREEMPT_NONE=y, HZ=1000, LATENCY_WARN) triggers resched_latency_warn() in __release_sock():
[ 3655.311821] sched: CPU 0 need_resched set for > 100006892 ns (100 ticks) without schedule [ 3655.311889] Call trace: ... [ 3655.311944] resched_latency_warn+0x7c/0x88 [ 3655.311958] sched_tick+0x1c0/0x418 ... [ 3655.312578] net_rx_action+0x238/0x438 ... [ 3655.312641] do_softirq+0x4c/0x90 [ 3655.312651] __local_bh_enable_ip+0x84/0x90 [ 3655.312663] local_bh_enable+0x1c/0x28 [ 3655.312674] __dev_queue_xmit+0x4a8/0xb00 ... [ 3655.312782] tcp_v6_do_rcv+0x240/0x5f8 [ 3655.312793] __release_sock+0x9c/0x188 [ 3655.312806] release_sock+0x150/0x168 [ 3655.312817] tcp_sendmsg+0x4c/0x70
__release_sock() can loop past 100 ms without calling cond_resched():
- Each outer-loop pass drains sk_backlog, but "if (!skb) break;" runs before "++nb", so a pass of B skbs only adds B - 1 to nb (0 for 1 skb).
- With 500 TCPv6 streams and NAPI sharing two Cortex-A53 cores, runnable tasks keep TIF_NEED_RESCHED set on CPU 0.
- During spin_unlock_bh() and TX softirqs (__dev_queue_xmit() -> local_bh_enable()), tcp_add_backlog() coalesces arriving pure ACKs into a single tail skb.
- Repeated 1-skb passes never advance nb or call cond_resched(), triggering resched_latency_warn() after 100 ticks.
Restore the do-while loop and drop "if (!skb) break;" so every skb increments nb across passes and calls cond_resched() every 16 skbs.
Reproduced the issue and verified the fix on two 2-core Cortex-A53 hosts (CONFIG_PREEMPT_NONE=y, HZ=1000, LATENCY_WARN, latency_warn_once=0) with a userspace reproducer over /dev/net/tun:
- CPU 0 runs a TCPv6 sender and a second runnable task while CPU 1 writes pure ACKs to /dev/net/tun (~30k TCPBacklogCoalesce/run), sustaining 1-skb sk_backlog refills in __release_sock() for ~400 ms (ftrace).
- Before: CPU 0 stayed unscheduled in __release_sock(), hitting resched_latency_warn() 293 and 275 times on the two hosts (> 100.9 ms).
- After: cond_resched() yielded CPU 0 inside __release_sock(), with 0 resched_latency_warn() hits on both hosts.
- Also observed no regression with the workload from
commit 16c610162d1f ("net: call cond_resched() less often in __release_sock()"), "super_netperf 4 -H srv -T,10 -l 3000 &".
--- net/core/sock.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/sock.c +2 -4
@@ -2968,7 +2968,7 @@ void __release_sock(struct sock *sk)spin_unlock_bh (&sk->sk_lock.slock); -while (1 ) { + do { next = skb->next; prefetch(next); DEBUG_NET_WARN_ON_ONCE(skb_dst_is_noref(skb));
@@ -2976,12 +2976,10 @@ void __release_sock(struct sock *sk)sk_backlog_rcv (sk, skb); skb = next; -if (!skb) -break ;if (!(++nb &15 ))cond_resched (); - } + }while (skb);spin_lock_bh (&sk->sk_lock.slock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1307/2857 net: ethernet: ti: am65-cpsw-nuss: Enable timestamping of unicast PTP packets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 6887a8f98244ba4c0fbe2d2461b9b8f8a300e326 ]
On a BeagleY-AI (J722S), ptp4l as a unicast master (unicast_listen) logs "received DELAY_REQ without timestamp" for each unicast Delay_Req, and its port goes to FAULTY after "timed out while polling for tx timestamp" for the first unicast Sync.
am65_cpsw_nuss_hwtstamp_set() does not set the TS_UNI_EN bit (bit 24) of the port's TS_CTL_LTYPE2 register. According to the TRM (J722S TRM SPRUJB3D, 12.2.1.4.7.13.5.1 Ethernet Port Receive Event and 12.2.1.4.7.13.5.2 Ethernet Port Transmit Event), this bit must be set for the port to timestamp PTP event messages over UDP sent to a unicast address; without it, only messages sent to the PTP multicast addresses selected by the TS_107 and TS_129 to TS_132 bits are timestamped. TI's netcp_ethss driver for the Keystone 2 Ethernet switch, which has the same timestamping registers, always sets TS_UNI_EN.
Set TS_UNI_EN along with the other bits. With this change, ptp4l in the same setup gets timestamps for the unicast Delay_Req and Sync messages.
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +3 -1
@@ -109,6 +109,7 @@#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_319 BIT(21)#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_320 BIT(22)#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO BIT(23) +#define AM65_CPSW_PN_TS_CTL_LTYPE2_TS_UNI_EN BIT(24)/* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */ #define AM65_CPSW_TS_EVENT_MSG_TYPE_BITS (BIT(0) | BIT(1) | BIT(2) | BIT(3))
@@ -1304,7 +1305,8 @@ static int am65_cpsw_nuss_hwtstamp_set(struct net_device *ndev,AM65_CPSW_PN_TS_CTL_LTYPE2_TS_132 |AM65_CPSW_PN_TS_CTL_LTYPE2_TS_319 |AM65_CPSW_PN_TS_CTL_LTYPE2_TS_320 | -AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO ; +AM65_CPSW_PN_TS_CTL_LTYPE2_TS_TTL_NONZERO | +AM65_CPSW_PN_TS_CTL_LTYPE2_TS_UNI_EN ; ts_ctrl =AM65_CPSW_TS_EVENT_MSG_TYPE_BITS <<AM65_CPSW_PN_TS_CTL_MSG_TYPE_EN_SHIFT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1308/2857 drm/etnaviv: Flush the tile status cache through both the PE and BLT
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Gmeiner <[email protected]>
[ Upstream commit c1a757f8df1363032623fa9b1baaba0dcf34de6d ]
Since commit f232d9ec029c ("drm/etnaviv: fix TS cache flushing on GPUs with BLT engine"), jobs on GPUs with a BLT engine use a BLT command to flush the tile status cache instead of TS_FLUSH_CACHE, which is broken on most of these GPUs.
GC7000 r6008/r6009 and GC8200 r6401 are the other way around:TS_FLUSH_CACHE works, but the BLT command does not flush the cache. The vendor driver handles these GPUs using TS_FLUSH_CACHE, but the etnaviv kernel driver has no way to identify them.
As a result, dirty tile status cache lines survive the end of a job. They are written back by the next cache flush, using the page table of the job issuing it. If that job belongs to another process, the write goes to the wrong address space.
On GC7000 r6009 this causes MMU faults and GPU recoveries blamed on an innocent process. I see around 1100 per run of a multisample depth/stencil test running alongside two other GPU clients.
Emit both flushes at the end of every job on GPUs with a BLT engine. Whichever does not work on a given GPU is a no-op. Since dirty lines are only written back once, this costs one additional state load per job.
--- drivers/gpu/drm/etnaviv/etnaviv_buffer.c | 40 +++++++++++------------- 1 file changed, 18 insertions(+), 22 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_buffer.c +18 -22
@@ -229,6 +229,17 @@ u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id)return buffer->user_size /8 ; } +static void etnaviv_cmd_flush_ts (struct etnaviv_cmdbuf *buffer,bool has_blt) +{ +CMD_LOAD_STATE (buffer,VIVS_TS_FLUSH_CACHE ,VIVS_TS_FLUSH_CACHE_FLUSH ); + +if (has_blt) { +CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x1 ); +CMD_LOAD_STATE (buffer,VIVS_BLT_SET_COMMAND ,0x1 ); +CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); + } +} +void etnaviv_buffer_end (struct etnaviv_gpu *gpu) {struct etnaviv_cmdbuf *buffer = &gpu->buffer;
@@ -252,7 +263,7 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)unsigned int dwords =7 ;if (has_blt) - dwords +=10 ; + dwords +=11 ; link_target =etnaviv_buffer_reserve (gpu, buffer, dwords);
@@ -265,16 +276,8 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); }CMD_LOAD_STATE (buffer,VIVS_GL_FLUSH_CACHE , flush); -if (gpu->exec_state ==ETNA_PIPE_3D ) { -if (has_blt) { -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_SET_COMMAND ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); - }else { -CMD_LOAD_STATE (buffer,VIVS_TS_FLUSH_CACHE , -VIVS_TS_FLUSH_CACHE_FLUSH ); - } - } +if (gpu->exec_state ==ETNA_PIPE_3D ) +etnaviv_cmd_flush_ts (buffer, has_blt);CMD_SEM (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );CMD_STALL (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );if (has_blt) {
@@ -461,12 +464,12 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state, return_dwords =7 ;/* -* When the BLT engine is present we need 6 more dwords in the return +* When the BLT engine is present we need 7 more dwords in the return * target: 3 enable/flush/disable + 4 enable/semaphore stall/disable, -* but we don't need the normal TS flush state. +* on top of the normal TS flush state. */ if (has_blt) - return_dwords +=6 ; + return_dwords +=7 ; return_target =etnaviv_buffer_reserve (gpu, buffer, return_dwords);CMD_LINK (cmdbuf, return_dwords, return_target);
@@ -483,14 +486,7 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,VIVS_GL_FLUSH_CACHE_DEPTH |VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_SHADER_L1); -if (has_blt) { -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_SET_COMMAND ,0x1 ); -CMD_LOAD_STATE (buffer,VIVS_BLT_ENABLE ,0x0 ); - }else { -CMD_LOAD_STATE (buffer,VIVS_TS_FLUSH_CACHE , -VIVS_TS_FLUSH_CACHE_FLUSH ); - } +etnaviv_cmd_flush_ts (buffer, has_blt); }CMD_SEM (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );CMD_STALL (buffer,SYNC_RECIPIENT_FE ,SYNC_RECIPIENT_PE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1309/2857 udf: dont let the extent type hide an exhausted free-space table extent
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit da582d84fcf5f2f0c1d7760e1a899ca7cedb80fc ]
udf_table_new_block() takes the first block of the free-space table extent closest to the goal. It keeps that extent's type and length together in goal_elen, subtracts one block, and deletes the extent only if goal_elen then reaches zero. UDF 2.60 section 2.3.7.1 requires the free-space extents of an Unallocated Space Entry to be of type 1 (allocated but not recorded), and mkudffs writes them that way. For such an extent the type bits keep goal_elen non-zero, so taking its last block leaves a type-1 extent of length zero behind, starting at the block after the extent, which is in use.
The next allocation that picks this empty extent returns that in-use block. Subtracting a block from 0x40000000 then borrows from the type bits, and the extent becomes type 0 with a length of 2^30 - blocksize:
about a gigabyte of "free" space overlapping live metadata, the other table extents and whatever lies behind the partition. From then on blocks are handed out twice, or past the end of the partition.
Extents that udf_table_free_blocks() adds are type 0, where the check works, so only tables written by mkudffs or by another implementation are affected. Nothing more than filling such a filesystem is needed:
on a fresh 1 MiB "mkudffs --space=unalloctable" image, creating empty files until the partition is full writes file entries over the reserve volume descriptor sequence and the backup anchor, and df then reports a negative amount of used space.
On syzbot's images the same double allocation is what the two reports below trip over. In the first, ftruncate() extends a new file with enough hole extents to need a chain of allocation extent descriptors; one AED is placed on another inode's file entry, and a later one is placed on the block of the AED currently being filled, which udf_setup_indirect_aext() zeroes, so __udf_add_aext() finds lengthAllocDescs out of step with its cursor. In the second, an AED is placed past the end of the device, sb_getblk() fails, and the error path of udf_do_extend_file() calls udf_truncate_extents() on an extent list that no longer covers i_size.
Keep the type separately from the length, as udf_table_prealloc_blocks() already does.
--- fs/udf/balloc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/udf/balloc.c +5 -3
@@ -580,7 +580,7 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb,uint32_t elen, goal_elen =0 ;struct kernel_lb_addr eloc, goal_eloc;struct extent_position epos, goal_epos; -int8_t etype; +int8_t etype, goal_etype =0 ;struct udf_inode_info *iinfo =UDF_I (table); *err = -ENOSPC ;
@@ -628,7 +628,8 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb, goal_epos.block = epos.block; goal_epos.offset = epos.offset - adsize; goal_eloc = eloc; - goal_elen = (etype <<30 ) | elen; + goal_elen = elen; + goal_etype = etype; } }
@@ -650,7 +651,8 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb, goal_elen -= sb->s_blocksize;if (goal_elen) -udf_write_aext (table, &goal_epos, &goal_eloc, goal_elen,1 ); +udf_write_aext (table, &goal_epos, &goal_eloc, + (goal_etype <<30 ) | goal_elen,1 );else udf_delete_aext (table, goal_epos);brelse (goal_epos.bh);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1310/2857 MIPS: mm: Fix the cache error vector jump for XKPHYS kernels
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit 30b76362f80d39d80f1197c88b284d9fa7952356 ]
except_vec2_generic jumps to cache_parity_error with a j, which cannot leave the vector's 256MB region. An XKPHYS kernel such as IP30's, linked at 512MB, is outside it, so the j targets an unbacked address and its speculative fetch raises bus errors on unrelated fetches. Jump to the handler's uncached XKPHYS address instead.
--- arch/mips/mm/cex-gen.S | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/mips/mm/cex-gen.S +16 -0
@@ -8,6 +8,7 @@ * * Cache error handler */ +#include <asm/addrspace.h> #include <asm/asm.h> #include <asm/regdef.h> #include <asm/mipsregs.h>
@@ -37,6 +38,21 @@ nop nop +#if defined(CONFIG_64BIT) && VMLINUX_LOAD_ADDRESS >= XKPHYS && \ + VMLINUX_LOAD_ADDRESS < XKSEG + /* + * An XKPHYS kernel may lie outside the 256MB region a j from the + * vector reaches, so jump to the handler's uncached XKPHYS address. + */ + PTR_LA k0, cache_parity_error + PTR_LI k1, TO_PHYS_MASK + and k0, k0, k1 + PTR_LI k1, UNCAC_BASE + or k0, k0, k1 + jr k0 + nop +#else j cache_parity_error nop +#endif END(except_vec2_generic)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1311/2857 MIPS: sgi-ip32: Mask MACE PCI interrupts in CRIME only
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit 4e65c502b8975e7c3c3d84aba59cd04af1dd6b8a ]
Masking PCI interrupts in the MACE PCI control register overwrites the error and arbitration enables set at init, and a read-modify-write can hang CRIME 1.1 machines under DMA load. Enable the slot interrupts once and mask them in CRIME.
--- arch/mips/pci/pci-ip32.c | 7 ++++-- arch/mips/sgi-ip32/ip32-irq.c | 45 +++-------------------------------- 2 files changed, 8 insertions(+), 44 deletions(-)
arch/mips/pci/pci-ip32.c +5 -2
@@ -125,10 +125,13 @@ static int __init mace_init(void) {PCIBIOS_MIN_IO =0x1000 ; -/* Clear any outstanding errors and enable interrupts */ +/* +* Clear any outstanding errors and enable interrupts. PCI interrupts +* are masked in CRIME, so the per-slot enables stay on. +*/ mace->pci.error_addr =0 ; mace->pci.error =0 ; - mace->pci.control =0xff008500 ; + mace->pci.control =0xff0085ff ;printk ("MACE PCI rev %d\n" , mace->pci.rev);
arch/mips/sgi-ip32/ip32-irq.c +3 -42
69 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1312/2857 MIPS: sgi-ip32: Leave MACE PCI control alone in config accesses
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Kaloz <[email protected]>
[ Upstream commit a55a7df2cf788234850d9053ecc25a5470175929 ]
mace_pci_read_config() clears the master abort interrupt enable in the MACE PCI control register around each config read. A register read followed by two register writes can hang CRIME 1.1 under DMA load.
Ack master aborts in the error register instead, and follow every write with a read so back-to-back accesses cannot form that sequence.
--- arch/mips/pci/ops-mace.c | 26 +++++++++++++++++++------- arch/mips/pci/pci-ip32.c | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
arch/mips/pci/ops-mace.c +19 -7
@@ -35,15 +35,27 @@ static inline int mkaddr(struct pci_bus *bus, unsigned int devfn, (reg &0xfc ); } +/* +* On CRIME 1.1, a MACE PCI register read followed by two register writes +* can hang the machine under DMA load, so every register write in this +* file is followed by a read. Config cycles to empty slots end in a +* master abort; ack it with interrupts still off so the bridge error +* interrupt does not report it. +*/ +static void mace_pci_ack_abort (void ) +{ +u32 error = mace->pci.error; + +if (error &MACEPCI_ERROR_MASTER_ABORT ) { + mace->pci.error = error & ~MACEPCI_ERROR_MASTER_ABORT ; + mace->pci.error; + } +}static int mace_pci_read_config (struct pci_bus *bus,unsigned int devfn,int reg,int size,u32 *val) { -u32 control = mace->pci.control; - -/* disable master aborts interrupts during config read */ - mace->pci.control = control & ~MACEPCI_CONTROL_MAR_INT ; mace->pci.config_addr =mkaddr (bus, devfn, reg);switch (size) {case 1 :
@@ -56,9 +68,7 @@ mace_pci_read_config(struct pci_bus *bus, unsigned int devfn, *val = mace->pci.config_data.l;break ; } -/* ack possible master abort */ - mace->pci.error &= ~MACEPCI_ERROR_MASTER_ABORT ; - mace->pci.control = control; +mace_pci_ack_abort ();/* * someone forgot to set the ultra bit for the onboard * scsi chips; we fake it here
@@ -77,6 +87,7 @@ mace_pci_write_config(struct pci_bus *bus, unsigned int devfn, int reg, int size, u32 val) { mace->pci.config_addr = mkaddr(bus, devfn, reg); + mace->pci.error;switch (size) {case 1 : mace->pci.config_data.b[(reg &3 ) ^3 ] = val;
@@ -88,6 +99,7 @@ mace_pci_write_config(struct pci_bus *bus, unsigned int devfn, mace->pci.config_data.l = val;break ; } +mace_pci_ack_abort ();DPRINTK ("write%d: reg=%08x,val=%02x\n" , size *8 , reg, val);
arch/mips/pci/pci-ip32.c +2 -0
@@ -77,6 +77,8 @@ static irqreturn_t macepci_error(int irq, void *dev) } mace->pci.error = flags; +/* follow the write with a read, see mace_pci_ack_abort() */ + mace->pci.error;return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1313/2857 nvmet: bound the traddr and trsvcid configfs writes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shao Mingyin <[email protected]>
[ Upstream commit cf399d4abbeddc317f8160a79fefb4016c469862 ]
nvmet_addr_traddr_store() and nvmet_addr_trsvcid_store() reject a write only when count is larger than NVMF_TRADDR_SIZE (256) respectively NVMF_TRSVCID_SIZE (32). A write of exactly that many characters is accepted, and the following
sscanf(page, "%s\n", port->disc_addr.traddr)
has no field width. configfs terminates the buffer at page[count], so the scan writes 256 characters plus the trailing NUL, i.e. 257 bytes, into traddr[256]. The extra byte lands in the following tsas field of the discovery log entry, silently clearing the first TSAS byte (the RDMA queue type, or the TLS section type for TCP). trsvcid has the same off-by-one with a 32-byte write; there the extra byte lands in the reserved bytes that follow trsvcid.
Limit the scans to one byte less than the destination arrays. The count checks can stay as they are so that a normal newline-terminated write is still accepted.
--- drivers/nvme/target/configfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/configfs.c +2 -2
@@ -146,7 +146,7 @@ static ssize_t nvmet_addr_traddr_store(struct config_item *item,if (nvmet_is_port_enabled (port, __func__))return -EACCES ; -if (sscanf (page,"%s\n" , port->disc_addr.traddr) !=1 ) +if (sscanf (page,"%255s" , port->disc_addr.traddr) !=1 )return -EINVAL ;return count; }
@@ -220,7 +220,7 @@ static ssize_t nvmet_addr_trsvcid_store(struct config_item *item,if (nvmet_is_port_enabled (port, __func__))return -EACCES ; -if (sscanf (page,"%s\n" , port->disc_addr.trsvcid) !=1 ) +if (sscanf (page,"%31s" , port->disc_addr.trsvcid) !=1 )return -EINVAL ;return count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1314/2857 perf/core: Dont send SIGTRAP after exec removed the event
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danish Khateeb <[email protected]>
[ Upstream commit 6f083fbccd5f06889bc08e1182bd02c0383b9121 ]
A sigtrap event must also set remove_on_exec, so that its SIGTRAP never reaches a program after exec. But the signal is sent from task work, which only runs on the way back to user space. If the event overflows shortly before execve(), the task work can still be pending when the task enters execve(), and then runs when execve() returns. By then perf_event_exec() has removed the event and the new program has default signal handlers, so the SIGTRAP kills it.
The exec_stress test in the remove_on_exec selftest catches this and fails about half the time in a VM. A process that opens a sigtrap event on itself and then calls execve() is killed by SIGTRAP in 15% to 50% of runs, both on an AMD machine running v7.2 and in a VM, with or without close-on-exec on the event fd.
Commit ffb684f2aa14 ("perf: Fix race between perf_event_exit_task() and perf_pending_task()") made perf_sigtrap() return once perf_event_exit_task() has set ctx->task to TASK_TOMBSTONE. Exec only calls perf_event_exit_task() when the new program is not dumpable, such as a setuid one. An ordinary exec keeps the context and only removes the remove_on_exec events, so the SIGTRAP is still sent.
perf_event_exit_event() sets PERF_EVENT_STATE_EXIT when exec removes the event. If the event fd is close-on-exec and was the last reference to the file, exec also queues the file release as task work. Task work runs newest first, so perf_release() runs before the SIGTRAP work and moves the event on to PERF_EVENT_STATE_DEAD. So don't send the signal when the event state is PERF_EVENT_STATE_EXIT or lower, which means the event has been removed. That also covers PERF_EVENT_STATE_REVOKED, where the PMU is gone.
--- kernel/events/core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
kernel/events/core.c +9 -0
@@ -6586,6 +6586,15 @@ static void perf_sigtrap(struct perf_event *event)if (event->ctx->task ==TASK_TOMBSTONE )return ; +/* +* The event was removed after this signal was queued, e.g. by exec() +* (remove_on_exec), which may also have closed its fd (close-on-exec). +* The new program has default signal handlers, so a SIGTRAP would +* kill it. +*/ +if (READ_ONCE (event->state) <=PERF_EVENT_STATE_EXIT ) +return ; +/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1315/2857 x86/nmi: Ignore negative NMI handler durations
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit ade63af6cfb7b3ca19ced28730fd6461e8d1d410 ]
I am seeing NMI handlers in the Meta fleet reported as running for about 584 years. Over 30 days, 11 AMD and Intel machines logged 637 such lines, for example:
AMD EPYC 9D25 (family 0x1a, model 0x11, stepping 0x0):
[ 1650.616627] INFO: NMI handler (nmi_cpu_backtrace_handler.llvm.9643156322683129580) took too long to run: 18446744073709.551 msecs
Intel Xeon Platinum 8321HC (family 0x6, model 0x55, stepping 0xb):
[360448.230129] INFO: NMI handler (perf_event_nmi_handler) took too long to run: 18446744071018.936 msecs
Intel Xeon D-2191A (family 0x6, model 0x55, stepping 0x4):
[81787.188959] INFO: NMI handler (ghes_notify_nmi) took too long to run: 18446744073709.545 msecs
nmi_handle() times each handler with two sched_clock() reads. When the second read is lower than the first, the u64 subtraction wraps, and nmi_check_duration() treats the result as a duration. In the three examples, the clock went back by less than 1 us, by 2.7 s and by about 6 us.
The wrapped value is also stored in action->max_duration. Every later real duration is smaller, so the handler is never reported again until the next boot.
Whatever makes the clock read lower, a negative difference is not a duration, so return before it is stored or reported. A clock that steps forward is not covered, since that cannot be told from a real stall.
A backwards clock is still worth knowing about, so print the size of the step once per boot. This uses pr_warn_once() rather than WARN, as a stack trace says nothing about the clock and panic_on_warn machines should not go down for it.
--- arch/x86/kernel/nmi.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/kernel/nmi.c +8 -0
@@ -109,6 +109,14 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration) {int remainder_ns, decimal_msecs; +/* sched_clock() went backwards? */ +if ((s64 )duration <0 ) { +pr_warn_once ("NMI handler (%ps): sched_clock() went backwards by %lld ns on CPU%d\n" , + action->handler, -(s64 )duration, +smp_processor_id ()); +return ; + } +if (duration < nmi_longest_ns || duration < action->max_duration)return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1316/2857 iommu/amd: Skip non-IVMD entries when parsing IVRS memory definitions
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Akshay Jindal <[email protected]>
[ Upstream commit e62df37e0eff4d670e78bbd415be2c1675883c15 ]
init_memory_definitions() walks every top-level subtable including the IVHD blocks (type 0x10/0x11/0x40) in the IVRS ACPI table. It interprets each one as a 'struct ivmd_header', solely on m->flags, without first checking that the subtable's type actually is one of the IVMD types (ACPI_IVMD_TYPE, ACPI_IVMD_TYPE_ALL, ACPI_IVMD_TYPE_RANGE).
if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE))
init_unity_map_range(m, table);IVMD_FLAG_UNITY_MAP (0x01) occupies the same bit position as the IVHD flags field's HtTunEn bit. Unlike real hardware, QEMU's AMD IOMMU emulation sets HtTunEn unconditionally (flags=0xD1 for type 0x10, 0x11 for type 0x11), so every QEMU-emitted IVHD block is misidentified as a unity-map/exclusion-range IVMD entry, which subsequently results in the creation of a bogus pci segment. Eg:
AMD-Vi: PCI segment : 0x4000, last bdf : 0x0000
Fix by checking the subtable's type before treating it as IVMD.
--- drivers/iommu/amd/init.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iommu/amd/init.c +12 -2
@@ -2572,6 +2572,15 @@ static int __init init_unity_map_range(struct ivmd_header *m,return 0 ; } +static bool ivrs_block_type_ivmd (u8 type) +{ +if (type ==ACPI_IVMD_TYPE || + type ==ACPI_IVMD_TYPE_ALL || + type ==ACPI_IVMD_TYPE_RANGE ) +return true; +return false; +} +/* iterates over all memory definitions we find in the ACPI table */ static int __init init_memory_definitions (struct acpi_table_header *table) {
@@ -2583,10 +2592,11 @@ static int __init init_memory_definitions(struct acpi_table_header *table)while (p < end) { m = (struct ivmd_header *)p; + p += m->length; +if (!ivrs_block_type_ivmd (m->type)) +continue ;if (m->flags & (IVMD_FLAG_UNITY_MAP |IVMD_FLAG_EXCL_RANGE ))init_unity_map_range (m, table); - - p += m->length; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1317/2857 arm64: kexec_file: Fix elf_headers memory leak in retry loop
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
[ Upstream commit ac302aea3d824ccc99f29b8e499c365cb9a684a9 ]
A retry allocates new elf headers and overwrites image->elf_headers, leaking the previous buffer.
Free it before assigning.
--- arch/arm64/kernel/machine_kexec_file.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kernel/machine_kexec_file.c +2 -0
@@ -123,6 +123,8 @@ int load_other_segments(struct kimage *image,vfree (headers); goto out_err; } + +vfree (image->elf_headers); image->elf_headers = headers; image->elf_load_addr = kbuf.mem; image->elf_headers_sz = headers_sz;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1318/2857 x86/boot: Fix off-by-one error in sme_clear_pgd()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit cb319926808b1cca522d2087a13205e840beb45b ]
The mapping helpers __sme_map_range_pmd() and __sme_map_range_pte(), and therefore sme_encrypt_kernel(), use exclusive end addresses and stop before vaddr reaches vaddr_end.
However, sme_clear_pgd() treats vaddr_end as inclusive when calculating the last PGD entry to clear. If vaddr_end is PGD-aligned, the first PGD entry outside the range is cleared too.
Use vaddr_end - 1 to calculate the last PGD entry within the range.
--- arch/x86/mm/mem_encrypt_identity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/mem_encrypt_identity.c +1 -1
@@ -105,7 +105,7 @@ static void __head sme_clear_pgd(struct sme_populate_pgd_data *ppd)pgd_t *pgd_p; pgd_start = ppd->vaddr &PGDIR_MASK ; - pgd_end = ppd->vaddr_end &PGDIR_MASK ; + pgd_end = (ppd->vaddr_end -1 ) &PGDIR_MASK ; pgd_size = (((pgd_end - pgd_start) /PGDIR_SIZE ) +1 ) *sizeof (pgd_t);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1319/2857 ata: libata-pmp: disable the SEMB port on Marvell 88SM9705
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Ziliani <[email protected]>
[ Upstream commit 6b67cdb463b006e57f15e3fe4ea03b00f0ac9ee5 ]
The Marvell 88SM9705 is a 1-to-5 SATA port multiplier with one additional SEMB (SATA Enclosure Management Bridge) port [1]. Ports 0-4 are device ports and port 5 is the SEMB. The number of fan-out ports in GSCR[2] is 6 when the SEMB is enabled and 5 when it is not, so on boards without the SEMB there is no link 5 and this quirk does nothing. That includes the common 8-port PCIe cards that pair an 88SE9215 with an 88SM9705, which report 5 ports.
The SEMB port never answers SRST. libata probes it like a device port, and every EH round on the PMP ends in a retry loop that lasts about a minute before EH gives up, then starts over:
ata19.15: Port Multiplier 1.2, 0x1b4b:0x9705 r160, 6 ports, feat 0x1/0x1f ata19.05: hard resetting link
ata19.05: failed to resume link (SControl 0)
ata19.05: softreset failed (1st FIS failed)
ata19.05: hard resetting link
...
ata20.05: reset failed, giving up
Disk discovery waits for this, including disks on other controllers.
libata.force only partly works around it. The "disable" horkage only takes effect after IDENTIFY, which the SEMB link never reaches. "norst" on port 5 stops the retry loop, but the disks still come up about a minute later than with this change (see below).
Treat port 5 the same way as port 4 of the Marvell 88SM4140 and mark the link ATA_LFLAG_DISABLED.
Tested on a Synology DX1222 expansion unit (four 88SM9705 r160 behind a Marvell 88SE9235, passed through to a KVM guest, 6 disks), 7.4-rc1 with and without this change, one boot each:
softreset reset failed, last disk
failed giving up attached
7.4-rc1, no libata.force 60 12 197 s
7.4-rc1, libata.force=N.05:norst 0 0 70 s
7.4-rc1 + this patch, no force 0 0 11 sThe problem was first found on a Synology DX1215 with the same chain, where this change brought the disks up after about 20 s instead of about 200 s, including a disk on a separate AHCI controller.
Each PMP still logs one "failed to resume link (SControl 0)" for port 5 at probe time.
--- drivers/ata/libata-pmp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/ata/libata-pmp.c +14 -0
@@ -471,6 +471,20 @@ static void sata_pmp_quirks(struct ata_port *ap)if (link->pmp ==4 ) link->flags |=ATA_LFLAG_DISABLED ; } + }else if (vendor ==0x1b4b && devid ==0x9705 ) { +/* +* Marvell 88SM9705 quirks +* +* 1-to-5 PMP with an extra SEMB port. It reports 6 ports and +* port 5 is the SEMB, which never answers SRST: EH spends about +* a minute per round retrying it, and disk discovery waits for +* that. Seen behind a Marvell 88SE9235 in the Synology DX1215 +* and DX1222. +*/ +ata_for_each_link (link, ap,EDGE ) { +if (link->pmp ==5 ) + link->flags |=ATA_LFLAG_DISABLED ; + } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1320/2857 can: replace ARPHRD_CAN type checks with can_get_ml_priv()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 962947b69589881167054bae5accc8abfd5aa4b6 upstream.
Commit 4e096a18867a ("net: introduce CAN specific pointer in the struct net_device") introduced an explicit way to assign the midlayer private pointer (dev->ml_priv) to named users like ML_PRIV_CAN. A valid pointer returned by can_get_ml_priv() therefore identifies a real CAN device.
The referenced commit only converted the j1939 and proc code to this check, while the other parts of the CAN subsystem still rely on dev->type == ARPHRD_CAN.
The TUNSETLINK ioctl allows a down TUN/TAP device to set its hardware type to ARPHRD_CAN while dev->ml_priv remains NULL. Such a repurposed netdevice passes the ARPHRD_CAN checks.
Commit 8aa59e355949 ("can: af_can: fix NULL pointer dereference in can_rx_register()") already made can_rx_register() reject such devices. But can_rx_unregister() still only checks dev->type and dereferences the NULL ml_priv when it walks the receive lists of the device.
CAN_ISOTP reaches this path: isotp_bind() ignores the return values of can_rx_register() and binds the socket anyway. When the socket is released or the device is unregistered, isotp_release() and isotp_notify() remove the filters that have never been registered and trigger the NULL pointer dereference in can_rx_unregister(). This only requires owning a TUN/TAP device or CAP_NET_ADMIN in an unprivileged user namespace.
Convert the remaining ARPHRD_CAN checks in af_can, bcm, gw, isotp and raw to can_get_ml_priv().
[ backport to 6.1: This tree has no can_skb_ext, so only the ARPHRD_CAN
check is removed from the conditions in can_rcv(), canfd_rcv() and canxl_rcv(). Add the <linux/can/can-ml.h> include to raw.c, which upstream got with commit faba5860fcf9 ("can: raw: instantly reject disabled CAN frames"). ]
--- net/can/af_can.c | 12 ++++++------ net/can/bcm.c | 7 ++++--- net/can/gw.c | 7 ++++--- net/can/isotp.c | 5 +++-- net/can/raw.c | 5 +++-- 5 files changed, 20 insertions(+), 16 deletions(-)
net/can/af_can.c +6 -6
@@ -224,7 +224,7 @@ int can_send(struct sk_buff *skb, int loop) goto inval_skb; } -if (unlikely (skb->dev->type !=ARPHRD_CAN )) { +if (unlikely (!can_get_ml_priv (skb->dev))) { err = -EPERM ; goto inval_skb; }
@@ -451,7 +451,7 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id,/* insert new receiver (dev,canid,mask) -> (func,data) */ -if (dev && (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev))) +if (dev && !can_get_ml_priv (dev))return -ENODEV ;if (dev && !net_eq (net,dev_net (dev)))
@@ -518,7 +518,7 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,struct can_rcv_lists_stats *rcv_lists_stats = net->can.rcv_lists_stats;struct can_dev_rcv_lists *dev_rcv_lists; -if (dev && dev->type !=ARPHRD_CAN ) +if (dev && !can_get_ml_priv (dev))return ;if (dev && !net_eq (net,dev_net (dev)))
@@ -684,7 +684,7 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev)static int can_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) { -if (unlikely (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev) || !can_is_can_skb (skb))) { +if (unlikely (!can_get_ml_priv (dev) || !can_is_can_skb (skb))) {pr_warn_once ("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n" , dev->type, skb->len);
@@ -699,7 +699,7 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,static int canfd_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) { -if (unlikely (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev) || !can_is_canfd_skb (skb))) { +if (unlikely (!can_get_ml_priv (dev) || !can_is_canfd_skb (skb))) {pr_warn_once ("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n" , dev->type, skb->len);
@@ -714,7 +714,7 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,static int canxl_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev) { -if (unlikely (dev->type !=ARPHRD_CAN || !can_get_ml_priv (dev) || !can_is_canxl_skb (skb))) { +if (unlikely (!can_get_ml_priv (dev) || !can_is_canxl_skb (skb))) {pr_warn_once ("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n" , dev->type, skb->len);
net/can/bcm.c +4 -3
@@ -54,6 +54,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/skb.h> #include <linux/can/bcm.h>
@@ -1668,7 +1669,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) goto out_release; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) {dev_put (dev); ret = -ENODEV ; goto out_release;
@@ -1816,7 +1817,7 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg, {struct net_device *dev =netdev_notifier_info_to_dev (ptr); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg !=NETDEV_UNREGISTER && msg !=NETDEV_DOWN )return NOTIFY_DONE ;
@@ -1972,7 +1973,7 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len, ret = -ENODEV ; goto fail; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) {dev_put (dev); ret = -ENODEV ; goto fail;
net/can/gw.c +4 -3
@@ -52,6 +52,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/skb.h> #include <linux/can/gw.h>
@@ -603,7 +604,7 @@ static int cgw_notifier(struct notifier_block *nb,struct net_device *dev =netdev_notifier_info_to_dev (ptr);struct net *net =dev_net (dev); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg ==NETDEV_UNREGISTER ) {
@@ -1154,7 +1155,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh,if (!gwj->src.dev) goto out; -if (gwj->src.dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (gwj->src.dev)) goto out; gwj->dst.dev =__dev_get_by_index (net, gwj->ccgw.dst_idx);
@@ -1162,7 +1163,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh,if (!gwj->dst.dev) goto out; -if (gwj->dst.dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (gwj->dst.dev)) goto out;ASSERT_RTNL ();
net/can/isotp.c +3 -2
@@ -65,6 +65,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/skb.h> #include <linux/can/isotp.h>
@@ -1556,7 +1557,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) err = -ENODEV ; goto out; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) { err = -ENODEV ; goto out_put_dev; }
@@ -1856,7 +1857,7 @@ static int isotp_notifier(struct notifier_block *nb, unsigned long msg, {struct net_device *dev =netdev_notifier_info_to_dev (ptr); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg !=NETDEV_UNREGISTER && msg !=NETDEV_DOWN )return NOTIFY_DONE ;
net/can/raw.c +3 -2
@@ -49,6 +49,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/can.h> +#include <linux/can/can-ml.h> #include <linux/can/core.h> #include <linux/can/dev.h> /* for can_is_canxl_dev_mtu() */ #include <linux/can/skb.h>
@@ -318,7 +319,7 @@ static int raw_notifier(struct notifier_block *nb, unsigned long msg, {struct net_device *dev =netdev_notifier_info_to_dev (ptr); -if (dev->type !=ARPHRD_CAN ) +if (!can_get_ml_priv (dev))return NOTIFY_DONE ;if (msg !=NETDEV_UNREGISTER && msg !=NETDEV_DOWN )return NOTIFY_DONE ;
@@ -458,7 +459,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len) err = -ENODEV ; goto out; } -if (dev->type !=ARPHRD_CAN ) { +if (!can_get_ml_priv (dev)) { err = -ENODEV ; goto out_put_dev; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1321/2857 can: protect the receive lists with a per-device lock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 0f3ad9ab40e3dad06d5c0693806e07935ceedbc3 upstream.
The receive lists of a CAN device are located in the device's can_ml_priv and travel with the device when it is moved to another network namespace. But they are protected by the per-netns rcvlists_lock. So can_rx_unregister() needs dev_net(dev) to pick the right lock and silently returns when the passed namespace does not match dev_net(dev) anymore.
isotp_release() and bcm_release() leave their notifier list before they take any lock that serializes against the netdev notifier, which runs under RTNL. When the bound device is moved to another namespace in this window, the notifier skips the socket and the release path has to remove the filters itself. isotp_release() passes the socket's namespace, which does not match dev_net(dev) anymore. bcm_rx_unreg() passes dev_net(dev), which can_rx_unregister() reads again for its check, so a namespace change between both reads makes the check fail as well. In both cases can_rx_unregister() silently returns. As can_rx_register() stores rcv->sk without a reference, the remaining receivers point to the freed socket (isotp) or the freed op (bcm):
BUG: KASAN: use-after-free in isotp_rcv+0x1570/0x24d0 Read of size 1 at addr ffff888118130552 by task isotp_ns_uaf/578 can_rcv_filter+0x4af/0x8c0 can_receive+0x28d/0x3c0 can_rcv+0x2a9/0x310 __netif_receive_skb_one_core+0x21a/0x260 process_backlog+0x210/0x760
Besides this, the lists of a device are protected by the rcvlists_lock of the namespace that is passed in. Callers which pass dev_net(dev) read it at different times, so the same lists may be modified under the locks of different namespaces while the device is moved.
Taking RTNL in these release paths is no option: raw_bind(), raw_setsockopt() and raw_release() already hold RTNL while adding and removing up to CAN_RAW_FILTER_MAX filters per socket, which unprivileged users can trigger repeatedly and which makes RTNL a global bottleneck.
Instead fix the root cause and add a spinlock to struct can_dev_rcv_lists, which protects the receive lists of a CAN device or the 'any' CAN device lists of a namespace. It is initialized in can_set_ml_priv(), which is used by all CAN network devices. With this, can_rx_unregister() finds the subscription independently of the current namespace of the device. The protocols keep the device valid with their tracked references. The per-netns rcvlists_lock only protects the receive list statistics anymore, and CAN_RAW, CAN_BCM and CAN_ISOTP pass the namespace that has been used for can_rx_register().
So isotp_release() and bcm_release() now remove their filters correctly without RTNL, and raw_release(), raw_setsockopt(), raw_bind() and isotp_bind() do not need RTNL anymore and add and remove their filters under lock_sock(). To serialize bind() with NETDEV_UNREGISTER, bind() publishes the device inside the RCU section of its lookup, and raw_notify() and isotp_notify() recheck the bound device under lock_sock(). As RTNL does not keep NETDEV_DOWN out of bind() anymore, bind() checks IFF_UP after publishing the bound device, with a barrier pair against raw_notify() and isotp_notify(), so a down transition during bind() is still reported with ENETDOWN.
[ backport to 6.1: Adapt the can_pernet_init() context to kzalloc() as
this tree has no kzalloc_obj(). so->dev holds an untracked reference with dev_hold() in this tree. raw_setsockopt() has no raw_setsockopt_locked() split from commit 1e5185c09058 ("can: raw: add locking for raw flags bitfield") in this tree, so remove the RTNL locking from the CAN_RAW_FILTER and CAN_RAW_ERR_FILTER cases directly. Keep the NULL check for dev_put() in raw_bind() and use sock_net(sk) in raw_release(). ]
--- include/linux/can/can-ml.h | 3 ++ include/net/netns/can.h | 2 +- net/can/af_can.c | 39 +++++++++----- net/can/bcm.c | 43 +++++---------- net/can/isotp.c | 89 +++++++++++++++++++------------ net/can/raw.c | 106 +++++++++++++++++++++++++------------ 6 files changed, 166 insertions(+), 116 deletions(-)
include/linux/can/can-ml.h +3 -0
@@ -45,6 +45,7 @@#include <linux/can.h> #include <linux/list.h> #include <linux/netdevice.h> +#include <linux/spinlock.h> #define CAN_SFF_RCV_ARRAY_SZ (1 << CAN_SFF_ID_BITS)#define CAN_EFF_RCV_HASH_BITS 10
@@ -53,6 +54,7 @@enum {RX_ERR ,RX_ALL ,RX_FIL ,RX_INV ,RX_MAX };struct can_dev_rcv_lists { +spinlock_t lock;/* protects the receive lists and entries */ struct hlist_head rx[RX_MAX ];struct hlist_head rx_sff[CAN_SFF_RCV_ARRAY_SZ ];struct hlist_head rx_eff[CAN_EFF_RCV_ARRAY_SZ ];
@@ -74,6 +76,7 @@ static inline struct can_ml_priv *can_get_ml_priv(struct net_device *dev)static inline void can_set_ml_priv (struct net_device *dev,struct can_ml_priv *ml_priv) { +spin_lock_init (&ml_priv->dev_rcv_lists.lock);netdev_set_ml_priv (dev, ml_priv,ML_PRIV_CAN ); }
include/net/netns/can.h +1 -1
@@ -29,7 +29,7 @@ struct netns_can {/* receive filters subscribed for 'all' CAN devices */ struct can_dev_rcv_lists *rx_alldev_list; -spinlock_t rcvlists_lock; +spinlock_t rcvlists_lock;/* protects the rcv_entries(_max) stats */ struct timer_list stattimer;/* timer for statistics update */ struct can_pkg_stats *pkg_stats;struct can_rcv_lists_stats *rcv_lists_stats;
net/can/af_can.c +25 -14
@@ -461,9 +461,10 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id,if (!rcv)return -ENOMEM ; -spin_lock_bh (&net->can.rcvlists_lock); - dev_rcv_lists =can_dev_rcv_lists_find (net, dev); + +spin_lock_bh (&dev_rcv_lists->lock); + rcv_list =can_rcv_list_find (&can_id, &mask, dev_rcv_lists); rcv->can_id = can_id;
@@ -477,6 +478,9 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id,hlist_add_head_rcu (&rcv->list, rcv_list); dev_rcv_lists->entries++; +spin_unlock_bh (&dev_rcv_lists->lock); + +spin_lock_bh (&net->can.rcvlists_lock); rcv_lists_stats->rcv_entries++; rcv_lists_stats->rcv_entries_max =max (rcv_lists_stats->rcv_entries_max, rcv_lists_stats->rcv_entries);
@@ -508,6 +512,14 @@ static void can_rx_delete_receiver(struct rcu_head *rp)* * Description: * Removes subscription entry depending on given (subscription) values. +* The receive lists of a CAN device are protected by a per-device lock, +* so the subscription is found even when the device has been moved to +* another network namespace after can_rx_register(). The caller has to +* ensure that @dev stays valid, e.g. by holding a reference to @dev or +* RTNL. @net should be the namespace that has been used for +* can_rx_register(). It selects the 'any' CAN device lists for +* @dev == NULL and is otherwise only used for the receive list +* statistics, which become imprecise when another namespace is passed. */ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, canid_t mask, void (*func)(struct sk_buff *, void *),
@@ -521,12 +533,10 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,if (dev && !can_get_ml_priv (dev))return ; -if (dev && !net_eq (net,dev_net (dev))) -return ; + dev_rcv_lists =can_dev_rcv_lists_find (net, dev); -spin_lock_bh (&net->can.rcvlists_lock); +spin_lock_bh (&dev_rcv_lists->lock); - dev_rcv_lists =can_dev_rcv_lists_find (net, dev); rcv_list =can_rcv_list_find (&can_id, &mask, dev_rcv_lists);/* Search the receiver list for the item to delete. This should
@@ -546,26 +556,26 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,* a warning here. */ if (!rcv) { +spin_unlock_bh (&dev_rcv_lists->lock);pr_warn ("can: receive list entry not found for dev %s, id %03X, mask %03X\n" ,DNAME (dev), can_id, mask); - goto out; +return ; }hlist_del_rcu (&rcv->list); dev_rcv_lists->entries--; +spin_unlock_bh (&dev_rcv_lists->lock); + +spin_lock_bh (&net->can.rcvlists_lock);if (rcv_lists_stats->rcv_entries >0 ) rcv_lists_stats->rcv_entries--; - - out:spin_unlock_bh (&net->can.rcvlists_lock);/* schedule the receiver item for deletion */ -if (rcv) { -if (rcv->sk) -sock_hold (rcv->sk); -call_rcu (&rcv->rcu, can_rx_delete_receiver); - } +if (rcv->sk) +sock_hold (rcv->sk); +call_rcu (&rcv->rcu, can_rx_delete_receiver); }EXPORT_SYMBOL (can_rx_unregister);
@@ -796,6 +806,7 @@ static int can_pernet_init(struct net *net)kzalloc (sizeof (*net->can.rx_alldev_list),GFP_KERNEL );if (!net->can.rx_alldev_list) goto out; +spin_lock_init (&net->can.rx_alldev_list->lock); net->can.pkg_stats =kzalloc (sizeof (*net->can.pkg_stats),GFP_KERNEL );if (!net->can.pkg_stats) goto out_free_rx_alldev_list;
net/can/bcm.c +12 -31
75 lines not on this page · raw message
net/can/isotp.c +54 -35
186 lines not on this page · raw message
net/can/raw.c +71 -35
248 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1322/2857 ceph: clamp the inline data length in ceph_fill_inline_data()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanglei Zhu <[email protected]>
[ Upstream commit 9c1d14d3b66b3e1dd96ee664c0dd2548f2b77a52 ]
The MDS decides how much inline data to attach to a reply, and the client parses inline_len without any upper bound: ceph_decode_need() only verifies that the message actually carries that many bytes. ceph_fill_inline_data() then copies the data into a single page with no length check, so a malicious or buggy MDS returning more inline data than the page can hold writes past its end.
Clamp the length to PAGE_SIZE so both callers, handle_cap_grant() and fill_inode(), are covered.
--- fs/ceph/addr.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ceph/addr.c +3 -0
@@ -1689,6 +1689,9 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,dout ("fill_inline_data %p %llx.%llx len %zu locked_page %p\n" , inode,ceph_vinop (inode), len, locked_page); +if (len >PAGE_SIZE ) + len =PAGE_SIZE ; +if (len >0 ) {void *kaddr =kmap_atomic (page);memcpy (kaddr, data, len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1323/2857 arm64: sdei: Run the event handler on the kernel vectors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
[ Upstream commit 9bf6ee7952c7ee151c30e0fffcfc61b58127c899 ]
With KPTI, VBAR_EL1 holds the trampoline vectors from the return to EL0 until the next exception from EL0 maps the kernel and installs the kernel vectors. The trampoline vectors only handle exceptions from EL0; their current-EL half is zero-filled.
An SDEI event is dispatched regardless of PSTATE.DAIF, so it lands there whenever the CPU is in user space. The SDEI entry trampoline maps the kernel but leaves VBAR_EL1 alone. An exception taken by the handler then executes the zeros, takes an undefined instruction exception to the same vector, and loops there forever. The event never completes and the CPU is lost; RCU stall reports are the first sign of it.
RAS notifications land in user space whenever a task consumes the error, and NMI backtraces land wherever the CPU happens to be. The GHES handler takes no exception on its own, but any exception in the handler path does it: a WARN, a kprobe hit, or a fault fixed up by a _nofault() accessor.
Install the kernel vectors in __sdei_handler() when VBAR_EL1 holds the trampoline vectors, and restore it before returning to firmware. The switch covers irqentry_nmi_enter() and irqentry_nmi_exit() too, as Usama Arif pointed out: their tracepoints and context tracking WARNs can take an exception as well.
The IRQ-like resume into user space must still go through the trampoline to map the kernel. do_sdei_event() takes the interrupted VBAR_EL1 and keeps basing the resume address on it.
--- arch/arm64/include/asm/sdei.h | 3 ++- arch/arm64/kernel/entry-common.c | 21 ++++++++++++++++++++- arch/arm64/kernel/sdei.c | 6 ++++-- 3 files changed, 26 insertions(+), 4 deletions(-)
arch/arm64/include/asm/sdei.h +2 -1
@@ -44,7 +44,8 @@ asmlinkage unsigned long __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg);unsigned long do_sdei_event (struct pt_regs *regs, -struct sdei_registered_event *arg); +struct sdei_registered_event *arg, +unsigned long vbar);unsigned long sdei_arch_get_entry_point (int conduit);#define sdei_arch_get_entry_point (x) sdei_arch_get_entry_point(x)
arch/arm64/kernel/entry-common.c +20 -1
@@ -26,6 +26,7 @@#include <asm/stacktrace.h> #include <asm/sysreg.h> #include <asm/system_misc.h> +#include <asm/vectors.h> /* * Handle IRQ/context state management when entering from kernel mode.
@@ -854,6 +855,7 @@ asmlinkage void noinstr handle_bad_stack(struct pt_regs *regs) asmlinkage noinstr unsigned long__sdei_handler (struct pt_regs *regs,struct sdei_registered_event *arg) { +unsigned long vbar;unsigned long ret;/*
@@ -878,10 +880,27 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) else if (cpu_has_pan()) set_pstate_pan(0); +/* +* With KPTI, VBAR_EL1 holds the trampoline vectors from the return to +* EL0 until the next exception from EL0 maps the kernel. They only +* handle exceptions from EL0: an exception taken here would run their +* empty current-EL half and never come back. Switch to the kernel +* vectors. The IRQ-like resume keeps using the interrupted VBAR, so it +* still goes through the trampoline. +*/ + vbar =read_sysreg (vbar_el1); +if (arm64_kernel_unmapped_at_el0 () && + vbar == (unsigned long )raw_cpu_read (this_cpu_vector)) { +write_sysreg ((unsigned long )vectors, vbar_el1); +isb (); + } +arm64_enter_nmi (regs); - ret =do_sdei_event (regs, arg); + ret =do_sdei_event (regs, arg, vbar);arm64_exit_nmi (regs); +write_sysreg (vbar, vbar_el1); + return ret; }#endif /* CONFIG_ARM_SDE_INTERFACE */
arch/arm64/kernel/sdei.c +4 -2
@@ -208,16 +208,18 @@ unsigned long sdei_arch_get_entry_point(int conduit)* SDEI_EV_HANDLED - success, return to the interrupted context. * SDEI_EV_FAILED - failure, return this error code to firmare. * virtual-address - success, return to this address. +* +* vbar is the interrupted context's VBAR_EL1, for the IRQ-like resume. */ unsigned long __kprobes do_sdei_event (struct pt_regs *regs, -struct sdei_registered_event *arg) +struct sdei_registered_event *arg, +unsigned long vbar) {u32 mode;int i, err =0 ;int clobbered_registers =4 ;u64 elr =read_sysreg (elr_el1);u32 kernel_mode =read_sysreg (CurrentEL) |1 ;/* +SPSel */ -unsigned long vbar =read_sysreg (vbar_el1);if (arm64_kernel_unmapped_at_el0 ()) clobbered_registers++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1324/2857 arm64: sdei: Preserve the interrupted contexts exception registers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
[ Upstream commit 58c1eb84e97701c583605ba2fd553b69afba2245 ]
An SDEI event is dispatched by firmware regardless of PSTATE.DAIF, so it can interrupt the kernel where the exception registers are live:
- exception entry, before kernel_entry has saved ELR_EL1/SPSR_EL1 and before the C handler has read ESR_EL1/FAR_EL1;
- exception return, after kernel_exit has loaded ELR_EL1/SPSR_EL1 and before the ERET.
An IRQ or pseudo-NMI cannot arrive there with PSTATE.I set. Firmware saves only x0-x17, PC and PSTATE around an SDEI event, so a synchronous exception taken by the handler overwrites the interrupted context's ELR, SPSR, ESR and FAR. do_sdei_event() only notices that ELR changed, and warns.
The interrupted context then carries on with the handler's state. A task interrupted on its way into the kernel can be sent SIGILL for the handler's kernel data abort. A task interrupted on its way back to user space ERETs to EL1, at the handler's fixup address, with user registers loaded.
With SDEI delivering NMI backtraces, this happens in normal operation. The handler runs show_regs(), which reads through possibly-NULL pointers with the _nofault() accessors. print_worker_info() faults this way for a kworker that is not running a work item, and a single sysrq-l warned once per such kworker.
Save ELR, SPSR, ESR and FAR in __sdei_handler() before irqentry_nmi_enter(), which can take an exception too, and restore them after irqentry_nmi_exit().
Once they are restored, a nested exception is harmless if its handler is safe in NMI context. That holds for EL1 data aborts on translation, permission and access-flag faults, which never take the mmap lock in NMI context, and for BRK. Warn once, with the syndrome, about any other exception class.
[ kas: keep arm64_enter_nmi()/arm64_exit_nmi() in __sdei_handler();
open-code the fault type check, no esr_fsc_is_*() helpers here ]
--- arch/arm64/kernel/entry-common.c | 21 +++++++++++- arch/arm64/kernel/sdei.c | 55 ++++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 10 deletions(-)
arch/arm64/kernel/entry-common.c +20 -1
@@ -855,7 +855,7 @@ asmlinkage void noinstr handle_bad_stack(struct pt_regs *regs) asmlinkage noinstr unsigned long__sdei_handler (struct pt_regs *regs,struct sdei_registered_event *arg) { -unsigned long vbar; +unsigned long elr, spsr, esr, far, vbar;unsigned long ret;/*
@@ -880,6 +880,17 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)else if (cpu_has_pan ())set_pstate_pan (0 ); +/* +* Nothing saved the interrupted context's exception registers on the +* way in, and it may be in the middle of exception entry or return +* (SDEI ignores DAIF). Save them before anything can take an exception +* and overwrite them. +*/ + elr =read_sysreg (elr_el1); + spsr =read_sysreg (spsr_el1); + esr =read_sysreg (esr_el1); + far =read_sysreg (far_el1); +/* * With KPTI, VBAR_EL1 holds the trampoline vectors from the return to * EL0 until the next exception from EL0 maps the kernel. They only
@@ -899,6 +910,14 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) ret =do_sdei_event (regs, arg, vbar);arm64_exit_nmi (regs); +/* +* Put them back unconditionally. An unchanged ELR does not rule out a +* nested exception: one may have returned to the same address. +*/ +write_sysreg (elr, elr_el1); +write_sysreg (spsr, spsr_el1); +write_sysreg (esr, esr_el1); +write_sysreg (far, far_el1);write_sysreg (vbar, vbar_el1);return ret;
arch/arm64/kernel/sdei.c +46 -9
76 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1325/2857 microblaze: restore the ABI argument home area below pt_regs (PTO)
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ramin Moussavi <[email protected]>
commit c35d40a3efd2e575ef51a761e983f2bf7113be6c upstream.
The MicroBlaze ABI has the caller reserve stack space for the arguments it passes in registers: REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1 in the gcc backend, so a callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C functions from entry.S with r1 pointing at pt_regs, handing the callee license to spill its incoming arguments over the saved registers -- the syscall dispatch is the worst case, where the first argument slot is PT_R1, the saved user stack pointer.
This was latent until GCC 15: since 3b9b8d6cfdf5 ("ira: Scale save/restore costs of callee save registers with block frequency") the allocator prefers spilling incoming arguments over copying them into callee-saved registers, and a kernel built with gcc >= 15 (without the TARGET_CALLEE_SAVE_COST workaround some distributions carry) corrupts PT_R1 on the first syscall: init takes SIGSEGV and the kernel panics.
The kernel had exactly this reservation until 2011:
commit 6e83557c38b4 ("microblaze: Remove r0_ram pointer and PTO alignment") removed STATE_SAVE_ARG_SPACE and with it the PTO offset, as part of cleaning up what was thought to be copied-from-v850 leftovers. Restore
it: the frame is STATE_SAVE_SIZE = PT_SIZE + PTO, r1 stays at the frame base through every asm-to-C call, and the saved registers are reached at r1 + PTO + PT_*. PTO is 28 rather than the historic 24, which was one word short: FIRST_PARM_OFFSET is 4 and REG_PARM_STACK_SPACE is 24, so the area spans [sp+4, sp+28) and needs 28 bytes. With 24 the last argument slot overlapped pt_regs' r0 -- harmless only because r0 is the constant-zero register. STACK_BOUNDARY is 32 bits, so 28 needs no further rounding.
Two places deliberately keep their mainline addressing. hw_exception_handler.S needs no offset change: its real-mode handler saves into the standalone pt_pool_space buffer rather than a stack frame, and _unaligned_data_exception works through a pointer to pt_regs in r7, where plain PT_* offsets are already right. And the user-SP reload after popping the frame keeps PT_R1 - PT_SIZE because PTO cancels there: (PTO + PT_R1) - (PT_SIZE + PTO) = PT_R1 - PT_SIZE. Both are exactly as the pre-2011 code had them.
The instruction count is unchanged -- the same instructions with different immediates, no per-call reservation and no trampolines. The cost is 28 bytes more kernel stack per saved frame.
--- arch/microblaze/include/asm/entry.h | 13 + arch/microblaze/include/asm/processor.h | 2 +- arch/microblaze/kernel/entry.S | 329 +++++++++--------- arch/microblaze/kernel/hw_exception_handler.S | 5 + arch/microblaze/kernel/process.c | 5 +- 5 files changed, 189 insertions(+), 165 deletions(-)
arch/microblaze/include/asm/entry.h +13 -0
@@ -21,6 +21,19 @@#define PER_CPU (var) var +/* +* The MicroBlaze ABI has the caller reserve an argument home area: +* REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1, so a +* callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C +* with r1 at the frame base, so reserve that area below pt_regs and reach +* the saved registers through PTO. This restores what 6e83557c38b4 +* ("microblaze: Remove r0_ram pointer and PTO alignment") removed; the old +* value of 24 was one word short and left the last argument slot +* overlapping pt_regs' r0. +*/ +#define PTO 28 +#define STATE_SAVE_SIZE (PT_SIZE + PTO) +# ifndef __ASSEMBLY__ DECLARE_PER_CPU(unsigned int, KSP); /* Saved kernel stack pointer */ DECLARE_PER_CPU(unsigned int, KM); /* Kernel/user mode */
arch/microblaze/include/asm/processor.h +1 -1
@@ -73,7 +73,7 @@ unsigned long __get_wchan(struct task_struct *p);# define task_regs (task) ((struct pt_regs *)task_tos(task) - 1)# define task_pt_regs_plus_args (tsk) \ - ((void *)task_pt_regs(tsk)) + (((void *)task_pt_regs(tsk)) - PTO)# define task_sp (task) (task_regs(task)->r1)# define task_pc (task) (task_regs(task)->pc)
arch/microblaze/kernel/entry.S +167 -162
675 lines not on this page · raw message
arch/microblaze/kernel/hw_exception_handler.S +5 -0
@@ -313,6 +313,11 @@ _MB_HW_ExceptionVectorTable: .align 4 .ent _hw_exception_handler _hw_exception_handler: + /* + * This handler saves into the static pt_pool_space buffer, not into a + * stack frame, so the plain PT_* offsets are right here -- do not add + * the PTO of entry.S's frames. + */ swi r1, r0, TOPHYS(pt_pool_space + PT_R1); /* GET_SP */ /* Save date to kernel memory. Here is the problem * when you came from user space */
arch/microblaze/kernel/process.c +3 -2
@@ -19,6 +19,7 @@#include <linux/bitops.h> #include <linux/ptrace.h> #include <asm/cacheflush.h> +#include <asm/entry.h> void show_regs (struct pt_regs *regs) {
@@ -65,7 +66,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)* the registers. That's OK for a brand new thread.*/ memset (childregs,0 ,sizeof (struct pt_regs ));memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; ti->cpu_context.r20 = (unsigned long )args->fn; ti->cpu_context.r19 = (unsigned long )args->fn_arg; childregs->pt_mode =1 ;
@@ -79,7 +80,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) childregs->r1 = usp;memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; childregs->msr |=MSR_UMS ;/* we should consider the fact that childregs is a copy of the parent
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1326/2857 vxlan: Stop rejecting dynamic FDB entries with a nexthop ID
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 7308ef8b4a6779a39f68d053c19b53a5c584a663 ]
Commit 98fc57d16744 ("vxlan: reject dynamic fdb entries that reference a nexthop id") started rejecting FDB entries that point to FDB nexthops unless they are configured as "permanent" or "static". The intent was to prevent such entries from being aged out by vxlan_cleanup(), which runs without RTNL and can therefore race with other VXLAN devices that modify the same per-nexthop FDB list.
However, FRR installs remote MACs that are behind a multihomed Ethernet Segment (EVPN-MH) as dynamic FDB entries that point to an FDB nexthop group. Since the above commit, these entries are rejected and traffic towards the corresponding MACs is flooded to all the remote VTEPs.
These entries are also marked as externally learned ("extern_learn") and are therefore skipped by vxlan_cleanup(), but exempting externally learned entries from the checks is not enough: vxlan_cleanup() reads the state and flags of an entry without the hash lock, so an entry that is concurrently changed from dynamic and externally learned to static can still be aged out.
Instead, remove the checks added by the above commit and make vxlan_cleanup() skip FDB entries that point to FDB nexthops. Such entries can only be configured from user space, cannot be learned and cannot roam, so there is no reason to age them out. The nexthop pointer of an FDB entry is set before the entry is linked and is only cleared after it was unlinked and an RCU grace period has passed, so it can be checked without the hash lock.
Adjust the test cases added by the above commit and add a test case that checks that dynamic FDB entries that point to FDB nexthops are not aged out. Without the fix:
# ./fib_nexthops.sh -t "ipv4_fdb_grp_fcnal ipv6_fdb_grp_fcnal"
IPv4 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [FAIL] TEST: Fdb mac add with nexthop group and extern_learn [FAIL] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [FAIL]
[...]
IPv6 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [FAIL] TEST: Fdb mac add with nexthop group and extern_learn [FAIL] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [FAIL]
[...]
Tests passed: 44
Tests failed: 6
Tests skipped: 0
With the fix:
# ./fib_nexthops.sh -t "ipv4_fdb_grp_fcnal ipv6_fdb_grp_fcnal"
IPv4 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [ OK ] TEST: Fdb mac add with nexthop group and extern_learn [ OK ] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [ OK ]
[...]
IPv6 fdb groups functional
--------------------------
[...]
TEST: Fdb mac add with nexthop group and dynamic state [ OK ] TEST: Fdb mac add with nexthop group and extern_learn [ OK ] TEST: Fdb mac without nexthop group aged out [ OK ] TEST: Fdb mac with nexthop group not aged out [ OK ]
[...]
Tests passed: 50
Tests failed: 0
Tests skipped: 0
[ idosch: fixed a small conflict in vxlan_fdb_add(), adjusted the
vxlan_cleanup() hunk to the per-bucket FDB iteration in this tree and open-coded the wait in fdb_entry_aged() since slowwait() is not available to fib_nexthops.sh in this tree ]
--- drivers/net/vxlan/vxlan_core.c | 14 ++----- tools/testing/selftests/net/fib_nexthops.sh | 46 +++++++++++++++------ 2 files changed, 37 insertions(+), 23 deletions(-)
drivers/net/vxlan/vxlan_core.c +3 -11
@@ -1054,12 +1054,6 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,return -EOPNOTSUPP ; } -if (rcu_access_pointer (f->nh) && - !(state & (NUD_PERMANENT |NUD_NOARP ))) { -NL_SET_ERR_MSG (extack,"Cannot make a nexthop fdb dynamic" ); -return -EOPNOTSUPP ; - } -/* Do not allow an externally learned entry to take over an entry added * by the user. */
@@ -1327,11 +1321,6 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],if (err)return err; -if (nhid && !(ndm->ndm_state & (NUD_PERMANENT |NUD_NOARP ))) { -NL_SET_ERR_MSG (extack,"A nexthop fdb cannot be dynamic" ); -return -EINVAL ; - } -if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)return -EAFNOSUPPORT ;
@@ -2979,6 +2968,9 @@ static void vxlan_cleanup(struct timer_list *t)if (f->flags &NTF_EXT_LEARNED )continue ; +if (rcu_access_pointer (f->nh)) +continue ; + timeout =READ_ONCE (f->used) + vxlan->cfg.age_interval *HZ ;if (time_before_eq (timeout, jiffies)) { netdev_dbg(vxlan->dev,
tools/testing/selftests/net/fib_nexthops.sh +34 -12
68 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1327/2857 mm/damon/core: move static variable last_nr_regions to damon_ctx
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
[ Upstream commit 26ae50a0901a44f7d50053f87dc38abd9f9a269c ]
kdamond_split_regions() uses a static variable last_nr_regions, to infer if the region boundaries are too stable. If it looks too stable, it does a more aggressive region split because it might be a fake stability coming from non-aggressive split. Because the variable is static, the inference can be racy and wrong when multiple kdamonds are running in parallel.
The user impact is not critical. No crash, no leak. DAMON's best-effort monitoring accuracy can be degraded when multiple kdamonds are used in parallel and the workload has certain access patterns. Still it is a bug that is better to fix.
Move the variable into the damon_ctx struct to fix the problem.
--- include/linux/damon.h | 6 ++++++ mm/damon/core.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-)
include/linux/damon.h +6 -0
@@ -465,6 +465,12 @@ struct damon_ctx {struct list_head adaptive_targets;struct list_head schemes; +/* private: */ +/* +* number of regions after last merge. Read kdamond_split_regions() +* for more details. +*/ +unsigned long last_nr_regions; };static inline struct damon_region *damon_next_region (struct damon_region *r)
mm/damon/core.c +2 -3
@@ -1101,7 +1101,6 @@ static void kdamond_split_regions(struct damon_ctx *ctx) {struct damon_target *t;unsigned int nr_regions =0 ; -static unsigned int last_nr_regions;int nr_subregions =2 ;damon_for_each_target (t, ctx)
@@ -1111,14 +1110,14 @@ static void kdamond_split_regions(struct damon_ctx *ctx)return ;/* Maybe the middle of the region has different access frequency */ -if (last_nr_regions == nr_regions && +if (ctx->last_nr_regions == nr_regions && nr_regions < ctx->attrs.max_nr_regions /3 ) nr_subregions =3 ;damon_for_each_target (t, ctx)damon_split_regions_of (t, nr_subregions); - last_nr_regions = nr_regions; + ctx->last_nr_regions = nr_regions; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1328/2857 can: raw, isotp: copy socket options outside of lock_sock()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Hartkopp <[email protected]>
commit 43c973a0887d3d7b2ee0a446603c97bf0f38c58e upstream.
The CAN_RAW and CAN_ISOTP specific socket options are copied from and to user space while holding lock_sock(). A copy that faults or stalls, e.g. on a userfaultfd or FUSE backed mapping, holds lock_sock() for its whole duration.
raw_notify() and isotp_notify() take lock_sock() of a socket that is bound to the vanishing device while holding RTNL. As the CAN_RAW options can also be changed on a bound socket, a stalled copy can block RTNL on an unregistration or namespace change of the bound device. Before "can: protect the receive lists with a per-device lock", raw_setsockopt() even held RTNL itself during the copy. CAN_ISOTP only copies its options for unbound sockets, which isotp_notify() skips without taking lock_sock().
Keep the user space copies out of the locked sections: Check the option name and length and copy the option values, including the CAN_RAW_FILTER filters, to kernel memory before lock_sock(). raw_setsockopt_locked() and isotp_setsockopt_locked() get the copied values directly and drop their now redundant length checks and copies. As a side effect, a failing copy can not leave partially overwritten options behind anymore. In raw_getsockopt() duplicate the filters under lock_sock() and copy them to user space after release_sock().
As the option name and length are now checked before lock_sock(), the order of the checks in isotp_setsockopt() and accordingly the order of the returned error values changes. This is in line with POSIX, which does not define an order in which multiple error conditions are detected and reported.
The generic SOL_SOCKET options in sk_setsockopt() are not affected by this patch.
[ backport to 6.1: This tree has no raw_setsockopt_locked() from commit
1e5185c09058 ("can: raw: add locking for raw flags bitfield"). raw_setsockopt() already copies all option values from user space before lock_sock() here, so only the raw_getsockopt() and isotp parts apply. raw_getsockopt() uses copy_to_user() and put_user() instead of the getsockopt_iter interface in this tree. Duplicate the filters under lock_sock() and copy them with copy_to_user() after release_sock(). Also move the put_user() of the needed filter space for -ERANGE behind release_sock(), which upstream writes to the kernel side opt->optlen. ]
--- net/can/isotp.c | 100 +++++++++++++++++++++++++++--------------------- net/can/raw.c | 25 +++++++++--- 2 files changed, 76 insertions(+), 49 deletions(-)
net/can/isotp.c +57 -43
@@ -1648,8 +1648,8 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)return ISOTP_MIN_NAMELEN ; } -static int isotp_setsockopt_locked (struct socket *sock,int level,int optname, -sockptr_t optval,unsigned int optlen) +static int isotp_setsockopt_locked (struct socket *sock,int optname, +const void *val) {struct sock *sk = sock->sk;struct isotp_sock *so =isotp_sk (sk);
@@ -1660,11 +1660,7 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,switch (optname) {case CAN_ISOTP_OPTS : -if (optlen !=sizeof (struct can_isotp_options )) -return -EINVAL ; - -if (copy_from_sockptr (&so->opt, optval, optlen)) -return -EFAULT ; +memcpy (&so->opt, val,sizeof (so->opt));/* no separate rx_ext_address is given => use ext_address */ if (!(so->opt.flags &CAN_ISOTP_RX_EXT_ADDR ))
@@ -1689,55 +1685,37 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,break ;case CAN_ISOTP_RECV_FC : -if (optlen !=sizeof (struct can_isotp_fc_options )) -return -EINVAL ; - -if (copy_from_sockptr (&so->rxfc, optval, optlen)) -return -EFAULT ; +memcpy (&so->rxfc, val,sizeof (so->rxfc));break ;case CAN_ISOTP_TX_STMIN : -if (optlen !=sizeof (u32)) -return -EINVAL ; - -if (copy_from_sockptr (&so->force_tx_stmin, optval, optlen)) -return -EFAULT ; + so->force_tx_stmin = *(const u32 *)val;break ;case CAN_ISOTP_RX_STMIN : -if (optlen !=sizeof (u32)) -return -EINVAL ; - -if (copy_from_sockptr (&so->force_rx_stmin, optval, optlen)) -return -EFAULT ; + so->force_rx_stmin = *(const u32 *)val;break ; -case CAN_ISOTP_LL_OPTS : -if (optlen ==sizeof (struct can_isotp_ll_options )) { -struct can_isotp_ll_options ll; - -if (copy_from_sockptr (&ll, optval, optlen)) -return -EFAULT ; +case CAN_ISOTP_LL_OPTS : { +const struct can_isotp_ll_options *ll = val; -/* check for correct ISO 11898-1 DLC data length */ -if (ll.tx_dl !=padlen (ll.tx_dl)) -return -EINVAL ; +/* check for correct ISO 11898-1 DLC data length */ +if (ll->tx_dl !=padlen (ll->tx_dl)) +return -EINVAL ; -if (ll.mtu !=CAN_MTU && ll.mtu !=CANFD_MTU ) -return -EINVAL ; +if (ll->mtu !=CAN_MTU && ll->mtu !=CANFD_MTU ) +return -EINVAL ; -if (ll.mtu ==CAN_MTU && - (ll.tx_dl >CAN_MAX_DLEN || ll.tx_flags !=0 )) -return -EINVAL ; +if (ll->mtu ==CAN_MTU && + (ll->tx_dl >CAN_MAX_DLEN || ll->tx_flags !=0 )) +return -EINVAL ; -memcpy (&so->ll, &ll,sizeof (ll)); +memcpy (&so->ll, ll,sizeof (*ll)); -/* set ll_dl for tx path to similar place as for rx */ - so->tx.ll_dl = ll.tx_dl; - }else { -return -EINVAL ; - } +/* set ll_dl for tx path to similar place as for rx */ + so->tx.ll_dl = ll->tx_dl;break ; + }default : ret = -ENOPROTOOPT ;
@@ -1751,13 +1729,49 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname, {struct sock *sk = sock->sk; +union { +struct can_isotp_options opt; +struct can_isotp_fc_options rxfc; +struct can_isotp_ll_options ll; +u32 stmin; + } val; +unsigned int size;int ret;if (level !=SOL_CAN_ISOTP )return -EINVAL ; +/* copy the option values from user space before lock_sock() */ +switch (optname) { +case CAN_ISOTP_OPTS : + size =sizeof (val.opt); +break ; + +case CAN_ISOTP_RECV_FC : + size =sizeof (val.rxfc); +break ; + +case CAN_ISOTP_TX_STMIN : +case CAN_ISOTP_RX_STMIN : + size =sizeof (val.stmin); +break ; + +case CAN_ISOTP_LL_OPTS : + size =sizeof (val.ll); +break ; + +default : +return -ENOPROTOOPT ; + } + +if (optlen != size) +return -EINVAL ; + +if (copy_from_sockptr (&val, optval, size)) +return -EFAULT ; +lock_sock (sk); - ret =isotp_setsockopt_locked (sock, level, optname, optval, optlen); + ret =isotp_setsockopt_locked (sock, optname, &val);release_sock (sk);return ret; }
net/can/raw.c +19 -6
@@ -776,31 +776,44 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,return -EINVAL ;switch (optname) { -case CAN_RAW_FILTER : +case CAN_RAW_FILTER : { +struct can_filter *filter =NULL ; +int fsize =0 ; +lock_sock (sk);if (ro->count >0 ) { -int fsize = ro->count *sizeof (struct can_filter ); + fsize = ro->count *sizeof (struct can_filter );/* user space buffer to small for filter list? */ if (len < fsize) {/* return -ERANGE and needed space in optlen */ err = -ERANGE ; -if (put_user (fsize, optlen)) - err = -EFAULT ; }else {if (len > fsize) len = fsize; -if (copy_to_user (optval, ro->filter, len)) - err = -EFAULT ; +/* copy to user space after release_sock() */ + filter =kmemdup (ro->filter, len,GFP_KERNEL ); +if (!filter) + err = -ENOMEM ; } }else { len =0 ; }release_sock (sk); +if (err == -ERANGE ) { +if (put_user (fsize, optlen)) + err = -EFAULT ; + }else if (filter) { +if (copy_to_user (optval, filter, len)) + err = -EFAULT ; +kfree (filter); + } +if (!err) err =put_user (len, optlen);return err; + }case CAN_RAW_ERR_FILTER :if (len >sizeof (can_err_mask_t))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1329/2857 ata: libata-scsi: reject data-in commands with a data-out buffer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Gongyi <[email protected]>
[ Upstream commit a4845f077415ef32fe672c841e2fc58ae9e28273 ]
SG_IO can submit a data-in SCSI command with DMA_TO_DEVICE. The scatterlist can then contain pages pinned without write access. ata_scsi_rbuf_fill() writes simulated replies to that scatterlist; in the reported case, the copy tried to write the shared zero page and faulted in the kernel.
The same mismatch can affect SG_IO commands translated by libata. ZBC IN and GET PHYSICAL ELEMENT STATUS completion handlers can modify the receive buffer even if the drive aborts the command. For ATAPI, the successful INQUIRY completion also rewrites the buffer in atapi_fixup_inquiry().
Reject these mismatched commands before the buffer is written or the command is issued. Report ABORTED COMMAND / DATA IN BUFFER ERROR because the CDB itself can be valid; the supplied transfer direction is wrong.
Backport notes: Use the older five-argument ata_scsi_set_sense() interface and spell DATA IN BUFFER ERROR as ASC/ASCQ 0x4b/0x0a. The older ata_scsi_rbuf_fill() takes struct ata_scsi_args; get the device and command from args, and reject before copying.
--- drivers/ata/libata-scsi.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/ata/libata-scsi.c +25 -0
@@ -1911,6 +1911,18 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,if (xlat_func (qc)) goto done; +/* +* A data-out request may contain pages pinned without write access. +* Reject a translated data-in command before issuing it, since its +* completion handler may write to the buffer even if the device fails. +*/ +if (unlikely (cmd->sc_data_direction ==DMA_TO_DEVICE && +ata_is_data (qc->tf.protocol) && + !(qc->tf.flags &ATA_TFLAG_WRITE ))) { +ata_scsi_set_sense (dev, cmd,ABORTED_COMMAND ,0x4b ,0x0a ); + goto done; + } +return ata_scsi_qc_issue (ap, qc); done:
@@ -1947,6 +1959,12 @@ static void ata_scsi_rbuf_fill(struct ata_scsi_args *args,struct scsi_cmnd *cmd = args->cmd;unsigned long flags; +/* A data-out request may contain pages pinned without write access. */ +if (cmd->sc_data_direction ==DMA_TO_DEVICE ) { +ata_scsi_set_sense (args->dev, cmd,ABORTED_COMMAND ,0x4b ,0x0a ); +return ; + } +spin_lock_irqsave (&ata_scsi_rbuf_lock, flags);memset (ata_scsi_rbuf,0 ,ATA_SCSI_RBUF_SIZE );
@@ -2772,6 +2790,13 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) qc->complete_fn = atapi_qc_complete; +/* atapi_fixup_inquiry() writes to the buffer on successful completion. */ +if (scmd->sc_data_direction ==DMA_TO_DEVICE && + scmd->cmnd[0 ] ==INQUIRY ) { +ata_scsi_set_sense (dev, scmd,ABORTED_COMMAND ,0x4b ,0x0a ); +return 1 ; + } + qc->tf.flags |=ATA_TFLAG_ISADDR |ATA_TFLAG_DEVICE ;if (scmd->sc_data_direction ==DMA_TO_DEVICE ) { qc->tf.flags |=ATA_TFLAG_WRITE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1330/2857 genirq/kexec: Do not take the bus lock of an interrupt chip on the crash path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Velkov <[email protected]>
commit 717862eac6eff0eea8ac30a0c0de0bed84922aab upstream.
machine_kexec_mask_interrupts() calls irq_set_irqchip_state() for every started interrupt. That function takes the bus lock of the chip and desc->lock, and syncs the chip when it drops them. On the crash path interrupts are off and the other CPUs are stopped, so a chip whose bus transfer is completed by an interrupt never returns from the sync.
On RK3399 boards with an RK808 PMIC the RTC alarm interrupt belongs to the regmap-irq chip of the RK808, which sits on I2C. rk808_irq_chip sets init_ack_masked, so regmap_irq_sync_unlock() writes the ack register on every unlock, and the I2C controller needs its own interrupt to finish the transfer. A panic with a crash kernel loaded prints
SMP: stopping secondary CPUs
and then nothing until the watchdog resets the board.
machine_kexec_mask_interrupts() takes neither lock for the other operations on the descriptor. Move the search for the chip that implements irq_set_irqchip_state() into __irq_set_irqchip_state(), which takes no locks, and call it from machine_kexec_mask_interrupts().
--- arch/arm64/kernel/machine_kexec.c | 2 +- include/linux/interrupt.h | 1 + kernel/irq/manage.c | 49 ++++++++++++++++--------------- 3 files changed, 27 insertions(+), 25 deletions(-)
arch/arm64/kernel/machine_kexec.c +1 -1
@@ -234,7 +234,7 @@ static void machine_kexec_mask_interrupts(void)* First try to remove the active state. If this * fails, try to EOI the interrupt. */ - ret =irq_set_irqchip_state (i,IRQCHIP_STATE_ACTIVE , false); + ret =__irq_set_irqchip_state (desc,IRQCHIP_STATE_ACTIVE , false);if (ret &&irqd_irq_inprogress (&desc->irq_data) && chip->irq_eoi)
include/linux/interrupt.h +1 -0
@@ -507,6 +507,7 @@ extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which, bool *state);extern int irq_set_irqchip_state (unsigned int irq,enum irqchip_irq_state which,bool state); +extern int __irq_set_irqchip_state (struct irq_desc *desc,enum irqchip_irq_state which,bool val);#ifdef CONFIG_IRQ_FORCED_THREADING # ifdef CONFIG_PREEMPT_RT
kernel/irq/manage.c +25 -24
67 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1331/2857 efi/libstub: arm64: Dont use the platform register x18
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
commit 4c86b5f3fa78347fa9cbc9e8ec06615b2f80e397 upstream
The UEFI specification designates x18, the platform register, as "do not use" on AArch64, so that UEFI code is compatible both with an OS that assigns a fixed role to x18, and with one that uses it as a temporary register.
The arm64 EFI stub and the EFI zboot decompressor only avoid x18 if the kernel is built with shadow call stacks, as that is the only case where -ffixed-x18 is added to KBUILD_CFLAGS, which the stub inherits. Otherwise, the compiler is free to use x18 as a temporary register, and it does so.
So pass -ffixed-x18 unconditionally when building the stub for arm64, so that the image can be run by loaders that rely on x18 being left alone, such as a kernel that uses it for its shadow call stack.
--- drivers/firmware/efi/libstub/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/Makefile +1 -1
@@ -19,7 +19,7 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -std=gnu11 \ # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly # disable the stackleak plugin cflags-$(CONFIG_ARM64) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ - -fpie $(DISABLE_STACKLEAK_PLUGIN) \ + -fpie $(DISABLE_STACKLEAK_PLUGIN) -ffixed-x18 \ $(call cc-option,-mbranch-protection=none) cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ -fno-builtin -fpic \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1332/2857 f2fs: force out-place update for all writes on compressed file
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiucheng Xu <[email protected]>
commit a64a3fec11e77a3a0dc0009bdc58b925e45a1bb4 upstream.
For compressed file, compressed write may fail and fall back to raw write.
-Thread A - Thread B
- f2fs_write_multi_pages - f2fs_down_write(&sbi->cp_rwsem);
- f2fs_write_compressed_pages - ...
- f2fs_trylock_op - ...
- f2fs_down_read_trylock(&sbi->cp_rwsem); - ...
- f2fs_write_raw_pages - ...Thread B acquires the lock first, which causes Thread A to fail lock acquisition and fall back to raw-data write.IPU_FORCE is enabled on small-capacity storage devices (< 16GB), so f2fs_write_raw_pages() overwrites the original compressed data in-place.
The in-memory node has been updated with raw-data addresses, while the node metadata stored on eMMC still remains in compressed state. If a power-cut occurs before the node is flushed to disk, on-disk inconsistency arises: disk data is raw, yet metadata treats it as a compressed cluster, leading to decompression failure.
To eliminate this risk completely, force out-place update for all write operations on compressed file.
--- fs/f2fs/data.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/f2fs/data.c +7 -0
@@ -2662,6 +2662,13 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return true;if (f2fs_is_atomic_file (inode))return true; +/* +* rewrite low ratio compress data w/ OPU mode to avoid fragmentation. +* If IO comes from compressed write path and fallback to raw write, +* force out-place to prevent metadata-data inconsistency. +*/ +if (f2fs_compressed_file (inode)) +return true;/* swap file is migrating in aligned write mode */ if (is_inode_flag_set (inode,FI_ALIGNED_WRITE ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1333/2857 f2fs: allow pinning empty compressed files
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Chang <[email protected]>
commit 2eebc31ae5f53e1066bb6238c8087c23b688ad17 upstream.
Commit a64a3fec11e7 ("f2fs: force out-place update for all writes on compressed file") updated f2fs_should_update_outplace() to always return true for compressed files. However, this function is also called during f2fs_ioc_set_pin_file() validation, so pinning an empty file with compression enabled now fails with -EINVAL before the compression flag can be stripped.
Fix this by guarding the f2fs_compressed_file(inode) check with fio in f2fs_should_update_outplace(). This preserves forced OPU for actual compressed writes (fio != NULL), while allowing f2fs_ioc_set_pin_file() (fio == NULL) to proceed to f2fs_disable_compressed_file(inode).
--- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c +1 -1
@@ -2667,7 +2667,7 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)* If IO comes from compressed write path and fallback to raw write, * force out-place to prevent metadata-data inconsistency. */ -if (f2fs_compressed_file (inode)) +if (fio &&f2fs_compressed_file (inode))return true;/* swap file is migrating in aligned write mode */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1334/2857 iommu/amd: Force device table to maximum size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump copies the previous kernel's device table only when the size encoded in the IOMMU device-table register matches pci_seg->dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so copy_device_table() rejects the table and reinitializes translation. Kernels that both have this patch agree on 2MB and the copy succeeds. Update the production kernel and the crash kernel together.
This backport adds X86_FEATURE_ZEN6. Bit 3*32+6 is still X86_FEATURE_P3 here, so the new flag uses free bit 21*32+7. Family 0x1a models 0x50-0x5f, 0x80-0xaf, 0xc0-0xcf, and 0xd8-0xef are Zen6 and are excluded from the workaround. This kernel has no X86_FEATURE_ZEN5. Other family 0x1a models stay unmarked and still take the 2MB device table.
--- arch/x86/include/asm/cpufeatures.h | 5 +++++ arch/x86/kernel/cpu/amd.c | 18 ++++++++++++++++++ drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +5 -0
@@ -452,6 +452,11 @@#define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3)/* "" BHI_DIS_S HW control enabled */ #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* "" Clear branch history at vmexit using SW loop */ #define X86_FEATURE_INDIRECT_THUNK_ITS (21*32 + 5)/* "" Use thunk for indirect branches in lower half of cacheline */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* "" CPU based on Zen6 microarchitecture */ #define X86_FEATURE_TSA_SQ_NO (21*32+11)/* "" AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (21*32+12)/* "" AMD CPU not vulnerable to TSA-L1 */
arch/x86/kernel/cpu/amd.c +18 -0
@@ -713,6 +713,24 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) }break ; } +case 0x1a : { +switch (c->x86_model) { + case 0x50 ... 0x5f: + case 0x80 ... 0xaf: + case 0xc0 ... 0xcf: + case 0xd8 ... 0xef: +setup_force_cpu_cap (X86_FEATURE_ZEN6 ); +break ; +default : +/* +* Zen5 models in family 0x1a have no feature bit +* in this kernel. Leave them unmarked so the +* device-table workaround still applies. +*/ +break ; + } +break ; + }default :break ; }
drivers/iommu/amd/init.c +22 -1
@@ -1587,6 +1587,21 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,return 0 ; } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* Allocate PCI segment data structure */ static struct amd_iommu_pci_seg *__init alloc_pci_segment (u16 id,struct acpi_table_header *ivrs_base)
@@ -1609,7 +1624,13 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf;DUMP_printk ("PCI segment : 0x%0x, last bdf : 0x%04x\n" , id, last_bdf); - pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , last_bdf); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + pci_seg->dev_table_size =SZ_2M ; + }else { + pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , + last_bdf); + } pci_seg->alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE , last_bdf); pci_seg->rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE , last_bdf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1335/2857 drm/nouveau/svm: drain fault handler before freeing svmm
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenhao Wan <[email protected]>
[ Upstream commit b46ddaf0823405f81e681eb26ec98508f3eb9a07 ]
The SVM fault handler nouveau_svm_fault() looks up each fault's nouveau_svmm under svm->mutex, caches it in the fault array, then drops svm->mutex and dereferences the svmm across blocking faults (mmu_interval_notifier_insert(), hmm_range_fault()).
nouveau_svmm is not refcounted. On DRM file close nouveau_svmm_fini() -> mmu_notifier_put() frees it asynchronously via call_srcu() without waiting for the handler, and mmget_not_zero() pins the mm, not the svmm. flush_work() on the fault buffer otherwise runs only at device removal and suspend, never on close, so a fault handled concurrently with a close can dereference a freed svmm.
The instance is already unlinked by nouveau_svmm_part() earlier in the same close, so no new fault can resolve to it. Drain the handler in nouveau_svmm_fini() before the free, guarding the flush with a NULL check on drm->svm: on device teardown nouveau_svm_fini() runs first and frees drm->svm (NULL) after blocking the notify and flushing the buffer, so the handler is already drained; on per-client close drm->svm is alive and the flush runs.
--- drivers/gpu/drm/nouveau/nouveau_svm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/nouveau/nouveau_svm.c +13 -0
@@ -306,6 +306,19 @@ nouveau_svmm_fini(struct nouveau_svmm **psvmm) {struct nouveau_svmm *svmm = *psvmm;if (svmm) { +struct nouveau_svm *svm = svmm->vmm->cli->drm->svm; + +/* The fault handler caches svmm pointers under svm->mutex and +* dereferences them after dropping it, across blocking faults. +* The instance is already unlinked (nouveau_svmm_part), so drain +* the handler before the free to release any in-flight reference. +* +* On device teardown nouveau_svm_fini() ran first and freed +* drm->svm (NULL) after draining the buffer; nothing to flush. +*/ +if (svm) +flush_work (&svm->buffer[0 ].notify.work); +mutex_lock (&svmm->mutex); svmm->vmm =NULL ;mutex_unlock (&svmm->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1336/2857 udf: Avoid invalid LVID used on mount
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
[ Upstream commit c8f1140cb82dc843e72697dc6f8c7ee1acce5d28 ]
udf_load_logicalvolint() loads logical volume integrity descriptors. Since there can be multiple blocks with LVIDs, we verify the contents of only the last (prevailing) LVID found. However if we fail to load the last LVID (either due to IO error or because it's checksum fails to match), we never perform the verification of validity of the LVID we are going to use. If such LVID contains invalid data, we can hit out-of-bounds access or similar issues. Fix the problem by verifying each LVID we are potentially going to accept.
Stable-dep-of: a61fb39759d7 ("udf: Make sure there's enough space for LVID implementation use field")
--- fs/udf/super.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-)
fs/udf/super.c +25 -17
@@ -1574,6 +1574,20 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,return ret; } +static bool udf_lvid_valid (struct super_block *sb, +struct logicalVolIntegrityDesc *lvid) +{ +u32 parts, impuselen; + + parts =le32_to_cpu (lvid->numOfPartitions); + impuselen =le32_to_cpu (lvid->lengthOfImpUse); +if (parts >= sb->s_blocksize || impuselen >= sb->s_blocksize || +sizeof (struct logicalVolIntegrityDesc ) + impuselen + +2 * parts *sizeof (u32) > sb->s_blocksize) +return false; +return true; +} +/* * Find the prevailing Logical Volume Integrity Descriptor. */
@@ -1584,7 +1598,6 @@ static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_struct udf_sb_info *sbi =UDF_SB (sb);struct logicalVolIntegrityDesc *lvid;int indirections =0 ; -u32 parts, impuselen;while (++indirections <=UDF_MAX_LVID_NESTING ) { final_bh =NULL ;
@@ -1606,32 +1619,27 @@ static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_if (!final_bh)return ; -brelse (sbi->s_lvid_bh); - sbi->s_lvid_bh = final_bh; - lvid = (struct logicalVolIntegrityDesc *)final_bh->b_data; +if (udf_lvid_valid (sb, lvid)) { +brelse (sbi->s_lvid_bh); + sbi->s_lvid_bh = final_bh; + }else { +udf_warn (sb,"Corrupted LVID (parts=%u, impuselen=%u), " +"ignoring.\n" , +le32_to_cpu (lvid->numOfPartitions), +le32_to_cpu (lvid->lengthOfImpUse)); + } +if (lvid->nextIntegrityExt.extLength ==0 ) - goto check; +return ; loc =leea_to_cpu (lvid->nextIntegrityExt); }udf_warn (sb,"Too many LVID indirections (max %u), ignoring.\n" ,UDF_MAX_LVID_NESTING ); -out_err:brelse (sbi->s_lvid_bh); sbi->s_lvid_bh =NULL ; -return ; -check: - parts =le32_to_cpu (lvid->numOfPartitions); - impuselen =le32_to_cpu (lvid->lengthOfImpUse); -if (parts >= sb->s_blocksize || impuselen >= sb->s_blocksize || -sizeof (struct logicalVolIntegrityDesc ) + impuselen + -2 * parts *sizeof (u32) > sb->s_blocksize) { -udf_warn (sb,"Corrupted LVID (parts=%u, impuselen=%u), " -"ignoring.\n" , parts, impuselen); - goto out_err; - } }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1337/2857 udf: Make sure theres enough space for LVID implementation use field
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
[ Upstream commit a61fb39759d719a4f4966742b4d28387e33d81c4 ]
udf_lvid_valid() verifies that the LVID has enough space for all the tables and the reported length of ImplementationUse field. However it doesn't make sure the reported length is large enough to contain logicalVolIntegrityDescImpUse structure which OSTA specification requires. This can thus lead to accesses beyond the end of LVID buffer for suitably corrupted UDF filesystem. Add the length check.
--- fs/udf/super.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/udf/super.c +4 -1
@@ -1581,7 +1581,10 @@ static bool udf_lvid_valid(struct super_block *sb, parts =le32_to_cpu (lvid->numOfPartitions); impuselen =le32_to_cpu (lvid->lengthOfImpUse); -if (parts >= sb->s_blocksize || impuselen >= sb->s_blocksize || +if (sizeof (struct logicalVolIntegrityDescImpUse ) > impuselen || + impuselen >= sb->s_blocksize) +return false; +if (parts >= sb->s_blocksize ||sizeof (struct logicalVolIntegrityDesc ) + impuselen +2 * parts *sizeof (u32) > sb->s_blocksize)return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1338/2857 powerpc/bpf: fix buffer overflow in JIT for large BPF programs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abhishek Dubey <[email protected]>
[ Upstream commit 78ce55b7913a78e1687306668e078b86bc6508ee ]
During size calculation in pass-0, exit_addr is 0 since addrs[fp->len] is not yet populated. bpf_jit_emit_exit_insn() treats a zero exit_addr as in-range and skips bpf_jit_build_epilogue(), so the alternate inline epilogue instructions are not counted in alloclen.
In later passes, if the real exit_addr falls outside the 32MB branch range, the full inline epilogue is emitted into the already-allocated buffer, writing past its end and corrupting adjacent memory.
Fix by ensuring exit_addr is non-zero before treating it as in-range, so pass-0 always falls through to bpf_jit_build_epilogue() and conservatively accounts for all epilogue instructions in alloclen. Also range check alt_exit_addr directly in the else-if condition.
Since exit_addr handling now falls through to the epilogue, two related issues in bpf_int_jit_compile() must also be addressed:
1. Reset cgctx.alt_exit_addr before the second size-calculation pass. Without this, a stale alt_exit_addr from the first pass causes the second pass to emit a single jump instead of the full epilogue, undercounting alloclen and reintroducing the overflow.
2. Recompute addrs[fp->len] at the end of each code-generation pass. The larger pass-0 body can shrink in later passes as out-of-range exits settle into in-range jumps; a stale addrs[fp->len] would leave exit branches targeting past the real (shrunken) epilogue.
Because shrinkage in a later pass can move the epilogue offset, the fixed two-pass loop is no longer sufficient: an exit that was out of range in an earlier pass may fall in range once the epilogue offset shrinks, shrinking the body further and overwriting the start of the epilogue. Convert the code-generation loop to iterate until the program size converges, bounded by CODEGEN_MAX_PASSES, and fail the JIT if it does not converge.
--- arch/powerpc/net/bpf_jit.h | 7 +++++++ arch/powerpc/net/bpf_jit_comp.c | 34 +++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-)
arch/powerpc/net/bpf_jit.h +7 -0
@@ -13,6 +13,13 @@#include <asm/types.h> #include <asm/ppc-opcode.h> +/* +* We need at least 2 passes for proper code generation, and may need +* additional passes if code size changes between passes. +*/ +#define CODEGEN_MIN_PASSES 2 +#define CODEGEN_MAX_PASSES 3 +#ifdef CONFIG_PPC64_ELF_ABI_V1 #define FUNCTION_DESCR_SIZE 24#else
arch/powerpc/net/bpf_jit_comp.c +26 -8
@@ -93,11 +93,10 @@ static int bpf_jit_fixup_addresses(struct bpf_prog *fp, u32 *image,int bpf_jit_emit_exit_insn (u32 *image,struct codegen_context *ctx,int tmp_reg,long exit_addr) { -if (!exit_addr ||is_offset_in_branch_range (exit_addr - (ctx->idx *4 ))) { +if (exit_addr &&is_offset_in_branch_range (exit_addr - (long )(ctx->idx *4 ))) {PPC_JMP (exit_addr); - }else if (ctx->alt_exit_addr) { -if (WARN_ON (!is_offset_in_branch_range ((long )ctx->alt_exit_addr - (ctx->idx *4 )))) -return -1 ; + }else if (ctx->alt_exit_addr &&is_offset_in_branch_range ( + (long )(ctx->alt_exit_addr) - (long )(ctx->idx *4 ))) {PPC_JMP (ctx->alt_exit_addr); }else { ctx->alt_exit_addr = ctx->idx *4 ;
@@ -200,6 +199,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)*/ if (cgctx.seen &SEEN_TAILCALL || !is_offset_in_branch_range ((long )cgctx.idx *4 )) { cgctx.idx =0 ; + cgctx.alt_exit_addr =0 ;if (bpf_jit_build_body (fp,0 , &cgctx, addrs,0 )) { fp = org_fp; goto out_addrs;
@@ -250,10 +250,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) goto skip_codegen_passes; } -/* Code generation passes 1-2 */ -for (pass =1 ; pass <3 ; pass++) { +/* Code generation passes 1-2+, loop until program size converges. */ +for (pass =1 ; pass <=CODEGEN_MAX_PASSES ; pass++) { +u32 prev_proglen = proglen; +/* Now build the prologue, body code & epilogue for real. */ cgctx.idx =0 ; + cgctx.exentry_idx =0 ; cgctx.alt_exit_addr =0 ;bpf_jit_build_prologue (code_base, &cgctx);if (bpf_jit_build_body (fp, code_base, &cgctx, addrs, pass)) {
@@ -261,11 +264,26 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) fp = org_fp; goto out_addrs; } + addrs[fp->len] = cgctx.idx *4 ;bpf_jit_build_epilogue (code_base, &cgctx); + proglen = cgctx.idx *4 ; +if (bpf_jit_enable >1 )pr_info ("Pass %d: shrink = %d, seen = 0x%x\n" , pass, - proglen - (cgctx.idx *4 ), cgctx.seen); + prev_proglen - proglen, cgctx.seen); + +/* Check if program size has converged, but ensure minimum passes */ +if (pass >=CODEGEN_MIN_PASSES && proglen == prev_proglen) +break ; + +if (pass ==CODEGEN_MAX_PASSES && proglen != prev_proglen) { +pr_err ("BPF JIT: Program did not converge after %d passes\n" , +CODEGEN_MAX_PASSES ); +bpf_jit_binary_free (bpf_hdr); + fp = org_fp; + goto out_addrs; + } } skip_codegen_passes:
@@ -322,7 +340,7 @@ int bpf_add_extable_entry(struct bpf_prog *fp, u32 *image, int pass, struct codeu32 *fixup;/* Populate extable entries only in the last pass */ -if (pass !=2 ) +if (pass <CODEGEN_MIN_PASSES )return 0 ; if (!fp->aux->extable ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1339/2857 crypto: algif_skcipher - rewind rounded output bytes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit 2f90facc7b94934653eb7ebfadcc25d503b89196 ]
af_alg_get_rsgl() advances the receive iterator by the unrounded RX scatterlist length. For a continuing skcipher request, _skcipher_recvmsg() then rounds its local length down to a whole chunksize without restoring the iterator.
A later chunk starts after bytes which the provider never wrote, while the syscall returns only the processed length. When copy_splice_read() supplies non-zeroed pages and publishes that return as a dense prefix, the gap exposes stale bytes from a previous page lifetime.
With unprivileged xts(aes), a 31-byte MSG_MORE request followed by one final byte advances a 47-byte destination while returning 32 bytes. A hardened v7.2-rc5 image retained all 15 seeded stale bytes in 4,829 of 4,829 records. With init_on_alloc enabled, all 72,345 gap bytes observed were zero.
Rewind the iterator by the tail excluded during rounding, before rejecting a zero processed length. The crypto request uses only the rounded length; af_alg_free_resources() releases the entire RX list before another receive iteration.
The fixed target-like kernel returned byte-identical dense 48-byte output in 4,771 of 4,771 rounds. The unmodified kernel returned the vulnerable 32-byte short record in 2,409 of 2,409 rounds.
--- crypto/algif_skcipher.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
crypto/algif_skcipher.c +6 -3
@@ -83,12 +83,15 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,* full block size buffers. */ if (ctx->more || len < ctx->used) { -if (len < bs) { +size_t excess = len % bs; + + len -= excess; +iov_iter_revert (&msg->msg_iter, excess); + +if (!len) { err = -EINVAL ; goto free; } - - len -= len % bs; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1340/2857 batman-adv: Limit number of aggregated packets directly
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 434becf57bdc89f939db635ed3337b9d1da5967e upstream.
The currently selected size in BATADV_MAX_AGGREGATION_BYTES (512) is chosen such that the number of possible aggregated packets is lower than 32. This number must be limited so that the type of batadv_forw_packet->direct_link_flags has enough bits to represent each packet (with the size of at least 24 bytes).
This requirement is better implemented in code instead of having it inside a comment.
--- net/batman-adv/bat_iv_ogm.c | 4 ++++ net/batman-adv/main.h | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-)
net/batman-adv/bat_iv_ogm.c +4 -0
@@ -450,6 +450,7 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,struct batadv_ogm_packet *batadv_ogm_packet;int aggregated_bytes = forw_packet->packet_len + packet_len;struct batadv_hard_iface *primary_if =NULL ; +u8 packet_num = forw_packet->num_packets +1 ;bool res = false;unsigned long aggregation_end_time;
@@ -475,6 +476,9 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,if (aggregated_bytes >BATADV_MAX_AGGREGATION_BYTES )return false; +if (packet_num >=BITS_PER_TYPE (forw_packet->direct_link_flags)) +return false; +/* packet is not leaving on the same interface. */ if (forw_packet->if_outgoing != if_outgoing)return false;
net/batman-adv/main.h +0 -3
@@ -102,9 +102,6 @@*/ #define BATADV_TQ_SIMILARITY_THRESHOLD 50 -/* should not be bigger than 512 bytes or change the size of -* forw_packet->direct_link_flags -*/ #define BATADV_MAX_AGGREGATION_BYTES 512#define BATADV_MAX_AGGREGATION_MS 100
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1341/2857 batman-adv: Close OGM aggregation before transmission
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit f91f64a91682c07e6c5f059804e709656364e8a6 upstream.
The OGM send worker leaves its forwarding packet on forw_bat_list until after batadv_iv_ogm_emit() returns. Aggregation holds forw_bat_list_lock, but emission reads and clones the packet without that lock.
CPU 0 can therefore start emitting a queued packet while CPU 1 takes the list lock, finds the same packet and appends another OGM. The sender can observe the new packet length before the corresponding direct-link flag is set, or clone the skb while its length and payload are being updated. This can transmit an OGM with incorrect flags or inconsistent data.
KCSAN reported:
BUG: KCSAN: data-race in batadv_iv_ogm_queue_add / batadv_iv_send_outstanding_bat_ogm_packet write to 0xffff888100fedcf8 of 2 bytes by interrupt on cpu 1: read to 0xffff888100fedcf8 of 2 bytes by task 70 on cpu 2: value changed: 0x00c0 -> 0x00d8
Mark the aggregate as full under forw_bat_list_lock before emission. This waits for any ongoing append and prevents further aggregation. Emission uses packet_len to walk the OGMs, so all queued packets are still sent. Keep the packet on the list so interface purging can find the worker, wait for it to finish and free the packet.
--- net/batman-adv/bat_iv_ogm.c | 5 +++++ net/batman-adv/types.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-)
net/batman-adv/bat_iv_ogm.c +5 -0
@@ -1794,6 +1794,11 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work) goto out; } +/* Mark aggregate as full before forcing emit. */ +spin_lock_bh (&bat_priv->forw_bat_list_lock); + forw_packet->num_packets =BITS_PER_TYPE (forw_packet->direct_link_flags); +spin_unlock_bh (&bat_priv->forw_bat_list_lock); +batadv_iv_ogm_emit (forw_packet);/* we have to have at least one packet in the queue to determine the
net/batman-adv/types.h +7 -1
@@ -2138,7 +2138,13 @@ struct batadv_forw_packet {/** @direct_link_flags: direct link flags for aggregated OGM packets */ u32 direct_link_flags; -/** @num_packets: counter for aggregated OGMv1 packets */ +/** +* @num_packets: counter for aggregated OGMv1 packets. Set to +* BITS_PER_TYPE(forw_packet->direct_link_flags) (independent of the +* real number of aggregated packets) by the send worker to prevent +* further aggregation while the packet is emitted. It must therefore +* not be used to iterate over the aggregated packets +*/ u8 num_packets;/** @delayed_work: work queue callback item for packet sending */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1342/2857 batman-adv: tpmeter: fix u32 truncation of reported bytes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 1025b76d13288a311e8259a0eefde0854fa63c41 upstream.
When more than 4 GB are transferred by the throughput meter, batadv_tp_batctl_notify() will cut of the upper 32 bit of the u64 counter and thus under-report the actual transferred bytes.
The data type of the temporary storage variable must therefore still continue to use u64.
--- net/batman-adv/tp_meter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/tp_meter.c +1 -1
@@ -226,9 +226,9 @@ static void batadv_tp_batctl_notify(enum batadv_tp_meter_reason reason, unsigned long start_time, u64 total_sent, u32 cookie) { + u64 total_bytes;u32 test_time;u8 result; -u32 total_bytes;if (!batadv_tp_is_error (reason)) { result =BATADV_TP_REASON_COMPLETE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1343/2857 batman-adv: stop originator purge worker before freeing TT
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit f89eda5a9ccf82cba06b085b42ebc4886b8dfe9e upstream.
batadv_mesh_free() releases the translation tables via batadv_tt_free() before batadv_originator_free() stops orig_work. The purge worker can therefore still run while the TT is torn down. When an originator times out, batadv_purge_orig_ref() calls batadv_tt_global_del_orig(), which loads tt.global_hash and walks all buckets while taking their locks:
CPU0 CPU1
batadv_tt_free() batadv_purge_orig()
batadv_tt_global_del_orig()
hash = ...tt.global_hash;
batadv_tt_global_table_free()
batadv_hash_destroy(hash);
spin_lock_bh(&hash->list_locks[i]);Disable orig_work at the beginning of batadv_mesh_free(), directly after the mesh was marked as deactivating. The second disable_delayed_work_sync() in batadv_originator_free() is harmless because it is free'd anyway.
--- net/batman-adv/main.c | 5 +++++ 1 file changed, 5 insertions(+)
net/batman-adv/main.c +5 -0
@@ -262,6 +262,11 @@ void batadv_mesh_free(struct net_device *soft_iface)atomic_set (&bat_priv->mesh_state,BATADV_MESH_DEACTIVATING ); +/* the originator purge worker accesses (among others) the TT tables +* and must therefore be stopped before any of them are freed +*/ +cancel_delayed_work_sync (&bat_priv->orig_work); +batadv_purge_outstanding_packets (bat_priv,NULL );batadv_tp_stop_all (bat_priv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1344/2857 batman-adv: tt: only transmit local ROAM flag together with DEL
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 10f24f058417024a2c19cb8d88a6a0678a58a21b upstream.
BATADV_TT_CLIENT_ROAM is part of BATADV_TT_REMOTE_MASK but on the wire it only has a defined meaning together with BATADV_TT_CLIENT_DEL: the originator no longer serves the client because it roamed to another node. Such a DEL is only relevant for events (non-full table requests).
An ADD carrying ROAM is processed (by accident) by the receiver like aROAMING_ADV: a newly created global entry is marked as roaming and is excluded from the global CRC. But the sender includes it in its local CRC.
But such a behavior doesn't make sense for non-ROAM_ADV because a new TTVN is meant as announced commit of the local TT table of a node and should therefore not be used to create a temporary (roam) global entry in a node.
At the moment, such an ADD with the BATADV_TT_CLIENT_ROAM flag set can happen due to two mechanisms:
batadv_tt_local_valid() copies all flags of the local entry into a full table response. It is not synchronized with batadv_tt_local_mark_removed(). An entry which was marked as ROAM|PENDING by a ROAMING_ADV is still part of the current TTVN and is sent with the ROAM flag set. The receivers then create a roaming global entry for it and detect a CRC mismatch, which causes them to request the full table again.
The same can happen for an ADD change which is queued for an entry which (still) has the ROAM flag set. For example when only the dynamic WIFI or ISOLA flags were updated.
It is not triggered by batadv_send_other_tt_response() because batadv_tt_global_valid() is already taking care of filtering out BATADV_TT_CLIENT_ROAM entries.
For the two problematic announcement mechanism, only send the ROAM flag of local entries together with a DEL.
This only fixes the ROAM marking of the global entry and the resulting CRC mismatch. When the requester of the full table is the node which sent the ROAMING_ADV, the still announced entry will (independent of the ROAM flag) cause batadv_tt_global_purge_local() to remove the requester's own (new) local entry for the client. This is not addressed here.
--- net/batman-adv/translation-table.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
net/batman-adv/translation-table.c +14 -2
@@ -470,7 +470,6 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,if (!tt_change_node)return ; - tt_change_node->change.flags = flags;memset (tt_change_node->change.reserved,0 ,sizeof (tt_change_node->change.reserved));ether_addr_copy (tt_change_node->change.addr, common->addr);
@@ -478,6 +477,15 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv, del_op_requested = flags &BATADV_TT_CLIENT_DEL ; +/* the ROAM flag is only meaningful for the receiver in combination +* with a DEL. An ADD with ROAM would be interpreted as a roaming +* advertisement +*/ +if (!del_op_requested) + flags &= ~BATADV_TT_CLIENT_ROAM ; + + tt_change_node->change.flags = flags; +/* check for ADD+DEL or DEL+ADD events */ spin_lock_bh (&bat_priv->tt.changes_list_lock); list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
@@ -2757,8 +2765,12 @@ static bool batadv_tt_local_valid(const void *entry_ptr,if (tt_common_entry->flags &BATADV_TT_CLIENT_NEW )return false; +/* the entry is (still) announced. A ROAM flag of an entry which is +* pending to be removed must not be transmitted. Otherwise, the +* receiver would handle it like a roaming advertisement +*/ if (flags) - *flags = tt_common_entry->flags; + *flags = tt_common_entry->flags & ~BATADV_TT_CLIENT_ROAM ;return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1345/2857 batman-adv: tt: clear ROAM flag when re-adding a pending local client
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit cc2186d7854785b30d423f5d43757b086b300e55 upstream.
When a ROAMING_ADV is received for an announced local client, batadv_tt_local_mark_removed() sets BATADV_TT_CLIENT_ROAM, queues a DEL|ROAM change and marks the entry as BATADV_TT_CLIENT_PENDING. If the client sends a frame again before the next TTVN commit, batadv_tt_local_add_existing() only clears the PENDING flag and returns early. The ADD cancels the queued DEL, but the entry keeps the ROAM flag:
* batadv_is_my_client() reports the client as not served by this node
* batadv_tt_local_client_is_roaming() reroutes unicast frames for it to the node which sent the ROAMING_ADV
The ROAM flag is only removed with the next frame of the client.
Since BATADV_TT_CLIENT_ROAM is set together with BATADV_TT_CLIENT_PENDING, it has to be cleared also at the same time with BATADV_TT_CLIENT_PENDING when the client roamed back.
--- net/batman-adv/translation-table.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/batman-adv/translation-table.c +6 -3
@@ -658,6 +658,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,int hash_added, table_size, packet_size_max;bool ret = false;bool roamed_back = false; +bool added = false;u8 remote_flags;u32 match_mark;
@@ -684,7 +685,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,* flag can be reset like it was never enqueued */ tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING ; - goto add_event; + added = true; }if (tt_local->common.flags &BATADV_TT_CLIENT_ROAM ) {
@@ -765,10 +766,12 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr, goto out; } -add_event: -batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); + added = true; check_roaming: +if (added) +batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); +/* Check whether it is a roaming, but don't do anything if the roaming * process has already been handled */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1346/2857 batman-adv: tt: send ROAM_ADV on each roamed back client
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit aff4d5d10f2dcb4a9b604e27414dafa1d51b6406 upstream.
When a ROAMING_ADV is received for an announced local client, batadv_roam_tvlv_unicast_handler_v1() creates a global entry with the BATADV_TT_CLIENT_ROAM flag set.
If the client sends a frame again before the next TTVN commit, batadv_tt_local_add_roam() is expected to announce this return via a ROAM_ADV frame. But this doesn't happen because the global entry (created by the first ROAMING_ADV) carries BATADV_TT_CLIENT_ROAM until the new originator announces the client.
Let batadv_tt_local_add_roam() always handle a roamed back client - independent of the ROAM flag of the global entry:
* trigger sending of the ROAM_ADV frame(s)
* remove the (with the roaming) associated global entry
--- net/batman-adv/translation-table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/translation-table.c +2 -1
@@ -775,7 +775,8 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,/* Check whether it is a roaming, but don't do anything if the roaming * process has already been handled */ -if (tt_global && !(tt_global->common.flags &BATADV_TT_CLIENT_ROAM )) { +if (tt_global && + (roamed_back || !(tt_global->common.flags &BATADV_TT_CLIENT_ROAM ))) {/* These node are probably going to update their tt table */ head = &tt_global->orig_list;rcu_read_lock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1347/2857 batman-adv: tt: ignore ROAM flag of received ADD changes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit c5d68abe6e7f1dbd132a602cb696fe1fff0389eb upstream.
A received TT change (OGM diff or full table response) with the ROAM flag but without DEL is handled by batadv_tt_global_add() like a ROAMING_ADV:
* a newly created global entry gets BATADV_TT_CLIENT_ROAM and is therefore excluded from the global CRC. The sender has it in its local CRC and the receiver has to request the full table again
* batadv_tt_global_purge_local() removes the local entry of the receiver. The receiver's own client is considered as roamed to the sender and frames for it are rerouted
The ROAM flag only has a meaning together with DEL. Drop it on reception to keep it from populating the global table with a temporary ROAMING entry which is not part of the CRC - and therefore causing a CRC mismatch.
--- net/batman-adv/translation-table.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
net/batman-adv/translation-table.c +12 -3
@@ -3339,20 +3339,29 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv, {int i;int roams; +u8 flags;for (i =0 ; i < tt_num_changes; i++) { -if ((tt_change + i)->flags &BATADV_TT_CLIENT_DEL ) { - roams = (tt_change + i)->flags &BATADV_TT_CLIENT_ROAM ; + flags = (tt_change + i)->flags; + +if (flags &BATADV_TT_CLIENT_DEL ) { + roams = flags &BATADV_TT_CLIENT_ROAM ;batadv_tt_global_del (bat_priv, orig_node, (tt_change + i)->addr,ntohs ((tt_change + i)->vid),"tt removed by changes" , roams); }else { +/* an announced client cannot have roamed away from +* orig_node. Only a ROAMING_ADV is allowed to add a +* global entry with the ROAM flag +*/ + flags &= ~BATADV_TT_CLIENT_ROAM ; +if (!batadv_tt_global_add (bat_priv, orig_node, (tt_change + i)->addr,ntohs ((tt_change + i)->vid), - (tt_change + i)->flags, ttvn)) + flags, ttvn))/* In case of problem while storing a * global_entry, we stop the updating * procedure without committing the
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1348/2857 batman-adv: tt: only update flags for TT events
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit ad1fd828aa3944efc393b84b0d7c02483f1b5638 upstream.
In the first implementation of the translation table events, it was only possible to announce:
* ADD: new locally detected client
* DEL: disappeared local client
If an ADD event was queued and then a DEL event was queued in the same timeslot, it is valid to destroy both events because nothing actually changed for remode nodes
But with commit 3c4f7ab60cc2 ("batman-adv: improve the TT component to support runtime flag changes") and subsequent changes, it could also happen that there are extra ADD events:
* ADD: _NEW_ locally detected client
* ADD: already existing client with new flags
* DEL: disappeared local client
The first and the last type of event could in theory still be removed together from the (to be announced) events queue. But if the "update flags" ADD is dropped together with the DEL, it would still leave global translation table of a remote node in the incorrect state - believing that the client didn't disappear.
If a detected client was previously announced, a DEL event must only overwrite the "update flags" ADD but the DEL itself must still continue to exist in the (to be anounced) events queue. For now, adjustment of the announced flags is used for everything instead of dropping already queued up events completely.
Similarly, a DEL followed by an ADD caused both entries to be deleted. But the new ADD could announce flags changes which were not yet present for the client before it was marked for DELetion. The new ADD must therefore only overwrite the DEL - but still be kept.
--- net/batman-adv/translation-table.c | 41 ++++++++---------------------- 1 file changed, 11 insertions(+), 30 deletions(-)
net/batman-adv/translation-table.c +11 -30
@@ -455,6 +455,9 @@ batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry *orig_entry)* @bat_priv: the bat priv with all the soft interface information * @tt_local_entry: the TT entry involved in the event * @event_flags: flags to store in the event structure +* +* Only a single change per client is queued. It describes the latest state of +* the client and a new event therefore replaces an already queued one. */ static void batadv_tt_local_event(struct batadv_priv *bat_priv, struct batadv_tt_local_entry *tt_local_entry,
@@ -463,8 +466,7 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,struct batadv_tt_change_node *tt_change_node, *entry, *safe;struct batadv_tt_common_entry *common = &tt_local_entry->common;u8 flags = common->flags | event_flags; -bool event_removed = false; -bool del_op_requested, del_op_entry; +bool del_op_requested; tt_change_node =kmem_cache_alloc (batadv_tt_change_cache,GFP_ATOMIC );if (!tt_change_node)
@@ -496,44 +498,23 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,if (entry->change.vid != tt_change_node->change.vid)continue ; -/* DEL+ADD in the same orig interval have no effect and can be -* removed to avoid silly behaviour on the receiver side. The -* other way around (ADD+DEL) can happen in case of roaming of -* a client still in the NEW state. Roaming of NEW clients is -* now possible due to automatically recognition of "temporary" -* clients -*/ - del_op_entry = entry->change.flags &BATADV_TT_CLIENT_DEL ; -if (!del_op_requested && del_op_entry) - goto del; -if (del_op_requested && !del_op_entry) - goto del; - -/* this is a second add in the same originator interval. It -* means that flags have been changed: update them! +/* the other nodes may know the client with different +* flags. A DEL+ADD must therefore still announce the +* current flags and an ADD+DEL must still remove the +* client. ADD+ADD and DEL+DEL only update the flags */ -if (!del_op_requested && !del_op_entry) - entry->change.flags = flags; - -continue ; -del: -list_del (&entry->list); -kmem_cache_free (batadv_tt_change_cache, entry); + entry->change.flags = flags;kmem_cache_free (batadv_tt_change_cache, tt_change_node); - event_removed = true; + goto unlock; }/* track the change in the OGMinterval list */ list_add_tail (&tt_change_node->list, &bat_priv->tt.changes_list); +atomic_inc (&bat_priv->tt.local_changes); unlock:spin_unlock_bh (&bat_priv->tt.changes_list_lock); - -if (event_removed) -atomic_dec (&bat_priv->tt.local_changes); -else -atomic_inc (&bat_priv->tt.local_changes); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1349/2857 batman-adv: tt: dont drop local events queued during TVLV update
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit ed7a0dfdd370acb48be7a281df732c1bebcc7f1d upstream.
batadv_tt_tvlv_container_update() read the number of local changes without holding changes_list_lock. batadv_tt_local_event() is not serialized by the commit_lock and can queue new events before the changes_list is flushed:
CPU0 CPU1
batadv_tt_tvlv_container_update()
num = ...local_changes;
batadv_tt_local_event()
list_add_tail(...);
...local_changes++;
spin_lock_bh(&...changes_list_lock);
/* only num events copied but all freed */The additional events were freed without ever being sent. Other nodes will only notice this via a CRC mismatch and must request the full table.
The number of changes and the changes_list must therefore be taken atomically. Events queued afterwards then stay in the tt.changes_list for the next TT round.
The changes can no longer be kept for the next round when the TVLV buffer allocation fails. But they would be sent with a skipped TTVN anyway, so the other nodes have to request the full table in this case either way. The last changeset is only dropped in this case when the TTVN was incremented. Without new changes, it still describes the current TTVN.
Previously, the unconsumed changes caused a retry of the TVLV container update in the next commit round. Since the changes are now consumed, the next round would only take the path without changes and wait for BATADV_TT_OGM_APPEND_MAX rounds before updating the container again. Until then, the outdated container with the previous TTVN would still be announced. The ogm_append_cnt is therefore reset on failure to retry the update in the next OGM interval.
This doesn't make the CRC consistent with the announced changeset. The local table modifications are still not serialized with the commit and batadv_tt_local_transition_new() can still make a client part of the CRC for which the event is only part of the next TT round. Such an inconsistency is detected by the CRC check of the other nodes and solved via a full table request.
[ Context, switch to old "mesh_iface" name "soft_iface", access
local_changes with atomic_t helpers ]
--- net/batman-adv/translation-table.c | 61 +++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 13 deletions(-)
net/batman-adv/translation-table.c +48 -13
@@ -1019,20 +1019,22 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,* batadv_tt_tvlv_container_update() - update the translation table tvlv * container after local tt changes have been committed * @bat_priv: the bat priv with all the soft interface information +* @changes_list: list of committed changes which will be consumed +* @tt_diff_entries_num: number of entries in @changes_list */ -static void batadv_tt_tvlv_container_update (struct batadv_priv *bat_priv) +static void batadv_tt_tvlv_container_update (struct batadv_priv *bat_priv, +struct list_head *changes_list, +int tt_diff_entries_num) {struct batadv_tt_change_node *entry, *safe;struct batadv_tvlv_tt_data *tt_data;struct batadv_tvlv_tt_change *tt_change;int tt_diff_len, tt_change_len =0 ; -int tt_diff_entries_num =0 ;int tt_diff_entries_count =0 ;bool drop_changes = false;size_t tt_extra_len =0 ;u16 tvlv_len; - tt_diff_entries_num =atomic_read (&bat_priv->tt.local_changes); tt_diff_len =batadv_tt_len (tt_diff_entries_num);/* if we have too many changes for one packet don't send any
@@ -1050,19 +1052,39 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) tvlv_len =batadv_tt_prepare_tvlv_local_data (bat_priv, &tt_data, &tt_change, &tt_diff_len); -if (!tvlv_len) +if (!tvlv_len) { +/* the changes are lost and the other nodes have to request the +* full table. Don't answer TT requests for the new TTVN with +* the stale changeset of the previous TTVN. Without changes, the +* TTVN was not incremented and the last changeset is still valid +*/ +if (drop_changes || tt_diff_entries_num >0 ) { +list_for_each_entry_safe (entry, safe, changes_list, + list) { +list_del (&entry->list); +kmem_cache_free (batadv_tt_change_cache, entry); + } + +spin_lock_bh (&bat_priv->tt.last_changeset_lock); +kfree (bat_priv->tt.last_changeset); + bat_priv->tt.last_changeset =NULL ; + bat_priv->tt.last_changeset_len =0 ; +spin_unlock_bh (&bat_priv->tt.last_changeset_lock); + } + +/* announce the already committed TTVN in the next OGM interval +* instead of waiting for BATADV_TT_OGM_APPEND_MAX idle rounds +*/ +atomic_set (&bat_priv->tt.ogm_append_cnt,0 );return ; + } tt_data->flags =BATADV_TT_OGM_DIFF ;if (!drop_changes && tt_diff_len ==0 ) goto container_register; -spin_lock_bh (&bat_priv->tt.changes_list_lock); -atomic_set (&bat_priv->tt.local_changes,0 ); - -list_for_each_entry_safe (entry, safe, &bat_priv->tt.changes_list, - list) { +list_for_each_entry_safe (entry, safe, changes_list, list) {if (tt_diff_entries_count < tt_diff_entries_num) { memcpy(tt_change + tt_diff_entries_count, &entry->change,
@@ -1072,7 +1094,6 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)list_del (&entry->list);kmem_cache_free (batadv_tt_change_cache, entry); } -spin_unlock_bh (&bat_priv->tt.changes_list_lock); tt_extra_len =batadv_tt_len (tt_diff_entries_num - tt_diff_entries_count);
@@ -3761,11 +3782,25 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)*/ static void batadv_tt_local_commit_changes_nolock (struct batadv_priv *bat_priv) { +LIST_HEAD (changes_list); +int changes_num; +lockdep_assert_held (&bat_priv->tt.commit_lock); -if (atomic_read (&bat_priv->tt.local_changes) <1 ) { +/* atomically get the list of changes. The TTVN decision and the +* announced changeset must cover the same events. Events queued +* afterwards stay in the tt.changes_list for the next TT round +*/ +spin_lock_bh (&bat_priv->tt.changes_list_lock); +list_splice_init (&bat_priv->tt.changes_list, &changes_list); + changes_num =atomic_read (&bat_priv->tt.local_changes); +atomic_set (&bat_priv->tt.local_changes,0 ); +spin_unlock_bh (&bat_priv->tt.changes_list_lock); + +if (changes_num ==0 ) {if (!batadv_atomic_dec_not_zero (&bat_priv->tt.ogm_append_cnt)) -batadv_tt_tvlv_container_update (bat_priv); +batadv_tt_tvlv_container_update (bat_priv, &changes_list, + changes_num);return ; }
@@ -3782,7 +3817,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)/* reset the sending counter */ atomic_set (&bat_priv->tt.ogm_append_cnt,BATADV_TT_OGM_APPEND_MAX ); -batadv_tt_tvlv_container_update (bat_priv); +batadv_tt_tvlv_container_update (bat_priv, &changes_list, changes_num); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1350/2857 lib/crypto: mips: Disable Octeon SHA code on little-endian kernels
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit dd2a4edb26e1c78823c50ba10c42f2d3de2e5ec4 upstream.
Kernels built for the MIPS64-based Cavium Octeon SoCs are normally big-endian, but little-endian builds are also supported. Currently, the SHA-1, SHA-256, and SHA-512 code using the Octeon crypto co-processor is enabled in both builds.
This code is untestable without the hardware. However, based on the code itself, it is implausible that it computes hash values correctly in little-endian builds. Such builds write many incorrect values to COP2:
- SHA-1 and SHA-256: The 64-bit integer that contains the last two 32-bit message words of each block is written to COP2 entirely byte-reflected, due to missing endianness conversion in octeon_sha1_start() and octeon_sha256_start() to compensate for using native 64-bit loads from the message bytes. This differs from all the earlier message words which are written correctly.
Furthermore, the state is written to COP2 with each 32-bit word byte-reflected within each 64-bit integer, due to incorrect use of 64-bit endianness conversion in write_octeon_64bit_hash_dword() when the state is kept in memory in native-endian 32-bit words.
- SHA-512: All the 64-bit message words are written to COP2 byte-reflected, due to missing endianness conversion in write_octeon_64bit_block_sha512() and octeon_sha512_start(). The SHA-512 state words seem to be written correctly.
Big-endian kernels aren't affected by these bugs. These bugs also aren't new; this code has been broken on little-endian ever since it and Octeon little-endian support were first added in v4.1.
Commit d2a948d2db68 ("MIPS: Octeon: Make octeon-md5 driver endian-agnostic") made the MD5 code work on little-endian kernels by adding 64-bit endianness conversions to the COP2 macros used by MD5 (some of which are shared by SHA-1 and SHA-256, despite those algorithms keeping the state words in native-endian instead of MD5's little-endian, causing some of the strange behavior described above). However, SHA-1, SHA-256, and SHA-512 were never fixed to work on little-endian kernels.
Therefore, disable the Octeon SHA-1, SHA-256, and SHA-512 code in little-endian kernels. This causes the generic code that actually computes hash values correctly to be used instead.
--- arch/mips/crypto/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/mips/crypto/Kconfig +3 -3
@@ -32,7 +32,7 @@ config CRYPTO_MD5_OCTEON config CRYPTO_SHA1_OCTEON tristate "Hash functions: SHA-1 (OCTEON)" - depends on CPU_CAVIUM_OCTEON + depends on CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN select CRYPTO_SHA1 select CRYPTO_HASH help
@@ -42,7 +42,7 @@ config CRYPTO_SHA1_OCTEON config CRYPTO_SHA256_OCTEON tristate "Hash functions: SHA-224 and SHA-256 (OCTEON)" - depends on CPU_CAVIUM_OCTEON + depends on CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN select CRYPTO_SHA256 select CRYPTO_HASH help
@@ -52,7 +52,7 @@ config CRYPTO_SHA256_OCTEON config CRYPTO_SHA512_OCTEON tristate "Hash functions: SHA-384 and SHA-512 (OCTEON)" - depends on CPU_CAVIUM_OCTEON + depends on CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN select CRYPTO_SHA512 select CRYPTO_HASH help
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1351/2857 blk-mq: end the request if getting a keyslot fails
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit e67cb6ed40e7f45912b63d7d575f18dfd2ebc98a upstream.
When blk_crypto_rq_get_keyslot() fails, blk_mq_submit_bio() ends the bio by hand and frees the request. By then blk_mq_bio_to_request() has done the IO accounting, which blk_mq_free_request() doesn't undo, so the in_flight counter never drops and iostat shows a device that is 100% busy. If the bio went through zone write plugging the zone stays plugged as well, and every later write to it waits forever.
Use blk_mq_end_request() like the dispatch path does for a request the driver rejected, after marking it for zone write plugging.
Move the call to blk_zone_write_plug_init_request() before blk_crypto_rq_get_keyslot() so that it doesn't need to be duplicated. It doesn't depend on the keyslot.
[ Backport to 6.1.y: dropped the part related to
bio_zone_write_plugging(), which doesn't exist on this branch. ]
--- block/blk-mq.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
block/blk-mq.c +1 -3
@@ -3030,9 +3030,7 @@ void blk_mq_submit_bio(struct bio *bio) ret =blk_crypto_rq_get_keyslot (rq);if (ret !=BLK_STS_OK ) { - bio->bi_status = ret; -bio_endio (bio); -blk_mq_free_request (rq); +blk_mq_end_request (rq, ret);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1352/2857 ALSA: usx2y: Refuse a retried DSP load after a failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: YuanZhe Liu <[email protected]>
[ Upstream commit 1f8101b6adc87a3ddbd51fcb6609251591758026 ]
snd_usx2y_hwdep_dsp_load() sets up the asynchronous sequence URBs and the interrupt URB when the FPGA firmware image with index 1 is loaded, and then creates the ALSA devices. If usx2y_in04_init() or usx2y_create_alsa_devices() fails, the URBs that were already set up are left in place.
The core keeps the index unloaded when the callback fails, so user space may issue the same request again. The second attempt then enters usx2y_async_seq04_init() or usx2y_in04_init() with the URBs still allocated and trips WARN_ON(usx2y->as04.buffer) or WARN_ON(usx2y->in04_urb).
The URBs cannot be released at this point: the card may already have registered PCM devices that user space can still open, and the disconnect handler accesses the URBs without holding the DSP lock. Mark the chip as hung instead, so that a retried request is refused with -ENODEV and the assertions keep their meaning. The URBs are released by snd_usx2y_card_private_free() when the card is freed.
A failing usx2y_async_seq04_init() still releases its own URBs, so that path remains retryable.
--- sound/usb/usx2y/usX2Yhwdep.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/usb/usx2y/usX2Yhwdep.c +5 -0
@@ -185,6 +185,9 @@ static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw,int lret, err;char *buf; +if (priv->chip_status &USX2Y_STAT_CHIP_HUP ) +return -ENODEV ; +snd_printdd ("dsp_load %s\n" , dsp->name); buf =memdup_user (dsp->image, dsp->length);
@@ -209,11 +212,13 @@ static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw, err =usx2y_in04_init (priv);if (err) {snd_printk (KERN_ERR "usx2y_in04_init error\n" ); + priv->chip_status |=USX2Y_STAT_CHIP_HUP ;return err; } err =usx2y_create_alsa_devices (hw->card);if (err) {snd_printk (KERN_ERR "usx2y_create_alsa_devices error %i\n" , err); + priv->chip_status |=USX2Y_STAT_CHIP_HUP ;return err; } priv->chip_status |=USX2Y_STAT_CHIP_INIT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1353/2857 Bluetooth: hci_sync: pause advertising for the scan address update
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valentin Kindschi <[email protected]>
[ Upstream commit 56ed6b127a27c418dc2daa3fd076539d8fe69c4c ]
hci_active_scan_sync() programs a non-resolvable private address with LE Set Random Address on every active scan start.
BLUETOOTH CORE SPECIFICATION Vol 4, Part E, 7.8.4 says the controller shall return Command Disallowed (0x0C) for that command while legacy advertising or scanning is enabled. hci_pause_addr_resolution(), called just above, only stops advertising when LL privacy is in use, so on a controller without it the command is issued while advertising is still on:
Bluetooth: hci0: Opcode 0x2005 failed: -16
It does not converge either. hdev->random_addr is only set on a successful command complete, so it stays BDADDR_ANY, and the deferral added by commit c2994b008492 ("Bluetooth: hci_sync: Fix not setting Random Address when required") requires it to be set. Unlike the resolvable address a few lines above, which is reused while rpa_valid(), the non-resolvable one is regenerated and rewritten on every call, so a controller that refuses the write is asked again at the scan restart period of about 10 s, for as long as discovery keeps restarting. Observed on a BCM43455, which has no LL privacy and no extended advertising, 190 rejections in one capture, every one retrying the same address:
< LE Set Random Address Address: 02:16:91:90:F1:D4 (Non-Resolvable) > Command Complete LE Set Random Address, Command Disallowed < LE Set Random Address Address: 26:90:57:96:9A:3E (Non-Resolvable) > Command Complete LE Set Random Address, Command Disallowed
Pause advertising for the address update, and resume it once the update is done and before the scan is started. The pause does not outlive the
function: it is taken only when nothing else holds it, and every exit resumes advertising, which also releases the pause taken by hci_pause_addr_resolution(). A failed pause returns before marking anything paused, so the error path is a no-op.
The resume in the error path is no longer guarded by ll_privacy_capable(). That guard matched a pause taken only under LL privacy; the pause added here is unconditional, and hci_resume_advertising_sync() returns early when nothing was paused.
One caveat this widens, raised on the previous posting. When HCI_ADVERTISING is set, hci_pause_advertising_sync() also clears HCI_DISCOVERABLE and HCI_LIMITED_DISCOVERABLE and zeroes discov_timeout, and hci_resume_advertising_sync() restores only HCI_ADVERTISING, so the discoverable state is lost. It reproduces today on an LL privacy controller through hci_pause_addr_resolution(); the unconditional pause makes it reachable without LL privacy as well. hci_suspend_sync() also pauses unconditionally, so a device that suspends loses the same state on any controller today. That asymmetry is pre-existing and is left alone here rather than folded into a scan path fix.
Legacy controllers have one random address register, shared by the scanner and the advertiser. Restoring the advertiser here can reprogram it when the advertiser is non-connectable, so the scan then uses that address rather than the one generated for it. Both are non-resolvable and neither is linkable to the identity address. With privacy enabled both roles already share one resolvable address the same way.
With the patch, on the same hardware:
< LE Set Advertising Enable Enable: 0x00 Success < LE Set Random Address Success < LE Set Advertising Parameters Success < LE Set Advertising Enable Enable: 0x01 Success < LE Set Scan Parameters Success < LE Set Scan Enable Enable: 0x01 Success
The address write is accepted, and advertising is restored before the scan is started.
Over 119369 btmon records and about 12 minutes of the normal workload of that device, alternating active and passive scanning with ten outgoing connection attempts, every LE Set Random Address succeeded and there were no Command Disallowed responses of any opcode, against one per scan restart before.
Patch 1 is required: without it the resume added here returns -EPERM on the controllers this fixes and leaves advertising disabled.
[ Valentin: Adjusted for 6.1.y: the privacy guard removed in the failed: label
reads use_ll_privacy(hdev) in this tree, and the line after the added resume is only if (hci_is_adv_monitoring(hdev)) {, without the HCI_QUIRK_STRICT_DUPLICATE_FILTER term. The added lines are unchanged. Requires commit 737139f4157d ("Bluetooth: hci_sync: re-enable legacy advertising on resume"). ]
--- net/bluetooth/hci_sync.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
net/bluetooth/hci_sync.c +12 -3
@@ -5913,6 +5913,7 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)u8 filter_policy =0x00 ;/* Default is to enable duplicates filter */ u8 filter_dup =LE_SCAN_FILTER_DUP_ENABLE ; +bool paused;int err;bt_dev_dbg (hdev,"" );
@@ -5936,6 +5937,12 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)if (err) goto failed; +/* LE Set Random Address is disallowed while advertising is enabled. */ + paused = !hdev->advertising_paused; + err =hci_pause_advertising_sync (hdev); +if (err) + goto failed; +/* All active scans will be done with either a resolvable private * address (when privacy feature has been enabled) or non-resolvable * private address.
@@ -5945,6 +5952,9 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)if (err <0 ) own_addr_type =ADDR_LE_DEV_PUBLIC ; +if (paused) +hci_resume_advertising_sync (hdev); +if (hci_is_adv_monitoring (hdev)) {/* Duplicate filter should be disabled when some advertisement * monitor is activated, otherwise AdvMon can only receive one
@@ -5969,9 +5979,8 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval)return err; failed: -/* Resume advertising if it was paused */ -if (use_ll_privacy (hdev)) -hci_resume_advertising_sync (hdev); +/* No-op when advertising was not paused. */ +hci_resume_advertising_sync (hdev);/* Resume passive scanning */ hci_update_passive_scan_sync (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1354/2857 media: microchip-isc: fix awb_mutex and lock lifecycle
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 5540b48c0702f6a1389db3d473d7fd0db930422a ]
isc->lock and awb_mutex were initialised in isc_async_complete() and destroyed in isc_async_unbind(), tying their lifetime to the subdev bind/unbind cycle instead of the device:
- isc_async_unbind() destroyed awb_mutex before cancel_work_sync(), which takes it;
- a failed .complete() left them initialised, and isc->lock was destroyed only on the .complete() error path, so the normal unbind path leaked it;
- a rebind runs .complete() again and reinitialises a live mutex.
Initialise both with devm_mutex_init() at probe so they live for the whole device lifetime and are freed at remove, and drop the init and destroy from the .complete()/.unbind() callbacks.
isc_async_complete_err then only returned ret, so drop the label and return directly at each error site.
--- drivers/media/platform/atmel/atmel-isc-base.c | 18 +++++------------- .../media/platform/atmel/atmel-sama5d2-isc.c | 9 +++++++++ .../media/platform/atmel/atmel-sama7g5-isc.c | 9 +++++++++ 3 files changed, 23 insertions(+), 13 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +5 -13
@@ -1754,7 +1754,6 @@ static void isc_async_unbind(struct v4l2_async_notifier *notifier, {struct isc_device *isc =container_of (notifier->v4l2_dev, struct isc_device, v4l2_dev); -mutex_destroy (&isc->awb_mutex);cancel_work_sync (&isc->awb_work);video_unregister_device (&isc->video_dev);v4l2_ctrl_handler_free (&isc->ctrls.handler);
@@ -1863,8 +1862,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) isc->current_subdev =container_of (notifier, struct isc_subdev_entity, notifier); -mutex_init (&isc->lock); -mutex_init (&isc->awb_mutex);init_completion (&isc->comp);
@@ -1884,7 +1881,7 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)if (ret <0 ) {v4l2_err (&isc->v4l2_dev,"vb2_queue_init() failed: %d\n" , ret); - goto isc_async_complete_err; +return ret; }/* Init video dma queues */
@@ -1896,19 +1893,19 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)if (ret <0 ) {v4l2_err (&isc->v4l2_dev,"Init format failed: %d\n" , ret); - goto isc_async_complete_err; +return ret; } ret =isc_set_default_fmt (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Could not set default format\n" ); - goto isc_async_complete_err; +return ret; } ret =isc_ctrl_init (isc);if (ret) {v4l2_err (&isc->v4l2_dev,"Init isc ctrols failed: %d\n" , ret); - goto isc_async_complete_err; +return ret; }/* Register video device */
@@ -1928,15 +1925,10 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)if (ret <0 ) {v4l2_err (&isc->v4l2_dev,"video_register_device failed: %d\n" , ret); - goto isc_async_complete_err; +return ret; }return 0 ; - -isc_async_complete_err: -mutex_destroy (&isc->awb_mutex); -mutex_destroy (&isc->lock); -return ret; }const struct v4l2_async_notifier_operations isc_async_ops = {
drivers/media/platform/atmel/atmel-sama5d2-isc.c +9 -0
@@ -30,6 +30,7 @@#include <linux/interrupt.h> #include <linux/math64.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/of_graph.h> #include <linux/platform_device.h>
@@ -405,6 +406,14 @@ static int atmel_isc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, isc); isc->dev = dev; + ret =devm_mutex_init (dev, &isc->lock); +if (ret) +return ret; + + ret =devm_mutex_init (dev, &isc->awb_mutex); +if (ret) +return ret; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); io_base =devm_ioremap_resource (dev, res);if (IS_ERR (io_base))
drivers/media/platform/atmel/atmel-sama7g5-isc.c +9 -0
@@ -33,6 +33,7 @@#include <linux/interrupt.h> #include <linux/math64.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/of_graph.h> #include <linux/platform_device.h>
@@ -394,6 +395,14 @@ static int microchip_xisc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, isc); isc->dev = dev; + ret =devm_mutex_init (dev, &isc->lock); +if (ret) +return ret; + + ret =devm_mutex_init (dev, &isc->awb_mutex); +if (ret) +return ret; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); io_base =devm_ioremap_resource (dev, res);if (IS_ERR (io_base))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1355/2857 arm64: dts: mediatek: mt7986: correct timer frequency
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Pesaresi <[email protected]>
[ Upstream commit 1cf18e4b9815beaf0439c5b57b65b45151c82ad7 ]
The MT7986 architected timer runs at 12,986,200 Hz rather than 13 MHz. Firmware reports 13 MHz through CNTFRQ_EL0, causing the system clock to run slow by about 1062 ppm. This exceeds the kernel's 500 ppm NTP correction limit and leaves clock discipline saturated.
The corrected rate comes from MediaTek's downstream OpenWrt feed, where it is applied to both MT7986A and MT7986B. Since upstream mt7986b.dtsi includes mt7986a.dtsi, add it once to the common timer node so the architected timer driver uses the actual counter rate.
--- arch/arm64/boot/dts/mediatek/mt7986a.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/mediatek/mt7986a.dtsi +1 -0
@@ -81,6 +81,7 @@ wmcpu_emi: wmcpu-reserved@4fc00000 { timer { compatible = "arm,armv8-timer"; interrupt-parent = <&gic>; + clock-frequency = <12986200>; interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 11 IRQ_TYPE_LEVEL_LOW>,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1356/2857 wifi: rtw89: cap firmware section_num before parsing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laxman Acharya Padhya <[email protected]>
[ Upstream commit 273b0a8be083df6d0319ce62caa870e927f94a31 ]
rtw89_fw_bin_info.section_info has FWDL_SECTION_MAX_NUM (10) entries. The v0/v1 header parsers take section_num from an 8-bit firmware field (0..255) and write info->section_info[i] with no cap. rtw89_fw_download_suit() keeps that object on the stack, so a crafted firmware blob overflows the stack.
Reject a truncated header and a section table that does not fit in the firmware image before reading fw_hdr->sections[i].
--- drivers/net/wireless/realtek/rtw89/fw.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/net/wireless/realtek/rtw89/fw.c +15 -0
@@ -91,9 +91,24 @@ static int rtw89_fw_hdr_parser(struct rtw89_dev *rtwdev, const u8 *fw, u32 len,if (!info)return -EINVAL ; +if (len <RTW89_FW_HDR_SIZE ) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->section_num =GET_FW_HDR_SEC_NUM (fw); +if (!info->section_num || info->section_num >FWDL_SECTION_MAX_NUM ) { +rtw89_err (rtwdev,"[ERR]invalid fw section num %u\n" , + info->section_num); +return -EINVAL ; + } + info->hdr_len =RTW89_FW_HDR_SIZE + info->section_num *RTW89_FW_SECTION_HDR_SIZE ; +if (info->hdr_len > len) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } bin = fw + info->hdr_len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1357/2857 wifi: mac80211: update outdated comment
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kexin Sun <[email protected]>
[ Upstream commit b8a57b979a7c2069081ed0bf88a727b17d85ac96 ]
The function ieee80211_start_scan() was refactored and replaced by __ieee80211_start_scan() in commit f3b85252f081 ("mac80211: fix scan races and rework scanning"). Update the comment in ieee80211_tx_h_check_assoc() accordingly.
Additionally, remove the broken gmane.org link in the comment.
Stable-dep-of: 13e51269b665 ("wifi: mac80211: queue frames while off-channel")
--- net/mac80211/tx.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
net/mac80211/tx.c +1 -4
@@ -300,10 +300,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)* active scan) are allowed, all other frames should not be * sent and we should not get here, but if we do * nonetheless, drop them to avoid sending them -* off-channel. See the link below and -* ieee80211_start_scan() for more. -* -* http://article.gmane.org/gmane.linux.kernel.wireless.general/30089 +* off-channel. See __ieee80211_start_scan() for more. */ return TX_DROP ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1358/2857 wifi: mac80211: queue frames while off-channel
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislaw Gruszka <[email protected]>
[ Upstream commit 13e51269b6656768dc595ed6025e4974f2026543 ]
Drivers without FAST_XMIT and hardware scan support currently drop TX frames during software scanning while being off-channel. This happens in ieee80211_tx_h_check_assoc() before frames reach internal TX queue.
Move the off-channel check to invoke_tx_handlers_late(), after ieee80211_queue_skb(). Frames can then remain queued and be transmitted when the interface returns on-channel. This how TX works currently when code goes via ieee80211_xmit_fast() path.
Below is rt2x00 driver ping output example while scanning, before and after the fix. After the fix, packets are no longer lost. Some have increased latency, what is expected behavior.
BEFORE:
64 bytes from 192.168.0.1: icmp_seq=29 ttl=64 time=3.61 ms 64 bytes from 192.168.0.1: icmp_seq=31 ttl=64 time=3.33 ms # Missed 30 64 bytes from 192.168.0.1: icmp_seq=32 ttl=64 time=4.03 ms 64 bytes from 192.168.0.1: icmp_seq=34 ttl=64 time=3.10 ms # Missed 33 64 bytes from 192.168.0.1: icmp_seq=36 ttl=64 time=3.04 ms # Missed 35 64 bytes from 192.168.0.1: icmp_seq=38 ttl=64 time=3.05 ms # Missed 37 64 bytes from 192.168.0.1: icmp_seq=40 ttl=64 time=4.14 ms # Missed 39 64 bytes from 192.168.0.1: icmp_seq=41 ttl=64 time=4.50 ms
AFTER:
64 bytes from 192.168.0.1: icmp_seq=29 ttl=64 time=3.40 ms 64 bytes from 192.168.0.1: icmp_seq=30 ttl=64 time=6.10 ms 64 bytes from 192.168.0.1: icmp_seq=31 ttl=64 time=4.69 ms 64 bytes from 192.168.0.1: icmp_seq=32 ttl=64 time=4.49 ms 64 bytes from 192.168.0.1: icmp_seq=33 ttl=64 time=148 ms 64 bytes from 192.168.0.1: icmp_seq=34 ttl=64 time=6.83 ms 64 bytes from 192.168.0.1: icmp_seq=35 ttl=64 time=8.66 ms 64 bytes from 192.168.0.1: icmp_seq=36 ttl=64 time=13.0 ms 64 bytes from 192.168.0.1: icmp_seq=37 ttl=64 time=4.78 ms 64 bytes from 192.168.0.1: icmp_seq=38 ttl=64 time=3.85 ms
--- net/mac80211/tx.c | 52 +++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 24 deletions(-)
net/mac80211/tx.c +28 -24
@@ -282,7 +282,6 @@ ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx) static ieee80211_tx_result debug_noinlineieee80211_tx_h_check_assoc (struct ieee80211_tx_data *tx) { -struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb);bool assoc = false;
@@ -290,20 +289,6 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)if (unlikely (info->flags &IEEE80211_TX_CTL_INJECTED ))return TX_CONTINUE ; -if (unlikely (test_bit (SCAN_SW_SCANNING , &tx->local->scanning)) && -test_bit (SDATA_STATE_OFFCHANNEL , &tx->sdata->state) && - !ieee80211_is_probe_req (hdr->frame_control) && - !ieee80211_is_any_nullfunc (hdr->frame_control)) -/* -* When software scanning only nullfunc frames (to notify -* the sleep state to the AP) and probe requests (for the -* active scan) are allowed, all other frames should not be -* sent and we should not get here, but if we do -* nonetheless, drop them to avoid sending them -* off-channel. See __ieee80211_start_scan() for more. -*/ -return TX_DROP ; -if (tx->sdata->vif.type ==NL80211_IFTYPE_OCB )return TX_CONTINUE ;
@@ -829,6 +814,33 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)return TX_CONTINUE ; } +static ieee80211_tx_result debug_noinline +ieee80211_tx_h_check_offchannel (struct ieee80211_tx_data *tx) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb); + +if (unlikely (info->flags &IEEE80211_TX_CTL_INJECTED )) +return TX_CONTINUE ; + +if (unlikely (test_bit (SCAN_SW_SCANNING , &tx->local->scanning)) && +test_bit (SDATA_STATE_OFFCHANNEL , &tx->sdata->state) && + !ieee80211_is_probe_req (hdr->frame_control) && + !ieee80211_is_any_nullfunc (hdr->frame_control)) { +/* +* When software scanning only nullfunc frames (to notify +* the sleep state to the AP) and probe requests (for the +* active scan) are allowed, all other frames should not be +* sent and we should not get here, but if we do +* nonetheless, drop them to avoid sending them +* off-channel. See __ieee80211_start_scan() for more. +*/ +return TX_DROP ; + } + +return TX_CONTINUE ; +} +static __le16 ieee80211_tx_next_seq (struct sta_info *sta,int tid) {u16 *seq = &sta->tid_seq[tid];
@@ -1887,6 +1899,7 @@ static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx) goto txh_done; } +CALL_TXH (ieee80211_tx_h_check_offchannel);CALL_TXH (ieee80211_tx_h_michael_mic_add);CALL_TXH (ieee80211_tx_h_sequence);CALL_TXH (ieee80211_tx_h_fragment);
@@ -4552,10 +4565,6 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,skb_get_hash (skb); } -if (unlikely (test_bit (SCAN_SW_SCANNING , &local->scanning)) && -test_bit (SDATA_STATE_OFFCHANNEL , &sdata->state)) - goto out_free; - skb =skb_share_check (skb,GFP_ATOMIC );if (unlikely (!skb))return ;
@@ -4617,11 +4626,6 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, info->control.hw_key = &key->conf;ieee80211_tx_8023 (sdata, skb, sta, false); - -return ; - -out_free: -kfree_skb (skb); } netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1359/2857 PCI: endpoint: pci-epf-vntb: Manage virtual NTB and PCI bus lifetime
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 5cdbd6d3a3a147fa9975e35f2602cbec9a72a932 ]
The virtual PCI driver registers an ntb_dev but has no remove callback. Unbinding the endpoint function can therefore free BARs while the NTB device and its client still use them. It also leaves the virtual PCI devices and root bus allocated.
Allocate an ntb_dev for each virtual PCI probe and unregister it from the matching remove callback. Start command processing only after registration. Publish the device for doorbell IRQs at the same point. During remove, stop the command work and drain IRQ handlers before unregistering the device.
Retain the root bus returned by pci_scan_bus() so it can be removed on unbind. Unregister the virtual PCI driver before releasing endpoint resources. Stop and remove the root bus under the PCI rescan/remove lock, then release its host bridge.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +55 -14
@@ -116,7 +116,7 @@ struct epf_ntb_ctrl { } __packed;struct epf_ntb { -struct ntb_dev ntb; +struct ntb_dev *ntb;struct pci_epf *epf;struct config_group group;
@@ -143,10 +143,15 @@ struct epf_ntb {void __iomem *vpci_mw_addr[MAX_MW ];struct delayed_work cmd_handler; +struct pci_bus *vpci_bus; };#define to_epf_ntb (epf_group) container_of((epf_group), struct epf_ntb, group) -#define ntb_ndev (__ntb) container_of(__ntb, struct epf_ntb, ntb) + +static struct epf_ntb *ntb_ndev (struct ntb_dev *ntb) +{ +return ntb->pdev->sysdata; +}static struct pci_epf_header epf_ntb_header = { .vendorid =PCI_ANY_ID ,
@@ -172,7 +177,7 @@ static int epf_ntb_link_up(struct epf_ntb *ntb, bool link_up)else ntb->reg->link_status &= ~LINK_STATUS_UP ; -ntb_link_event (&ntb->ntb); +ntb_link_event (ntb->ntb);return 0 ; }
@@ -262,7 +267,7 @@ static void epf_ntb_cmd_handler(struct work_struct *work)if (readl (ntb->epf_db + i *4 )) ntb->db |=1 << (i -1 ); -ntb_db_event (&ntb->ntb, i); +ntb_db_event (ntb->ntb, i);writel (0 , ntb->epf_db + i *4 ); } }
@@ -774,7 +779,6 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb) }INIT_DELAYED_WORK (&ntb->cmd_handler, epf_ntb_cmd_handler); -queue_work (kpcintb_workqueue, &ntb->cmd_handler.work);return 0 ;
@@ -1023,6 +1027,7 @@ static int vpci_scan_bus(void *sysdata)pr_err ("create pci bus failed\n" );return -EINVAL ; } + ndev->vpci_bus = vpci_bus;pci_bus_add_devices (vpci_bus);
@@ -1067,7 +1072,7 @@ static int vntb_epf_mw_set_trans(struct ntb_dev *ndev, int pidx, int idx,int ret;struct device *dev; - dev = &ntb->ntb.dev; + dev = &ndev->dev; barno = ntb->epf_ntb_bar[BAR_MW0 + idx]; epf_bar = &ntb->epf->bar[barno]; epf_bar->phys_addr = addr;
@@ -1170,7 +1175,7 @@ static int vntb_epf_peer_db_set(struct ntb_dev *ndev, u64 db_bits)PCI_EPC_IRQ_MSI , interrupt_num + 1);if (ret) -dev_err (&ntb->ntb.dev,"Failed to raise IRQ\n" ); +dev_err (&ntb->epf->dev,"Failed to raise IRQ\n" );return ret; }
@@ -1253,13 +1258,18 @@ static const struct ntb_dev_ops vntb_epf_ops = {static int pci_vntb_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -int ret;struct epf_ntb *ndev = (struct epf_ntb *)pdev->sysdata;struct device *dev = &pdev->dev; +struct ntb_dev *ntb; +int ret; - ndev->ntb.pdev = pdev; - ndev->ntb.topo =NTB_TOPO_NONE ; - ndev->ntb.ops = &vntb_epf_ops; + ntb =devm_kzalloc (dev,sizeof (*ntb),GFP_KERNEL ); +if (!ntb) +return -ENOMEM ; + + ntb->pdev = pdev; + ntb->topo =NTB_TOPO_NONE ; + ntb->ops = &vntb_epf_ops; ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 ));if (ret) {
@@ -1267,16 +1277,33 @@ static int pci_vntb_probe(struct pci_dev *pdev, const struct pci_device_id *id)return -EINVAL ; } - ret =ntb_register_device (&ndev->ntb); + ret =ntb_register_device (ntb);if (ret) {dev_err (dev,"Failed to register NTB device\n" );return ret; } +/* Publish after ntb_register_device() succeeds */ +smp_store_release (&ndev->ntb, ntb); +queue_delayed_work (kpcintb_workqueue, &ndev->cmd_handler,0 ); +dev_dbg (dev,"PCI Virtual NTB driver loaded\n" );return 0 ; } +static void pci_vntb_remove (struct pci_dev *pdev) +{ +struct epf_ntb *ndev = pdev->sysdata; +struct ntb_dev *ntb; + +/* Stop the work reader */ +cancel_delayed_work_sync (&ndev->cmd_handler); + + ntb =xchg (&ndev->ntb,NULL ); + +ntb_unregister_device (ntb); +} +static struct pci_device_id pci_vntb_table[] = { {PCI_DEVICE (0xffff ,0xffff ),
@@ -1288,6 +1315,7 @@ static struct pci_driver vntb_pci_driver = { .name = "pci-vntb", .id_table = pci_vntb_table, .probe = pci_vntb_probe, + .remove = pci_vntb_remove, };/* ============ PCIe EPF Driver Bind ====================*/
@@ -1368,12 +1396,25 @@ static int epf_ntb_bind(struct pci_epf *epf)*/ static void epf_ntb_unbind (struct pci_epf *epf) { +struct pci_host_bridge *bridge;struct epf_ntb *ntb =epf_get_drvdata (epf); +pci_unregister_driver (&vntb_pci_driver); + +if (ntb->vpci_bus) { + bridge =to_pci_host_bridge (ntb->vpci_bus->bridge); + +pci_lock_rescan_remove (); +pci_stop_root_bus (ntb->vpci_bus); +pci_remove_root_bus (ntb->vpci_bus); + ntb->vpci_bus =NULL ; +pci_unlock_rescan_remove (); + +pci_free_host_bridge (bridge); + } +epf_ntb_epc_cleanup (ntb);epf_ntb_config_spad_bar_free (ntb); - -pci_unregister_driver (&vntb_pci_driver); }// EPF driver probe
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1360/2857 media: microchip-isc: fix WB offset and gain register field masking
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 6e9eaa3b93870e4edac1bd2539fe113c24663eaf ]
ISC_WB_O_* and ISC_WB_G_* each pack two 13-bit fields. A negative offset sign-extends and corrupts the adjacent field. Add masks for the two fields and write them with FIELD_PREP(), which masks each value into its field, so sign extension can no longer bleed across.
--- drivers/media/platform/atmel/atmel-isc-base.c | 17 +++++++++-------- drivers/media/platform/atmel/atmel-isc-regs.h | 6 ++++++ 2 files changed, 15 insertions(+), 8 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +9 -8
@@ -8,6 +8,7 @@* Author: Eugen Hristev <[email protected]> * */ +#include <linux/bitfield.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/math64.h>
@@ -71,17 +72,17 @@ static inline void isc_update_awb_ctrls(struct isc_device *isc)/* In here we set our actual hw pipeline config */ regmap_write (isc->regmap,ISC_WB_O_RGR , - ((ctrls->offset[ISC_HIS_CFG_MODE_R ])) | - ((ctrls->offset[ISC_HIS_CFG_MODE_GR ]) <<16 )); +FIELD_PREP (ISC_WB_O_LO , ctrls->offset[ISC_HIS_CFG_MODE_R ]) | +FIELD_PREP (ISC_WB_O_HI , ctrls->offset[ISC_HIS_CFG_MODE_GR ]));regmap_write (isc->regmap,ISC_WB_O_BGB , - ((ctrls->offset[ISC_HIS_CFG_MODE_B ])) | - ((ctrls->offset[ISC_HIS_CFG_MODE_GB ]) <<16 )); +FIELD_PREP (ISC_WB_O_LO , ctrls->offset[ISC_HIS_CFG_MODE_B ]) | +FIELD_PREP (ISC_WB_O_HI , ctrls->offset[ISC_HIS_CFG_MODE_GB ]));regmap_write (isc->regmap,ISC_WB_G_RGR , - ctrls->gain[ISC_HIS_CFG_MODE_R ] | - (ctrls->gain[ISC_HIS_CFG_MODE_GR ] <<16 )); +FIELD_PREP (ISC_WB_G_LO , ctrls->gain[ISC_HIS_CFG_MODE_R ]) | +FIELD_PREP (ISC_WB_G_HI , ctrls->gain[ISC_HIS_CFG_MODE_GR ]));regmap_write (isc->regmap,ISC_WB_G_BGB , - ctrls->gain[ISC_HIS_CFG_MODE_B ] | - (ctrls->gain[ISC_HIS_CFG_MODE_GB ] <<16 )); +FIELD_PREP (ISC_WB_G_LO , ctrls->gain[ISC_HIS_CFG_MODE_B ]) | +FIELD_PREP (ISC_WB_G_HI , ctrls->gain[ISC_HIS_CFG_MODE_GB ])); }static inline void isc_reset_awb_ctrls (struct isc_device *isc)
drivers/media/platform/atmel/atmel-isc-regs.h +6 -0
@@ -149,6 +149,12 @@/* ISC White Balance Gain for B, GB Register */ #define ISC_WB_G_BGB 0x0000006c +/* Each WB offset/gain register packs two 13-bit fields, low and high */ +#define ISC_WB_O_LO GENMASK(12, 0)/* R or B offset [12:0] */ +#define ISC_WB_O_HI GENMASK(28, 16)/* GR or GB offset [28:16] */ +#define ISC_WB_G_LO GENMASK(12, 0)/* R or B gain [12:0] */ +#define ISC_WB_G_HI GENMASK(28, 16)/* GR or GB gain [28:16] */ +/* ISC Color Filter Array Control Register */ #define ISC_CFA_CTRL 0x00000070
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1361/2857 media: microchip-isc: synchronize the IRQ before disabling clocks on stop
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 19fa5407da5ef3e605cacfcd90f70d8b2c121cd7 ]
isc_stop_streaming() masks the DMA interrupt and then drops the runtime PM reference, which disables the ISC clocks. microchip_isc_interrupt() may still be executing on another CPU at that point; it reads ISC_INTSR over regmap, and touching the unclocked registers triggers an external abort.
Store the IRQ number at probe and call synchronize_irq() after masking the interrupt, before dropping the PM reference.
--- drivers/media/platform/atmel/atmel-isc-base.c | 3 +++ drivers/media/platform/atmel/atmel-isc.h | 1 + drivers/media/platform/atmel/atmel-sama5d2-isc.c | 2 ++ drivers/media/platform/atmel/atmel-sama7g5-isc.c | 2 ++ 4 files changed, 8 insertions(+)
drivers/media/platform/atmel/atmel-isc-base.c +3 -0
@@ -423,6 +423,9 @@ static void isc_stop_streaming(struct vb2_queue *vq)/* Disable DMA interrupt */ regmap_write (isc->regmap,ISC_INTDIS ,ISC_INT_DDONE ); +/* let a running IRQ handler finish before the clock is disabled */ +synchronize_irq (isc->irq); +pm_runtime_put_sync (isc->dev);/* Disable stream on the sub device */
drivers/media/platform/atmel/atmel-isc.h +1 -0
@@ -269,6 +269,7 @@ struct isc_device {u32 dcfg;struct device *dev; +int irq;struct v4l2_device v4l2_dev;struct video_device video_dev;
drivers/media/platform/atmel/atmel-sama5d2-isc.c +2 -0
@@ -430,6 +430,8 @@ static int atmel_isc_probe(struct platform_device *pdev)if (irq <0 )return irq; + isc->irq = irq; + ret =devm_request_irq (dev, irq, isc_interrupt,0 ,"atmel-sama5d2-isc" , isc);if (ret <0 ) {
drivers/media/platform/atmel/atmel-sama7g5-isc.c +2 -0
@@ -419,6 +419,8 @@ static int microchip_xisc_probe(struct platform_device *pdev)if (irq <0 )return irq; + isc->irq = irq; + ret =devm_request_irq (dev, irq, isc_interrupt,0 ,"microchip-sama7g5-xisc" , isc);if (ret <0 ) {
Signature · 1 line
2.53.0