6.1.193-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 374/2857 drm/amdkfd: Reject zero-sized AQL queue allocations after size halving
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sunday Clement <[email protected]>
[ Upstream commit 40ba09e11188d1b7f79d51fc28aca5ea45e0c138 ]
KFD_IOC_ALLOC_MEMORY_OF_GPU with flag KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM and size=1 triggers the AQL wraparound workaround (size >>= 1), reducing size to 0. The resulting zero passes through PAGE_ALIGN(0) = 0 without validation, bypassing the per-process VRAM quota check in reserve_mem_limit() (vram_used + 0 > vram_available is always false).
The fix adds post-halving zero-size validation in the primary allocation path (amdgpu_amdkfd_gpuvm.c). The check happens after size halving but before reserve_mem_limit(), and uses err_alignment_size error path to properly clean up the allocated kgd_mem structure and mutex.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 +++++++ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7 -0
@@ -1711,6 +1711,12 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( size >>=1 ; aligned_size =PAGE_ALIGN (size); +/* reject AQL queue with size < 2 */ +if (!aligned_size) { + ret = -EINVAL ; + goto err_alignment_size; + } + (*mem)->alloc_flags = flags;amdgpu_sync_create (&(*mem)->sync);
@@ -1784,6 +1790,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(amdgpu_amdkfd_unreserve_mem_limit (adev, aligned_size, flags); err_reserve_limit:amdgpu_sync_free (&(*mem)->sync); +err_alignment_size:mutex_destroy (&(*mem)->lock);if (gobj)drm_gem_object_put (gobj);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -1
@@ -1151,7 +1151,8 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,if (flags &KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM ) size >>=1 ; -WRITE_ONCE (pdd->vram_usage, pdd->vram_usage +PAGE_ALIGN (size)); + size =PAGE_ALIGN (size); +WRITE_ONCE (pdd->vram_usage, pdd->vram_usage + size); }mutex_unlock (&p->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/2857 i2c: qcom-cci: fix autosuspend cleanup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit f98d4986482151a835b521a734722fe8dc5ca37d ]
cci_probe() calls pm_runtime_use_autosuspend(), but the remove path does not call the matching pm_runtime_dont_use_autosuspend() before disabling runtime PM.
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without undoing the autosuspend setting during teardown, this reference is not dropped and usage_count remains unbalanced.
Use devm_pm_runtime_set_active_enabled() to manage the runtime PM state. Its managed cleanup disables autosuspend and runtime PM and restores the suspended state on probe failure and driver removal. Remove the now redundant manual runtime PM cleanup.
This issue was found by manual code inspection.
--- drivers/i2c/busses/i2c-qcom-cci.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +11 -6
@@ -640,9 +640,11 @@ static int cci_probe(struct platform_device *pdev) goto error;pm_runtime_set_autosuspend_delay (dev,MSEC_PER_SEC ); + ret =devm_pm_runtime_set_active_enabled (dev); +if (ret) + goto disable_clocks; +pm_runtime_use_autosuspend (dev); -pm_runtime_set_active (dev); -pm_runtime_enable (dev);for (i =0 ; i < cci->data->num_masters; i++) {if (!cci->master[i].cci)
@@ -658,8 +660,6 @@ static int cci_probe(struct platform_device *pdev)return 0 ; error_i2c: -pm_runtime_disable (dev); -pm_runtime_dont_use_autosuspend (dev);for (--i ; i >=0 ; i--) {if (cci->master[i].cci) {
@@ -667,6 +667,13 @@ static int cci_probe(struct platform_device *pdev)of_node_put (cci->master[i].adap.dev.of_node); } } + +disable_irq (cci->irq); +if (!IS_ENABLED (CONFIG_PM )) +cci_disable_clocks (cci); + +return ret; + error:disable_irq (cci->irq); disable_clocks:
@@ -689,8 +696,6 @@ static int cci_remove(struct platform_device *pdev) }disable_irq (cci->irq); -pm_runtime_disable (&pdev->dev); -pm_runtime_set_suspended (&pdev->dev);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/2857 lib/vsprintf: split out sprintf() and friends
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 39ced19b9e60f6f5b80db6b72965a8cf1982439d ]
Patch series "lib/vsprintf: Rework header inclusions", v3.
Some patches that reduce the mess with the header inclusions related to vsprintf.c module. Each patch has its own description, and has no dependencies to each other, except the collisions over modifications of the same places. Hence the series.
This patch (of 2):
kernel.h is being used as a dump for all kinds of stuff for a long time. sprintf() and friends are used in many drivers without need of the full kernel.h dependency train with it.
Here is the attempt on cleaning it up by splitting out sprintf() and friends.
Stable-dep-of: f0ea4824deeb ("iio: health: max30102: fix NULL dereference in interrupt handler")
--- include/linux/kernel.h | 30 +----------------------------- include/linux/sprintf.h | 25 +++++++++++++++++++++++++ lib/test_printf.c | 1 + lib/vsprintf.c | 1 + 4 files changed, 28 insertions(+), 29 deletions(-) create mode 100644 include/linux/sprintf.h
include/linux/kernel.h +1 -29
@@ -29,6 +29,7 @@#include <linux/panic.h> #include <linux/printk.h> #include <linux/build_bug.h> +#include <linux/sprintf.h> #include <linux/static_call_types.h> #include <linux/instruction_pointer.h> #include <asm/byteorder.h>
@@ -197,35 +198,6 @@ static inline void might_fault(void) { }void do_exit (long error_code)__noreturn ; -extern int num_to_str(char *buf, int size, - unsigned long long num, unsigned int width); - -/* lib/printf utilities */ - -extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...); -extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list); -extern __printf(3, 4) -int snprintf(char *buf, size_t size, const char *fmt, ...); -extern __printf(3, 0) -int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); -extern __printf(3, 4) -int scnprintf(char *buf, size_t size, const char *fmt, ...); -extern __printf(3, 0) -int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); -extern __printf(2, 3) __malloc -char *kasprintf(gfp_t gfp, const char *fmt, ...); -extern __printf(2, 0) __malloc -char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); -extern __printf(2, 0) -const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); - -extern __scanf(2, 3) -int sscanf(const char *, const char *, ...); -extern __scanf(2, 0) -int vsscanf(const char *, const char *, va_list); - -extern int no_hash_pointers_enable(char *str); -extern int get_option (char **str,int *pint);extern char *get_options (const char *str,int nints,int *ints);extern unsigned long long memparse (const char *ptr,char **retptr);
include/linux/sprintf.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_KERNEL_SPRINTF_H_ +#define _LINUX_KERNEL_SPRINTF_H_ + +#include <linux/compiler_attributes.h> +#include <linux/types.h> + +int num_to_str (char *buf,int size,unsigned long long num,unsigned int width); + +__printf(2, 3) int sprintf(char *buf, const char * fmt, ...); +__printf(2, 0) int vsprintf(char *buf, const char *, va_list); +__printf(3, 4) int snprintf(char *buf, size_t size, const char *fmt, ...); +__printf(3, 0) int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); +__printf(3, 4) int scnprintf(char *buf, size_t size, const char *fmt, ...); +__printf(3, 0) int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); +__printf(2, 3) __malloc char *kasprintf(gfp_t gfp, const char *fmt, ...); +__printf(2, 0) __malloc char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); +__printf(2, 0) const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); + +__scanf(2, 3) int sscanf(const char *, const char *, ...); +__scanf(2, 0) int vsscanf(const char *, const char *, va_list); + +int no_hash_pointers_enable (char *str); + +#endif /* _LINUX_KERNEL_SPRINTF_H */
lib/test_printf.c +1 -0
@@ -12,6 +12,7 @@#include <linux/random.h> #include <linux/rtc.h> #include <linux/slab.h> +#include <linux/sprintf.h> #include <linux/string.h> #include <linux/bitmap.h>
lib/vsprintf.c +1 -0
@@ -34,6 +34,7 @@#include <linux/dcache.h> #include <linux/cred.h> #include <linux/rtc.h> +#include <linux/sprintf.h> #include <linux/time.h> #include <linux/uuid.h> #include <linux/of.h>
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/2857 iio: core: Add iio_read_acpi_mount_matrix() helper function
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
[ Upstream commit 02eae0bb9538dc7dcb5a6bc2c3066bd6ca682969 ]
The ACPI "ROTM" rotation matrix parsing code atm is already duplicated between bmc150-accel-core.c and kxcjk-1013.c and a third user of this is coming.
Add an iio_read_acpi_mount_matrix() helper function for this. The 2 existing copies of the code are identical, except that the kxcjk-1013.c has slightly better error logging.
To new helper is a 1:1 copy of the kxcjk-1013.c version, the only change is the addition of a "char *acpi_method" parameter since some bmc150 dual-accel setups (360° hinges with 1 accel in kbd/base + 1 in display) declare both accels in a single ACPI device with 2 different method names for the 2 matrices. This new acpi_method parameter is not "const char *" because the pathname parameter to acpi_evaluate_object() is not const.
The 2 existing copies of this function will be removed in further patches in this series.
Stable-dep-of: f0ea4824deeb ("iio: health: max30102: fix NULL dereference in interrupt handler")
--- drivers/iio/Makefile | 1 + drivers/iio/industrialio-acpi.c | 85 +++++++++++++++++++++++++++++++++ include/linux/iio/iio.h | 13 +++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/iio/industrialio-acpi.c
drivers/iio/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o +industrialio-$(CONFIG_ACPI) += industrialio-acpi.o obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o obj-$(CONFIG_IIO_SW_DEVICE) += industrialio-sw-device.o
drivers/iio/industrialio-acpi.c new file +85 -0
85 lines not on this page · raw message
include/linux/iio/iio.h +13 -0
@@ -751,6 +751,19 @@ static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) }#endif +#ifdef CONFIG_ACPI +bool iio_read_acpi_mount_matrix (struct device *dev, +struct iio_mount_matrix *orientation, +char *acpi_method); +#else +static inline bool iio_read_acpi_mount_matrix (struct device *dev, +struct iio_mount_matrix *orientation, +char *acpi_method) +{ +return false; +} +#endif +ssize_t iio_format_value (char *buf,unsigned int type,int size,int *vals); int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/2857 iio: introduce struct iio_scan_type
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lechner <[email protected]>
[ Upstream commit fd7179ece035417f44f7ecff086d6df674d8a5bd ]
This gives the channel scan_type a named type so that it can be used to simplify code in later commits.
Stable-dep-of: f0ea4824deeb ("iio: health: max30102: fix NULL dereference in interrupt handler")
--- include/linux/iio/iio.h | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-)
include/linux/iio/iio.h +22 -19
@@ -172,6 +172,27 @@ struct iio_event_spec {unsigned long mask_shared_by_all; }; +/** +* struct iio_scan_type - specification for channel data format in buffer +* @sign: 's' or 'u' to specify signed or unsigned +* @realbits: Number of valid bits of data +* @storagebits: Realbits + padding +* @shift: Shift right by this before masking out realbits. +* @repeat: Number of times real/storage bits repeats. When the +* repeat element is more than 1, then the type element in +* sysfs will show a repeat value. Otherwise, the number +* of repetitions is omitted. +* @endianness: little or big endian +*/ +struct iio_scan_type { +char sign; +u8 realbits; +u8 storagebits; +u8 shift; +u8 repeat; +enum iio_endian endianness; +}; +/** * struct iio_chan_spec - specification of a single channel * @type: What type of measurement is the channel making.
@@ -183,17 +204,6 @@ struct iio_event_spec {* @scan_index: Monotonic index to give ordering in scans when read * from a buffer. * @scan_type: struct describing the scan type -* @scan_type.sign: 's' or 'u' to specify signed or unsigned -* @scan_type.realbits: Number of valid bits of data -* @scan_type.storagebits: Realbits + padding -* @scan_type.shift: Shift right by this before masking out -* realbits. -* @scan_type.repeat: Number of times real/storage bits repeats. -* When the repeat element is more than 1, then -* the type element in sysfs will show a repeat -* value. Otherwise, the number of repetitions -* is omitted. -* @scan_type.endianness: little or big endian * @info_mask_separate: What information is to be exported that is specific to * this channel. * @info_mask_separate_available: What availability information is to be
@@ -241,14 +251,7 @@ struct iio_chan_spec {int channel2;unsigned long address;int scan_index; -struct { -char sign; -u8 realbits; -u8 storagebits; -u8 shift; -u8 repeat; -enum iio_endian endianness; - } scan_type; +struct iio_scan_type scan_type;long info_mask_separate;long info_mask_separate_available;long info_mask_shared_by_type;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/2857 iio: buffer: use struct iio_scan_type to simplify code
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lechner <[email protected]>
[ Upstream commit 7758562898033a3bd98a24d2a541c930b0fc98e6 ]
By using struct iio_scan_type, we can simplify the code by removing lots of duplicate pointer dereferences. This make the code a bit easier to read.
This also prepares for a future where channels may have more than one scan_type.
Stable-dep-of: f0ea4824deeb ("iio: health: max30102: fix NULL dereference in interrupt handler")
--- drivers/iio/industrialio-buffer.c | 48 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-)
drivers/iio/industrialio-buffer.c +28 -20
@@ -367,7 +367,8 @@ static ssize_t iio_show_fixed_type(struct device *dev, char *buf) {struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); -u8 type = this_attr->c->scan_type.endianness; +const struct iio_scan_type *scan_type = &this_attr->c->scan_type; +u8 type = scan_type->endianness;if (type ==IIO_CPU ) {#ifdef __LITTLE_ENDIAN
@@ -376,21 +377,21 @@ static ssize_t iio_show_fixed_type(struct device *dev, type =IIO_BE ;#endif } -if (this_attr->c->scan_type.repeat >1 ) +if (scan_type->repeat >1 )return sysfs_emit (buf,"%s:%c%d/%dX%d>>%u\n" , iio_endian_prefix[type], - this_attr->c->scan_type.sign, - this_attr->c->scan_type.realbits, - this_attr->c->scan_type.storagebits, - this_attr->c->scan_type.repeat, - this_attr->c->scan_type.shift); + scan_type->sign, + scan_type->realbits, + scan_type->storagebits, + scan_type->repeat, + scan_type->shift);else return sysfs_emit (buf,"%s:%c%d/%d>>%u\n" , iio_endian_prefix[type], - this_attr->c->scan_type.sign, - this_attr->c->scan_type.realbits, - this_attr->c->scan_type.storagebits, - this_attr->c->scan_type.shift); + scan_type->sign, + scan_type->realbits, + scan_type->storagebits, + scan_type->shift); } static ssize_t iio_scan_el_show(struct device *dev,
@@ -686,12 +687,16 @@ static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev, unsigned int scan_index) {const struct iio_chan_spec *ch; +const struct iio_scan_type *scan_type;unsigned int bytes; ch =iio_find_channel_from_si (indio_dev, scan_index); - bytes = ch->scan_type.storagebits /8 ; -if (ch->scan_type.repeat >1 ) - bytes *= ch->scan_type.repeat; + scan_type = &ch->scan_type; + bytes = scan_type->storagebits /8 ; + +if (scan_type->repeat >1 ) + bytes *= scan_type->repeat; +return bytes; }
@@ -1623,18 +1628,21 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,if (channels) {/* new magic */ for (i =0 ; i < indio_dev->num_channels; i++) { +const struct iio_scan_type *scan_type; +if (channels[i].scan_index <0 )continue ; + scan_type = &channels[i].scan_type; +/* Verify that sample bits fit into storage */ -if (channels[i].scan_type.storagebits < - channels[i].scan_type.realbits + - channels[i].scan_type.shift) { +if (scan_type->storagebits < + scan_type->realbits + scan_type->shift) {dev_err (&indio_dev->dev,"Channel %d storagebits (%d) < shifted realbits (%d + %d)\n" , - i, channels[i].scan_type.storagebits, - channels[i].scan_type.realbits, - channels[i].scan_type.shift); + i, scan_type->storagebits, + scan_type->realbits, + scan_type->shift); ret = -EINVAL ; goto error_cleanup_dynamic; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/2857 iio: core: add accessors masklength
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuno Sa <[email protected]>
[ Upstream commit de79583ffe794663c53b77f97be814522d4edc4f ]
'masklength' is supposed to be an IIO private member. However, drivers (often in trigger handlers) need to access it to iterate over the enabled channels for example (there are other reasons). Hence, a couple of new accessors are being added:
* iio_for_each_active_channel() - Iterates over the active channels;
* iio_get_masklength() - Get length of the channels mask.
The goal of these new accessors is to annotate 'masklength' as private as soon as all drivers accessing it are converted to use the new helpers.
Stable-dep-of: f0ea4824deeb ("iio: health: max30102: fix NULL dereference in interrupt handler")
--- drivers/iio/health/max30102.c | 2 +- include/linux/iio/iio.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/iio/health/max30102.c +1 -1
@@ -293,7 +293,7 @@ static irqreturn_t max30102_interrupt_handler(int irq, void *private)struct iio_dev *indio_dev = private;struct max30102_data *data =iio_priv (indio_dev);unsigned int measurements =bitmap_weight (indio_dev->active_scan_mask, - indio_dev->masklength); +iio_get_masklength (indio_dev));int ret, cnt =0 ;mutex_lock (&data->lock);
include/linux/iio/iio.h +18 -0
@@ -767,6 +767,24 @@ static inline bool iio_read_acpi_mount_matrix(struct device *dev, }#endif +/** +* iio_get_masklength - Get length of the channels mask +* @indio_dev: the IIO device to get the masklength for +*/ +static inline unsigned int iio_get_masklength (const struct iio_dev *indio_dev) +{ +return indio_dev->masklength; +} + +/** +* iio_for_each_active_channel - Iterated over active channels +* @indio_dev: the IIO device +* @chan: Holds the index of the enabled channel +*/ +#define iio_for_each_active_channel (indio_dev, chan) \ + for_each_set_bit((chan), (indio_dev)->active_scan_mask, \ + iio_get_masklength(indio_dev)) +ssize_t iio_format_value (char *buf,unsigned int type,int size,int *vals); int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/2857 iio: health: max30102: fix NULL dereference in interrupt handler
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Chen <[email protected]>
[ Upstream commit f0ea4824deebf21dacfbe397c4b0a5fd3e745a8d ]
The interrupt is requested in max30102_probe() and stays enabled for the lifetime of the device, but indio_dev->active_scan_mask is only valid while a buffer is enabled. When an interrupt arrives while no buffer is enabled, the handler dereferences the NULL active_scan_mask:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 Call trace: __bitmap_weight+0x64/0x98 (P) max30102_interrupt_handler+0x48/0x160 [max30102]
Call max30102_fifo_count() at the top of the handler and return early unless it reports a FIFO sample is ready. Because FIFO_RDY is the only interrupt source enabled in max30102_chip_init(), an invocation of max30102_interrupt_handler() without the FIFO_RDY interrupt status bit set carries no data to read and can return before touching active_scan_mask. A negative return from max30102_fifo_count() indicates a failed interrupt status read and is treated the same way.
--- drivers/iio/health/max30102.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/iio/health/max30102.c +9 -3
@@ -292,9 +292,15 @@ static irqreturn_t max30102_interrupt_handler(int irq, void *private) {struct iio_dev *indio_dev = private;struct max30102_data *data =iio_priv (indio_dev); -unsigned int measurements =bitmap_weight (indio_dev->active_scan_mask, -iio_get_masklength (indio_dev)); -int ret, cnt =0 ; +unsigned int measurements; +int ret, cnt; + + cnt =max30102_fifo_count (data); +if (cnt <=0 ) +return IRQ_HANDLED ; + + measurements =bitmap_weight (indio_dev->active_scan_mask, +iio_get_masklength (indio_dev));mutex_lock (&data->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/2857 iio: admv1013: initialize callback mutex before registering notifier
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 baf7e43b7fb5afb777353bf265ddf9d909f72b9f ]
admv1013_probe() registers a clock notifier whose callback takes st->lock on POST_RATE_CHANGE. Initialize the mutex before devm_clk_notifier_register() so the callback cannot observe an uninitialized lock during probe.
Use devm_mutex_init() so the lock lifetime is tied to the device and cleanup stays paired with the rest of the managed probe resources.
--- drivers/iio/frequency/admv1013.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/frequency/admv1013.c +5 -2
@@ -613,11 +613,14 @@ static int admv1013_probe(struct spi_device *spi)return ret; st->nb.notifier_call = admv1013_freq_change; - ret =devm_clk_notifier_register (&spi->dev, st->clkin, &st->nb); + + ret =devm_mutex_init (&spi->dev, &st->lock);if (ret)return ret; -mutex_init (&st->lock); + ret =devm_clk_notifier_register (&spi->dev, st->clkin, &st->nb); +if (ret) +return ret; ret =admv1013_init (st);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/2857 reboot: fix cad_pid use-after-free race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit 5a88f78df753993469dab4d1831f8fb4256a9468 ]
cad_pid is a single kernel-wide struct pid pointer. proc_do_cad_pid() reads it and passes it to pid_vnr() without protecting the lifetime of the referenced struct pid. A concurrent writer can replace cad_pid and drop the final reference to the old struct pid after the reader has loaded the pointer but before pid_vnr() has finished dereferencing it, causing a use-after-free.
kill_cad_pid() has the same lifetime race when it passes cad_pid to kill_pid().
At the time this issue was reported, an unprivileged user could reach the sysctl through user and PID namespaces because cad_pid was registered in pid_table[]. Moving cad_pid back to the global reboot sysctl table corrected that namespace and permission mismatch, but did not fix the underlying lifetime race.
Fix this by treating cad_pid as an RCU-protected pointer at both read sites and by waiting for a grace period before dropping the old reference on the write side.
call_rcu(&old_pid->rcu, ...) cannot be used here because free_pid() also queues pid->rcu; queueing the same rcu_head twice can corrupt the RCU callback list.
Original KASAN crash stack:
kernel/pid.c:545 pid_nr_ns() # reads freed pid->level kernel/pid.c:556 pid_vnr() # calls pid_nr_ns() kernel/pid.c:775 proc_do_cad_pid() # calls pid_vnr(cad_pid)
--- include/linux/sched.h | 2 +- include/linux/sched/signal.h | 5 +---- init/main.c | 2 +- kernel/reboot.c | 5 +++-- kernel/signal.c | 12 ++++++++++++ kernel/sysctl.c | 13 +++++++++++-- 6 files changed, 29 insertions(+), 10 deletions(-)
include/linux/sched.h +1 -1
@@ -1724,7 +1724,7 @@ static inline int is_global_init(struct task_struct *tsk)return task_tgid_nr (tsk) ==1 ; } -extern struct pid *cad_pid; +extern struct pid __rcu *cad_pid;/* * Per process flags
include/linux/sched/signal.h +1 -4
@@ -591,10 +591,7 @@ static inline sigset_t *sigmask_to_save(void)return res; } -static inline int kill_cad_pid (int sig,int priv) -{ -return kill_pid (cad_pid, sig, priv); -} +int kill_cad_pid (int sig,int priv);/* These can be the second arg to send_sig_info/send_group_sig_info. */ #define SEND_SIG_NOINFO ((struct kernel_siginfo *) 0)
init/main.c +1 -1
@@ -1575,7 +1575,7 @@ static noinline void __init kernel_init_freeable(void)*/ set_mems_allowed (node_states[N_MEMORY ]); - cad_pid =get_pid (task_pid (current)); +rcu_assign_pointer (cad_pid,get_pid (task_pid (current)));smp_prepare_cpus (setup_max_cpus);
kernel/reboot.c +3 -2
@@ -13,7 +13,9 @@#include <linux/kexec.h> #include <linux/kmod.h> #include <linux/kmsg_dump.h> +#include <linux/rcupdate.h> #include <linux/reboot.h> +#include <linux/sched/signal.h> #include <linux/suspend.h> #include <linux/syscalls.h> #include <linux/syscore_ops.h>
@@ -24,8 +26,7 @@*/ static int C_A_D =1 ; -struct pid *cad_pid; -EXPORT_SYMBOL (cad_pid); +struct pid __rcu *cad_pid;#if defined(CONFIG_ARM )#define DEFAULT_REBOOT_MODE = REBOOT_HARD
kernel/signal.c +12 -0
@@ -1937,6 +1937,18 @@ int kill_pid(struct pid *pid, int sig, int priv) }EXPORT_SYMBOL (kill_pid); +int kill_cad_pid (int sig,int priv) +{ +int ret; + +rcu_read_lock (); + ret =kill_pid (rcu_dereference (cad_pid), sig, priv); +rcu_read_unlock (); + +return ret; +} +EXPORT_SYMBOL (kill_cad_pid); +/* * These functions support sending signals using preallocated sigqueue * structures. This is needed "because realtime applications cannot
kernel/sysctl.c +11 -2
@@ -1348,10 +1348,13 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { struct pid *new_pid; +struct pid *old_pid;pid_t tmp;int r; - tmp =pid_vnr (cad_pid); +rcu_read_lock (); + tmp =pid_vnr (rcu_dereference (cad_pid)); +rcu_read_unlock (); r =__do_proc_dointvec (&tmp, table, write, buffer, lenp, ppos,NULL ,NULL );
@@ -1362,7 +1365,13 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,if (!new_pid)return -ESRCH ; -put_pid (xchg (&cad_pid, new_pid)); + old_pid =unrcu_pointer (xchg (&cad_pid,RCU_INITIALIZER (new_pid))); +/* +* Wait for cad_pid readers before put_pid(). We cannot use +* call_rcu() here because free_pid() already owns pid->rcu. +*/ +synchronize_rcu (); +put_pid (old_pid);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/2857 smb: client: reject SetEA requests that do not fit the request buffer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunpeng Tian <[email protected]>
[ Upstream commit 4aa2c106aef4bf3dfd97c30842db0767b26e8428 ]
CIFSSMBSetEA() copies the caller's extended attribute value into the SMB request buffer without checking that it fits. The requirement is stated in the source but was never implemented:
/*BB add length check to see if it would fit in negotiated SMB buffer size BB */ /* if (ea_value_len > buffer_size - 512 (enough for header)) */ if (ea_value_len) memcpy(parm_data->list.name + name_len + 1, ea_value, ea_value_len);
The only bound applied on the way in is in cifs_xattr_set():
#define MAX_EA_VALUE_SIZE CIFSMaxBufSize ... if (size > MAX_EA_VALUE_SIZE)
CIFSMaxBufSize is the full payload capacity of the buffer, so a value of exactly that size leaves no room for the SMB header, the TRANS2 parameter block, the fealist header and the EA name that are written ahead of it in the same object.
SendReceive() already enforces the correct limit on this very length:
if (in_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE)
but it is called after the copy has taken place. An unprivileged setxattr(2) on an SMB1 mount with a 250-byte name and a 16384-byte value writes 16384 bytes starting 345 bytes into a 16588-byte cifs_request object, ending 141 bytes past it:
BUG: KASAN: slab-out-of-bounds in CIFSSMBSetEA+0xabc/0xde0 Write of size 16384 at addr ffff888003aa0159 by task init/68 __asan_memcpy+0x3c/0x60 CIFSSMBSetEA+0xabc/0xde0 cifs_xattr_set+0xd3a/0xff0 __vfs_setxattr+0x13e/0x1a0 The buggy address is located 345 bytes inside of allocated 16588-byte region
Apply SendReceive()'s limit to the assembled request before the copy rather than after it, and widen the byte counters so the sum cannot wrap before it is tested.
byte_count is also tested against U16_MAX, because it is stored in the 16-bit pSMB->ByteCount. That becomes reachable when CIFSMaxBufSize is raised at module load, where it may be set as high as 1024*127: with a 5-byte EA name and a 65521-byte value, count is exactly U16_MAX while byte_count is 65556, and cpu_to_le16() would truncate it to 20 and transmit a frame whose ByteCount does not match its length. Testing byte_count covers count as well, since byte_count is the larger of the two and count's only 16-bit consumer is written after this point.
check_add_overflow() is evaluated first so that total_len is assigned before it is reported.
--- fs/smb/client/cifssmb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/smb/client/cifssmb.c +12 -1
@@ -5799,8 +5799,11 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon,int name_len;int rc =0 ;int bytes_returned =0 ; -__u16 params, param_offset, byte_count, offset, count; +__u16 params, param_offset; +unsigned int byte_count, offset, count;int remap =cifs_remap (cifs_sb); +unsigned int total_len; +unsigned int in_len;cifs_dbg (FYI ,"In SetEA\n" ); SetEARetry:
@@ -5808,6 +5811,7 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, (void **) &pSMBr);if (rc)return rc; + in_len =get_rfc1002_length (pSMB);if (pSMB->hdr.Flags2 &SMBFLG2_UNICODE ) { name_len =
@@ -5851,6 +5855,13 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, pSMB->Reserved3 =0 ; pSMB->SubCommand =cpu_to_le16 (TRANS2_SET_PATH_INFORMATION ); byte_count =3 /* pad */ + params + count; +if (check_add_overflow (in_len, byte_count, &total_len) || + byte_count >U16_MAX || + total_len > CIFSMaxBufSize +MAX_CIFS_HDR_SIZE -4 ) { +cifs_dbg (VFS ,"EA request too large: %u bytes\n" , total_len); +cifs_buf_release (pSMB); +return -E2BIG ; + } pSMB->DataCount =cpu_to_le16 (count); parm_data->list_len =cpu_to_le32 (count); parm_data->list[0 ].EA_flags =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/2857 vsock/vmci: validate packet source for connected sockets
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 ad9a7da3fa39c2d616ec0dd3cf6e30531d032fe7 ]
vmci_transport_recv_stream_cb() looks up sockets first by the full source and destination tuple, then by destination only in the bound table. The fallback can select a non-listening socket without checking whether the packet came from its stored peer.
This was reproduced with two VMCI contexts. A RST from the context not stored in a TCP_SYN_SENT socket reset that socket after it was selected by the destination-only lookup.
VMCI can process notification packets in bottom-half context when the socket is not owned by user context, or defer packets to a workqueue. Use vsock_check_source() after taking the socket lock in the bottom-half path, and recheck after lock_sock() in the workqueue path. Listening sockets continue to accept packets from any source.
Reply with a RST addressed from the received packet before dropping a source that fails validation. This preserves the existing reset behavior for bound non-listening and concurrently closed sockets without directing the reset to a connected socket's stored peer.
--- net/vmw_vsock/vmci_transport.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
net/vmw_vsock/vmci_transport.c +28 -6
@@ -676,11 +676,13 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)struct vmci_transport_packet *pkt;struct vsock_sock *vsk;bool bh_process_pkt; +bool drop_pkt;int err; sk =NULL ; err =VMCI_SUCCESS ; bh_process_pkt = false; + drop_pkt = false;/* Ignore incoming packets from contexts without sockets, or resources * that aren't vsock implementations.
@@ -757,17 +759,29 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)bh_lock_sock (sk);if (!sock_owned_by_user (sk)) { -/* The local context ID may be out of date, update it. */ - vsk->local_addr.svm_cid = dst.svm_cid; +if (sk->sk_state !=TCP_LISTEN && + !vsock_check_source (vsk, &vmci_transport, &src)) { + drop_pkt = true; + err =VMCI_ERROR_NO_ACCESS ; + }else { +/* The local context ID may be out of date, update it. */ + vsk->local_addr.svm_cid = dst.svm_cid; -if (sk->sk_state ==TCP_ESTABLISHED ) -vmci_trans (vsk)->notify_ops->handle_notify_pkt ( - sk, pkt, true, &dst, &src, - &bh_process_pkt); +if (sk->sk_state ==TCP_ESTABLISHED ) +vmci_trans (vsk)->notify_ops->handle_notify_pkt (sk, pkt, true, + &dst, &src, + &bh_process_pkt); + } }bh_unlock_sock (sk); +if (drop_pkt) { +if (vmci_transport_send_reset_bh (&dst, &src, pkt) <0 ) +pr_err ("unable to send reset\n" ); + goto out; + } +if (!bh_process_pkt) {struct vmci_transport_recv_pkt_info *recv_pkt_info;
@@ -892,6 +906,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) {struct vmci_transport_recv_pkt_info *recv_pkt_info;struct vmci_transport_packet *pkt; +struct sockaddr_vm src;struct sock *sk; recv_pkt_info =
@@ -900,6 +915,12 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) pkt = &recv_pkt_info->pkt;lock_sock (sk); +vsock_addr_init (&src, pkt->dg.src.context, pkt->src_port); +if (sk->sk_state !=TCP_LISTEN && + !vsock_check_source (vsock_sk (sk), &vmci_transport, &src)) { +vmci_transport_reply_reset (pkt); + goto out; + }/* The local context ID may be out of date. */ vsock_sk (sk)->local_addr.svm_cid = pkt->dg.dst.context;
@@ -929,6 +950,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work)break ; } +out:release_sock (sk);kfree (recv_pkt_info);/* Release reference obtained in the stream callback when we fetched
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/2857 ipv6: Fix redirect exception creation for UDP/RAW sockets
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 cd51b74bdd0b75aedf255dc67306a16dd057f7ee ]
When an ICMP Redirect Message is matched to a socket, both IPv4 and IPv6 verify that the source IP of the ICMP packet is the current gateway for the quoted packet. Both also pass the socket's bound device as the expected nexthop device.
The difference is that IPv4 treats "oif=0" as "any", whereas IPv6 always requires an exact match (see ip6_redirect_nh_match()), since the gateway address is usually a link-local address.
Therefore, when an IPv6 UDP/RAW socket is not bound to a device, the above verification fails and an exception is not created. This also happens when the socket is bound to a VRF, as l3mdev_update_flow() resets the oif to 0.
Fix this by passing the ifindex of the ingress device as the expected nexthop device. This is consistent with the existing callers of ip6_redirect(). Note that for ICMPv6 Redirect Message packets the VRF driver does not reset skb->dev to the VRF device, so skb->dev is correct, even when it is a VRF port.
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -3223,7 +3223,7 @@ void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif)void ip6_sk_redirect (struct sk_buff *skb,struct sock *sk) { -ip6_redirect (skb,sock_net (sk), sk->sk_bound_dev_if, +ip6_redirect (skb,sock_net (sk), skb->dev->ifindex,READ_ONCE (sk->sk_mark), sk->sk_uid); }EXPORT_SYMBOL_GPL (ip6_sk_redirect);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/2857 ipv6: udp: Create exceptions before socket matching
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 ac76cab50e899a7346408b8d3c3a4192c2eefb9f ]
Currently, when ICMPv6 Packet Too Big and Redirect Message packets are locally delivered and quote a UDP packet, an exception is only created in the IPv6 exception cache if the kernel can match the UDP packet to an existing socket.
This behavior allows off-path attackers to conduct a side-channel attack on the exception cache in order to discover the ephemeral port used by a connected UDP socket.
Commit 4785305c05b2 ("ipv6: use siphash in rt6_exception_hash()") and commit a00df2caffed ("ipv6: make exception cache less predictible") tried to mitigate such attacks by making it harder for attackers to discover hash collisions in the exception cache and by randomizing the number of exceptions a hash bucket can hold, respectively. Unfortunately, both of the mitigations can be bypassed.
Instead, mitigate such attacks by always creating an exception, even before trying to find a matching socket. Do that by calling ip6_update_pmtu() and ip6_redirect(), the helpers used when the quoted packet did not originate from a socket.
This means that guesses (right or wrong) from an off-path attacker will always result in an exception being created or updated in the cache that the attacker can observe.
Pass the ifindex of the ingress device and the default uid, in a similar fashion to icmpv6_err(). Unlike IPv4, an oif of 0 would not match any nexthop in ip6_redirect_nh_match() and no exception would be created in response to a Redirect Message.
Note that this does not allow attackers to create exceptions that they could not create before, as both helpers can already be reached with little to no validation. For example, by sending an ICMPv6 error that quotes an ICMPv6 Echo Reply or one that quotes a UDP source port that matches a wildcard socket.
Also note that in the good case (matched socket) the above scheme comes at the cost of an extra route lookup, as the no socket helpers perform their own lookup before the one performed by ip6_sk_update_pmtu() / ip6_sk_redirect(). When the two resolve to different nexthops, it also results in two exceptions being created for the same destination IP. One in the exception cache of the nexthop resolved by the no socket helpers and another in the exception cache of the nexthop used by the socket.
--- net/ipv6/udp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
net/ipv6/udp.c +13 -0
@@ -633,6 +633,17 @@ static struct sock *__udp6_lib_err_encap(struct net *net,return sk; } +static void udpv6_err_update_exception (struct net *net,struct sk_buff *skb, +u8 type,__be32 info) +{ +if (type ==ICMPV6_PKT_TOOBIG ) +ip6_update_pmtu (skb, net, info, skb->dev->ifindex,0 , +sock_net_uid (net,NULL )); +else if (type ==NDISC_REDIRECT ) +ip6_redirect (skb, net, skb->dev->ifindex,0 , +sock_net_uid (net,NULL )); +} +int __udp6_lib_err (struct sk_buff *skb,struct inet6_skb_parm *opt,u8 type,u8 code,int offset,__be32 info,struct udp_table *udptable)
@@ -648,6 +659,8 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,int err;struct net *net =dev_net (skb->dev); +udpv6_err_update_exception (net, skb, type, info); + sk =__udp6_lib_lookup (net, daddr, uh->dest, saddr, uh->source,inet6_iif (skb),inet6_sdif (skb), udptable,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/2857 xfrm: save input state data before secpath resets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 3cf5cdecd99c9c186a5ea518d93bbf3045b6e3aa ]
xfrm_input() stores the current xfrm_state in the skb secpath while it continues receive-side processing. Some input paths can reset that secpath before xfrm_input() has finished dereferencing the state.
Receive callback users such as VTI and XFRM interfaces can reset the secpath. The VTI receive path does so before checking whether the packet crosses network namespaces, while the XFRM interface path does so only for cross-network-namespace packets. The XFRM_MAX_DEPTH error path can also reset the secpath before the final drop callback reports the current state's protocol.
If secpath_reset() drops the last state reference while the state is concurrently deleted, xfrm_input() can still dereference the freed state when selecting transport_finish() or reporting the drop callback protocol.
Save the state protocol on the stack while the state is still valid, and use the already saved address family for transport_finish(). A larval XFRM_STATE_ACQ state has no type, so retain nexthdr as its protocol. This preserves the existing drop-path fallback while avoiding the post-reset state dereferences without adding an extra state reference to every received packet.
--- net/xfrm/xfrm_input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/xfrm/xfrm_input.c +7 -3
@@ -462,6 +462,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)struct xfrm_state *x =NULL ;xfrm_address_t *daddr;u32 mark = skb->mark; +u8 xfrm_proto = nexthdr;unsigned int family =AF_UNSPEC ;int decaps =0 ;int async =0 ;
@@ -472,6 +473,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (encap_type <0 || (xo && (xo->flags &XFRM_GRO || encap_type ==0 ))) { x =xfrm_input_state (skb); + xfrm_proto = x->type ? x->type->proto : nexthdr;if (unlikely (x->km.state !=XFRM_STATE_VALID )) {if (x->km.state ==XFRM_STATE_ACQ )
@@ -572,11 +574,13 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) x =xfrm_state_lookup (net, mark, daddr, spi, nexthdr, family);if (x ==NULL ) { + xfrm_proto = nexthdr;secpath_reset (skb);XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOSTATES );xfrm_audit_state_notfound (skb, family, spi, seq); goto drop; } + xfrm_proto = x->type ? x->type->proto : nexthdr; skb->mark =xfrm_smark_get (skb->mark, x);
@@ -695,7 +699,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) crypto_done = false; }while (!err); - err =xfrm_rcv_cb (skb, family, x->type->proto,0 ); + err =xfrm_rcv_cb (skb, family, xfrm_proto,0 );if (err) goto drop;
@@ -718,7 +722,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) err = -EAFNOSUPPORT ;rcu_read_lock (); - afinfo =xfrm_state_afinfo_get_rcu (x->props.family); + afinfo =xfrm_state_afinfo_get_rcu (family);if (likely (afinfo)) err = afinfo->transport_finish (skb, xfrm_gro || async);rcu_read_unlock ();
@@ -742,7 +746,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) drop:if (async)dev_put (skb->dev); -xfrm_rcv_cb (skb, family, x && x->type ? x->type->proto : nexthdr,-1 ); +xfrm_rcv_cb (skb, family, xfrm_proto,-1 );kfree_skb (skb);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/2857 IB/hfi1: Use dma_mmap_coherent for matching buffers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dean Luick <[email protected]>
[ Upstream commit 1ec82317a1daac78c04b0c15af89018ccf9fa2b7 ]
For memory allocated with dma_alloc_coherent(), use dma_mmap_coherent() to mmap it into user space.
Stable-dep-of: 975396b9e5a4 ("IB/hfi1: Resolve the credit-return buffer through the send context's node")
--- drivers/infiniband/hw/hfi1/file_ops.c | 81 +++++++++++++++++++-------- 1 file changed, 57 insertions(+), 24 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +57 -24
@@ -306,6 +306,17 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from)return reqs; } +static inline void mmap_cdbg (u16 ctxt,u8 subctxt,u8 type,u8 mapio,u8 vmf, +u64 memaddr,void *memvirt,dma_addr_t memdma, +ssize_t memlen,struct vm_area_struct *vma) +{ +hfi1_cdbg (PROC , +"%u:%u type:%u io/vf/dma:%d/%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx" , + ctxt, subctxt, type, mapio, vmf, !!memdma, + memaddr ?: (u64 )memvirt, memlen, + vma->vm_end - vma->vm_start, vma->vm_flags); +} +static int hfi1_file_mmap (struct file *fp,struct vm_area_struct *vma) {struct hfi1_filedata *fd = fp->private_data;
@@ -315,6 +326,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)u64 token = vma->vm_pgoff <<PAGE_SHIFT , memaddr =0 ;void *memvirt =NULL ; +dma_addr_t memdma =0 ;u8 subctxt, mapio =0 , vmf =0 , type;ssize_t memlen =0 ;int ret =0 ;
@@ -334,6 +346,11 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) goto done; } +/* +* vm_pgoff is used as a buffer selector cookie. Always mmap from +* the beginning. +*/ + vma->vm_pgoff =0 ; flags = vma->vm_flags;switch (type) {
@@ -355,7 +372,8 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); mapio =1 ;break ; -case PIO_CRED : +case PIO_CRED : { +u64 cr_page_offset;if (flags &VM_WRITE ) { ret = -EPERM ; goto done;
@@ -365,10 +383,11 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* second or third page allocated for credit returns (if number * of enabled contexts > 64 and 128 respectively). */ - memvirt = dd->cr_base[uctxt->numa_id].va; - memaddr =virt_to_phys (memvirt) + - (((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) &PAGE_MASK ); + cr_page_offset = ((u64 )uctxt->sc->hw_free - + (u64 )dd->cr_base[uctxt->numa_id].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; + memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
@@ -378,14 +397,16 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* memory been flagged as non-cached? */ /* vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); */ - mapio =1 ;break ; + }case RCV_HDRQ : memlen =rcvhdrq_size (uctxt); memvirt = uctxt->rcvhdrq; + memdma = uctxt->rcvhdrq_dma;break ;case RCV_EGRBUF : { -unsigned long addr; +unsigned long vm_start_save; +unsigned long vm_end_save;int i;/* * The RcvEgr buffer need to be handled differently
@@ -404,24 +425,34 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) goto done; } vma->vm_flags &= ~VM_MAYWRITE ; - addr = vma->vm_start; +/* +* Mmap multiple separate allocations into a single vma. From +* here, dma_mmap_coherent() calls dma_direct_mmap(), which +* requires the mmap to exactly fill the vma starting at +* vma_start. Adjust the vma start and end for each eager +* buffer segment mapped. Restore the originals when done. +*/ + vm_start_save = vma->vm_start; + vm_end_save = vma->vm_end; + vma->vm_end = vma->vm_start;for (i =0 ; i < uctxt->egrbufs.numbufs; i++) { memlen = uctxt->egrbufs.buffers[i].len; memvirt = uctxt->egrbufs.buffers[i].addr; - ret =remap_pfn_range ( - vma, addr, -/* -* virt_to_pfn() does the same, but -* it's not available on x86_64 -* when CONFIG_MMU is enabled. -*/ -PFN_DOWN (__pa (memvirt)), - memlen, - vma->vm_page_prot); -if (ret <0 ) + memdma = uctxt->egrbufs.buffers[i].dma; + vma->vm_end += memlen; +mmap_cdbg (ctxt, subctxt, type, mapio, vmf, memaddr, + memvirt, memdma, memlen, vma); + ret =dma_mmap_coherent (&dd->pcidev->dev, vma, + memvirt, memdma, memlen); +if (ret <0 ) { + vma->vm_start = vm_start_save; + vma->vm_end = vm_end_save; goto done; - addr += memlen; + } + vma->vm_start += memlen; } + vma->vm_start = vm_start_save; + vma->vm_end = vm_end_save; ret =0 ; goto done; }
@@ -481,6 +512,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) } memlen =PAGE_SIZE ; memvirt = (void *)hfi1_rcvhdrtail_kvaddr (uctxt); + memdma = uctxt->rcvhdrqtailaddr_dma; flags &= ~VM_MAYWRITE ;break ;case SUBCTXT_UREGS :
@@ -529,14 +561,15 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) } vma->vm_flags = flags; -hfi1_cdbg (PROC , -"%u:%u type:%u io/vf:%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx\n" , - ctxt, subctxt, type, mapio, vmf, memaddr, memlen, - vma->vm_end - vma->vm_start, vma->vm_flags); +mmap_cdbg (ctxt, subctxt, type, mapio, vmf, memaddr, memvirt, memdma, + memlen, vma);if (vmf) { vma->vm_pgoff =PFN_DOWN (memaddr); vma->vm_ops = &vm_ops; ret =0 ; + }else if (memdma) { + ret =dma_mmap_coherent (&dd->pcidev->dev, vma, + memvirt, memdma, memlen); }else if (mapio) { ret = io_remap_pfn_range(vma, vma->vm_start, PFN_DOWN(memaddr),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/2857 IB/hfi1: Resolve the credit-return buffer through the send contexts node
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
[ Upstream commit 975396b9e5a4028e649f4b9a6a5ca5dfb76a824b ]
hfi1_file_mmap()'s PIO_CRED case derives this context's credit-return page offset, and the DMA handle for it, from dd->cr_base[uctxt->numa_id]. uctxt->numa_id is the node of whichever CPU the process happened to be running on, but the entry itself lives in the credit-return allocation of the send context's own node:
sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index];
and user send contexts are allocated with sc_alloc(dd, SC_USER, ..., dd->node), the HFI-local node. On a multi-socket host with the process running off that node the two allocations differ, so the subtraction produces an offset into an unrelated buffer and the DMA handle belongs to the wrong allocation.
Use the send context's own node for all three references. The continuation lines are reindented at the same time; they mixed spaces and tabs.
--- drivers/infiniband/hw/hfi1/file_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +4 -4
@@ -384,10 +384,10 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* of enabled contexts > 64 and 128 respectively). */ cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) & -PAGE_MASK ; - memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; - memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; + (u64 )dd->cr_base[uctxt->sc->node].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; + memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/2857 IB/hfi1: Fix the PIO_CRED credit-return mmap
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
[ Upstream commit 62f0f34fbd2b2d5653d33d3b9d42fdcabb1c0101 ]
hfi1_file_mmap()'s PIO_CRED case must hand user space the single credit-return page that holds this context's entry. That page is the second or third page of the per-node credit-return allocation once the hardware send context index reaches 64 or 128, so the failure below is
intermittent: when the entry lands on the first page the offset is zero and everything works.
Two things are wrong.
First, cr_page_offset is a byte offset but .va is a struct credit_return *, so adding it is pointer arithmetic and scales the offset by sizeof(struct credit_return) == 64. memvirt then lands 256 KiB or 512 KiB past a 10240-byte allocation. With an IOMMU translating, that address is inside the vmalloc range but in no vm_area, so dma_mmap_coherent() -> iommu_dma_mmap() finds no pages, vmalloc_to_pfn() returns page_to_pfn(NULL), and remap_pfn_range() installs a frame above MAXPHYADDR. The first user read then takes:
psm2_ep_open_pr: Corrupted page table at address 7a14d007e000 PGD 800000013886a067 P4D 800000013886a067 PUD 13886b067 PMD 13886c067
PTE 800049168e911235 Oops: Bad pagetable: 000d [#1] SMP PTI
Second, and still wrong once the arithmetic is corrected, dma_mmap_coherent() describes a whole coherent buffer and selects the page within it with vma->vm_pgoff. Offsetting cpu_addr has no effect:
for a vmap'd allocation iommu_dma_mmap() uses cpu_addr only to locate the vm_area and then maps pages[vm_pgoff], which hfi1_file_mmap() has just set to 0. User space therefore always receives the first credit-return page, every credit read is for the wrong context, and send PIO stalls forever.
Use the DMA API as intended: pass the base of the allocation with its full length and select the page with vm_pgoff. A separate length is needed because memlen must keep describing the VMA for the existing size check. The dma-direct path stays correct as well, since dma_direct_mmap() adds the same vm_pgoff to the base pfn.
Tested on a Dell T7610 (Xeon E5-2650 v2, Intel IOMMU in DMA-FQ mode) against a Threadripper PRO 3995WX peer, both Omni-Path 100. Before this change psm2_ep_open() Oopses the kernel; with only the arithmetic corrected psm2_ep_open() succeeds but any transfer that uses send PIO hangs, PSM2_SDMA=2 (send PIO disabled) completing normally while PSM2_SDMA=0 (send PIO only) hangs every time. With this change send PIO, send DMA and the default mixed mode all work.
--- drivers/infiniband/hw/hfi1/file_ops.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +16 -5
@@ -328,6 +328,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)void *memvirt =NULL ;dma_addr_t memdma =0 ;u8 subctxt, mapio =0 , vmf =0 , type; +size_t memdmalen =0 ;ssize_t memlen =0 ;int ret =0 ;u16 ctxt;
@@ -373,7 +374,9 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) mapio =1 ;break ;case PIO_CRED : { +struct credit_return_base *cr = &dd->cr_base[uctxt->sc->node];u64 cr_page_offset; +if (flags &VM_WRITE ) { ret = -EPERM ; goto done;
@@ -383,11 +386,18 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* second or third page allocated for credit returns (if number * of enabled contexts > 64 and 128 respectively). */ - cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->sc->node].va) & + cr_page_offset = ((u64 )uctxt->sc->hw_free - (u64 )cr->va) &PAGE_MASK ; - memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; - memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; +/* +* dma_mmap_coherent() describes the whole coherent buffer and +* selects the page within it with vma->vm_pgoff, so pass the +* base of the allocation and its length and let vm_pgoff pick +* the page. +*/ + vma->vm_pgoff = cr_page_offset >>PAGE_SHIFT ; + memvirt = cr->va; + memdma = cr->dma; + memdmalen =TXE_NUM_CONTEXTS *sizeof (struct credit_return ); memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
@@ -569,7 +579,8 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) ret =0 ; }else if (memdma) { ret =dma_mmap_coherent (&dd->pcidev->dev, vma, - memvirt, memdma, memlen); + memvirt, memdma, + memdmalen ? memdmalen : memlen); }else if (mapio) { ret = io_remap_pfn_range(vma, vma->vm_start, PFN_DOWN(memaddr),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/2857 usb: cdnsp: fix wakeup from S3 after controller context loss
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pawel Laszczak <[email protected]>
[ Upstream commit eae6460f617382044c5afe5ef202f4d8b2c099b5 ]
CDNSP controller may lose its runtime register programming across S3 suspend/resume, depending on SoC power domain configuration. After resume the operational and interrupter registers may contain reset values, which prevents the gadget side from recovering correctly and breaks wakeup from S3.
Fix this by detecting whether the controller lost its register context after resume and handling both cases:
- If context was lost (CFG_3XPORT_U1_PIPE_CLK_GATE_EN set or power lost): reset the controller and reprogram the state required for normal operation, including the command ring, DCBAA pointer, doorbell base, event ring, ERST base/size and event ring dequeue pointer.
- If context was retained: restart the controller directly without reprogramming registers. Issue a wakeup if the link was in U3 before suspend.
Move the basic controller register programming out of the one-time memory initialization path and make it reusable from the resume path. Also separate ring allocation from ring initialization so that rings can be reinitialized without reallocating DMA memory.
Always perform the full suspend sequence regardless of the current link state. Previously, if the device was already in U3, the suspend callback returned early without stopping the controller, which could lead to commands being issued on a disabled slot during resume.
--- drivers/usb/cdns3/cdnsp-gadget.c | 111 +++++++++++++++++++++++++++++-- drivers/usb/cdns3/cdnsp-gadget.h | 1 + drivers/usb/cdns3/cdnsp-mem.c | 98 ++++++++++----------------- 3 files changed, 143 insertions(+), 67 deletions(-)
drivers/usb/cdns3/cdnsp-gadget.c +107 -4
@@ -1819,6 +1819,82 @@ static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) readl(&pdev->rev_cap->tx_buff_size)); } +static void cdnsp_set_event_deq (struct cdnsp_device *pdev) +{ +dma_addr_t deq; +u64 temp; + + deq =cdnsp_trb_virt_to_dma (pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + +/* Update controller event ring dequeue pointer */ + temp =cdnsp_read_64 (&pdev->ir_set->erst_dequeue); + temp &=ERST_PTR_MASK ; + +/* +* Don't clear the EHB bit (which is RW1C) because +* there might be more events to service. +*/ + temp &= ~ERST_EHB ; + +cdnsp_write_64 (((u64 )deq & (u64 )~ERST_PTR_MASK ) | temp, + &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_add_interrupter (struct cdnsp_device *pdev) +{ +u64 erst_base; +u32 erst_size; + +/* Set ERST count with the number of entries in the segment table. */ + erst_size =readl (&pdev->ir_set->erst_size); + erst_size &=ERST_SIZE_MASK ; + erst_size |=ERST_NUM_SEGS ; +writel (erst_size, &pdev->ir_set->erst_size); + +/* Set the segment table base address. */ + erst_base =cdnsp_read_64 (&pdev->ir_set->erst_base); + erst_base &=ERST_PTR_MASK ; + erst_base |= (pdev->erst.erst_dma_addr & (u64 )~ERST_PTR_MASK ); +cdnsp_write_64 (erst_base, &pdev->ir_set->erst_base); + +/* Set the event ring dequeue address. */ +cdnsp_set_event_deq (pdev); +} + +/* Set up basic CDNSP registers */ +static void cdnsp_init (struct cdnsp_device *pdev) +{ +unsigned int val; +u64 val_64; + + val =readl (&pdev->op_regs->config_reg); + val |= ((val & ~MAX_DEVS ) |CDNSP_DEV_MAX_SLOTS ) |CONFIG_U3E ; +writel (val, &pdev->op_regs->config_reg); + +/* Initialize the Command ring */ +cdnsp_ring_init (pdev, pdev->cmd_ring); + +/* Set the address in the Command Ring Control register */ + val_64 =cdnsp_read_64 (&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64 )CMD_RING_RSVD_BITS ) | + (pdev->cmd_ring->first_seg->dma & (u64 )~CMD_RING_RSVD_BITS ) | + pdev->cmd_ring->cycle_state; +cdnsp_write_64 (val_64, &pdev->op_regs->cmd_ring); + +/* Set Device Context Base Address Array pointer */ +cdnsp_write_64 (pdev->dcbaa->dma, &pdev->op_regs->dcbaa_ptr); + +/* Set Doorbell array pointer */ + val =readl (&pdev->cap_regs->db_off); + val &=DBOFF_MASK ; + pdev->dba = (void __iomem *)pdev->cap_regs + val; + +/* Initialize the Primary interrupter */ +cdnsp_ring_init (pdev, pdev->event_ring); +cdnsp_add_interrupter (pdev); +} +static int cdnsp_gen_setup (struct cdnsp_device *pdev) {int ret;
@@ -1884,6 +1960,8 @@ static int cdnsp_gen_setup(struct cdnsp_device *pdev)if (ret)return ret; +cdnsp_init (pdev); +/* * Software workaround for U1: after transition * to U1 the controller starts gating clock, and in some cases,
@@ -2014,9 +2092,6 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup)struct cdnsp_device *pdev = cdns->gadget_dev;unsigned long flags; -if (pdev->link_state ==XDEV_U3 ) -return 0 ; -spin_lock_irqsave (&pdev->lock, flags);cdnsp_disconnect_gadget (pdev);cdnsp_stop (pdev);
@@ -2030,12 +2105,38 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated)struct cdnsp_device *pdev = cdns->gadget_dev;enum usb_device_speed max_speed;unsigned long flags; +bool context_lost; +u32 val;int ret;if (!pdev->gadget_driver)return 0 ;spin_lock_irqsave (&pdev->lock, flags); + val =readl (&pdev->port3x_regs->mode_2); + context_lost = !!(val &CFG_3XPORT_U1_PIPE_CLK_GATE_EN ) || hibernated; + +if (context_lost) { +cdnsp_halt (pdev); +cdnsp_set_apb_timeout_value (pdev); + +/* Reset the internal controller memory state and registers. */ + ret =cdnsp_reset (pdev); +if (ret) + goto unlock; + + val =readl (&pdev->port3x_regs->mode_2); + val &= ~CFG_3XPORT_U1_PIPE_CLK_GATE_EN ; +writel (val, &pdev->port3x_regs->mode_2); + +cdnsp_clear_cmd_ring (pdev); + +memset (pdev->event_ring->first_seg->trbs,0 , +sizeof (union cdnsp_trb ) * (TRBS_PER_SEGMENT )); + +cdnsp_init (pdev); + } + max_speed = pdev->gadget_driver->max_speed;/* Limit speed if necessary. */
@@ -2043,9 +2144,11 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated) ret =cdnsp_run (pdev, max_speed); -if (pdev->link_state ==XDEV_U3 ) +if (!context_lost && pdev->active_port && + pdev->link_state ==XDEV_U3 )__cdnsp_gadget_wakeup (pdev); +unlock:spin_unlock_irqrestore (&pdev->lock, flags);return ret;
drivers/usb/cdns3/cdnsp-gadget.h +1 -0
@@ -1509,6 +1509,7 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,int cdnsp_ring_expansion (struct cdnsp_device *pdev,struct cdnsp_ring *ring,unsigned int num_trbs,gfp_t flags); +void cdnsp_ring_init (struct cdnsp_device *pdev,struct cdnsp_ring *ring);struct cdnsp_ring *cdnsp_dma_to_transfer_ring (struct cdnsp_ep *ep,u64 address); int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, struct cdnsp_ep *pep,
drivers/usb/cdns3/cdnsp-mem.c +35 -63
166 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/2857 ublk: clear VM_MAYWRITE on read-only ublk char device mmap
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kanishka De Silva <[email protected]>
[ Upstream commit 6e2b571b0a54755b06e092501913e1dfefe75d6c ]
ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.
The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.
Same bug class as the drm/panthor and drm/vc4 VM_MAYWRITE fixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).
Verified via mprotect() PoC: before the fix, a PROT_READ mapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corrupts io_desc fields (confirmed under KASAN). After the fix, mprotect() returns -EACCES.
--- drivers/block/ublk_drv.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/block/ublk_drv.c +6 -0
@@ -980,6 +980,12 @@ static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)if (vma->vm_flags &VM_WRITE )return -EPERM ; +/* +* The per-queue command buffer is kernel-written ABI; prevent +* the daemon from upgrading to writable via mprotect(). +*/ + vma->vm_flags &= ~VM_MAYWRITE ; + end =UBLKSRV_CMD_BUF_OFFSET + ub->dev_info.nr_hw_queues * max_sz;if (phys_off <UBLKSRV_CMD_BUF_OFFSET || phys_off >= end)return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/2857 memcg: make the v1 soft limit knob inert
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
[ Upstream commit a3417097fb107cea3358b19bcbb4eb655fd67f8c ]
The v1 soft limit has been deprecated since v6.12 and nobody has reported depending on it. Start the removal by decoupling the interface from the
implementation: keep memory.soft_limit_in_bytes, but ignore writes to it and always report the maximum value on read similar to what memory.kmem.limit_in_bytes already does.
Writes are still parsed, so malformed input keeps returning -EINVAL. The knob now also behaves the same everywhere: it used to return -EOPNOTSUPP on PREEMPT_RT, where soft limit reclaim has always been disabled.
This also fixes the syzbot report linked below. Soft limit reclaim is the only caller that runs shrink_lruvec() from kswapd against a specific memcg, so it is the only way to reach lru_gen_shrink_lruvec() and in turn set_mm_walk(), which warns when called from kswapd.
--- .../admin-guide/cgroup-v1/memory.rst | 46 +++---------------- mm/memcontrol.c | 40 ++++++++++------ 2 files changed, 32 insertions(+), 54 deletions(-)
Documentation/admin-guide/cgroup-v1/memory.rst +6 -40
@@ -47,7 +47,6 @@ Features: - pages are linked to per-memcg LRU exclusively, and there is no global LRU. - optionally, memory+swap usage can be accounted and limited. - hierarchical accounting - - soft limit - moving (recharging) account at moving a task is selectable. - usage threshold notifier - memory pressure notifier
@@ -75,8 +74,9 @@ Brief summary of control files. memory.memsw.failcnt show the number of memory+Swap hits limits memory.max_usage_in_bytes show max memory usage recorded memory.memsw.max_usage_in_bytes show max memory+Swap usage recorded - memory.soft_limit_in_bytes set/show soft limit of memory usage - This knob is not available on CONFIG_PREEMPT_RT systems. + memory.soft_limit_in_bytes This knob is deprecated and has no effect. + Writes are ignored and reads always + return the maximum value. memory.stat show various statistics memory.use_hierarchy set/show hierarchical account enabled This knob is deprecated and shouldn't be
@@ -326,9 +326,6 @@ memory.kmem.usage_in_bytes, or in a separate counter when it makes sense. The main "kmem" counter is fed into the main counter, so kmem charges will also be visible from the user counter. -Currently no soft limit is implemented for kernel memory. It is future work -to trigger slab reclaim when those limits are reached. - 2.7.1 Current Kernel Memory resources accounted -----------------------------------------------
@@ -687,41 +684,10 @@ For compatibility reasons writing 1 to memory.use_hierarchy will always pass:: 7. Soft limits ============== -Soft limits allow for greater sharing of memory. The idea behind soft limits -is to allow control groups to use as much of the memory as needed, provided - -a. There is no memory contention -b. They do not exceed their hard limit - -When the system detects memory contention or low memory, control groups -are pushed back to their soft limits. If the soft limit of each control -group is very high, they are pushed back as much as possible to make -sure that one control group does not starve the others of memory. - -Please note that soft limits is a best-effort feature; it comes with -no guarantees, but it does its best to make sure that when memory is -heavily contended for, memory is allocated based on the soft limit -hints/setup. Currently soft limit based reclaim is set up such that -it gets invoked from balance_pgdat (kswapd). - -7.1 Interface -------------- - -Soft limits can be setup by using the following commands (in this example we -assume a soft limit of 256 MiB):: - - # echo 256M > memory.soft_limit_in_bytes - -If we want to change this to 1G, we can at any time use:: - - # echo 1G > memory.soft_limit_in_bytes +Writing to memory.soft_limit_in_bytes has no effect and reading it will +always return the maximum value. -NOTE1: - Soft limits take effect over a long period of time, since they involve - reclaiming memory for balancing between memory cgroups -NOTE2: - It is recommended to set the soft limit always below the hard limit, - otherwise the hard limit will take precedence. +Use memory.low and memory.min in cgroup v2 instead. 8. Move charges at task migration (DEPRECATED!) ===============================================
mm/memcontrol.c +26 -14
@@ -3689,9 +3689,32 @@ enum {RES_LIMIT ,RES_MAX_USAGE , RES_FAILCNT, - RES_SOFT_LIMIT, }; +static u64 mem_cgroup_soft_limit_read (struct cgroup_subsys_state *css, +struct cftype *cft) +{ +return (u64 )PAGE_COUNTER_MAX *PAGE_SIZE ; +} + +static ssize_t mem_cgroup_soft_limit_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +unsigned long nr_pages; +int ret; + + ret =page_counter_memparse (strstrip (buf),"-1" , &nr_pages); +if (ret) +return ret; + +pr_warn_once ("soft_limit_in_bytes is deprecated and will be removed. " +"Writing any value to this file has no effect. " +"Please report your usecase to [email protected] if you " +"depend on this functionality.\n" ); + +return nbytes; +} +static u64 mem_cgroup_read_u64 (struct cgroup_subsys_state *css,struct cftype *cft) {
@@ -3728,8 +3751,6 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,return (u64 )counter->watermark *PAGE_SIZE ;case RES_FAILCNT :return counter->failcnt; -case RES_SOFT_LIMIT : -return (u64 )memcg->soft_limit *PAGE_SIZE ;default :BUG (); }
@@ -3870,14 +3891,6 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,break ; }break ; -case RES_SOFT_LIMIT : -if (IS_ENABLED (CONFIG_PREEMPT_RT )) { - ret = -EOPNOTSUPP ; - }else { - memcg->soft_limit = nr_pages; - ret =0 ; - } -break ; }return ret ?: nbytes; }
@@ -5026,9 +5039,8 @@ static struct cftype mem_cgroup_legacy_files[] = { }, { .name = "soft_limit_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT), - .write = mem_cgroup_write, - .read_u64 = mem_cgroup_read_u64, + .write = mem_cgroup_soft_limit_write, + .read_u64 = mem_cgroup_soft_limit_read, }, { .name = "failcnt",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/2857 ALSA: rawmidi: Return the error from snd_rawmidi_input_params()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit f4a23e17d84fd2a152d9e12369761934e1af0ee8 ]
The snd_rawmidi_input_params() computes err for the three invalid mode combinations and for resize_runtime_buffer(), applies the new framing and clock type only when err is zero, and then returns 0 anyway. A caller that asked for parameters the kernel rejected is told the change succeeded, and the substream keeps its old buffer.
The open_mutex conversion turned the early returns into assignments. It handled the output sibling correctly, which still returns err, and left this one behind.
--- sound/core/rawmidi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/rawmidi.c +1 -1
@@ -793,7 +793,7 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, substream->clock_type = clock_type; }mutex_unlock (&substream->rmidi->open_mutex); -return 0 ; +return err; }EXPORT_SYMBOL (snd_rawmidi_input_params);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/2857 dm-integrity: fix NULL pointer dereference when the R flag is used
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit 7d4d4f3b668d708d94f62ecdd33ac330a6fd8a84 ]
If the dm-integrity device has the SB_FLAG_DIRTY_BITMAP flag set and the user activates the device in the 'R' mode, a crash in dm_integrity_resume happens because the function attempts to read the journal containing the bitmap.
This patch makes dm-integrity skip any writes to the device in dm_integrity_resume if the device is activated in the 'R' mode.
--- drivers/md/dm-integrity.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/md/dm-integrity.c +5 -0
@@ -3253,6 +3253,10 @@ static void dm_integrity_resume(struct dm_target *ti) r =sync_rw_sb (ic,REQ_OP_READ );if (r)dm_integrity_io_error (ic,"reading superblock" , r); + +if (ic->mode =='R' ) + goto skip_writes; +if ((ic->sb->flags & flags) != flags) { ic->sb->flags |= flags; r =sync_rw_sb (ic,REQ_OP_WRITE |REQ_FUA );
@@ -3362,6 +3366,7 @@ static void dm_integrity_resume(struct dm_target *ti) } } +skip_writes: ic->reboot_notifier.notifier_call = dm_integrity_reboot; ic->reboot_notifier.next =NULL ; ic->reboot_notifier.priority =INT_MAX -1 ;/* be notified after md and before hardware drivers */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/2857 drm/amdgpu: Skip accessing psp rum time db for APUs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kanala Ramalingeswara Reddy <[email protected]>
[ Upstream commit a26301203a196a991527f7b1ab884d4dd0e7c95e ]
Psp runtime DB is for dGPUs only.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +6 -0
@@ -266,6 +266,12 @@ static bool psp_get_runtime_db_entry(struct amdgpu_device *adev,bool ret = false;int i; +/* +* Runtime DB is for dGPUs only. +*/ +if (adev->flags &AMD_IS_APU ) +return false; + db_header_pos = adev->gmc.mc_vram_size -PSP_RUNTIME_DB_OFFSET ; db_dir_pos = db_header_pos +sizeof (struct psp_runtime_data_header );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/2857 smb: client: pin DFS superblock in iterator callback
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit d806d5a85dcbe2a0f181b2f0f9f61ddfbefa1818 ]
tcon_super_cb() stores a raw superblock pointer, but __cifs_get_super() takes its active reference only after iterate_supers_type() has dropped s_umount and its passive reference. Concurrent DFS automount expiry can therefore free the superblock before cifs_sb_active() uses it.
A deterministic KASAN test reproduces the race as:
BUG: KASAN: slab-use-after-free in cifs_sb_active+0x77/0x80
The same test passes with this change applied.
Take the active reference in the callback while iterate_supers_type() still holds s_umount shared. cifs_put_tcp_super() remains the matching release.
--- fs/smb/client/misc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
fs/smb/client/misc.c +8 -9
@@ -1379,8 +1379,14 @@ static void tcp_super_cb(struct super_block *sb, void *arg) cifs_sb =CIFS_SB (sb); tcon =cifs_sb_master_tcon (cifs_sb); -if (tcon->ses->server == server) +if (tcon->ses->server == server) { +/* +* Take the active reference while iterate_supers_type() still +* holds s_umount shared. +*/ +cifs_sb_active (sb); sd->sb = sb; + } } static struct super_block *__cifs_get_super(void (*f)(struct super_block *, void *),
@@ -1396,15 +1402,8 @@ static struct super_block *__cifs_get_super(void (*f)(struct super_block *, voidfor (; *fs_type; fs_type++) {iterate_supers_type (*fs_type, f, &sd); -if (sd.sb) { -/* -* Grab an active reference in order to prevent automounts (DFS links) -* of expiring and then freeing up our cifs superblock pointer while -* we're doing failover. -*/ -cifs_sb_active (sd.sb); +if (sd.sb)return sd.sb; - } }return ERR_PTR (-EINVAL ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/2857 mmc: mmc-hsq: Use fifo to dispatch mmc_request
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Wu <[email protected]>
[ Upstream commit e026a3f9172f5c9aacff270b929a166c3ea1b6f7 ]
Current next_tag selection will cause a large delay in some requests and destroy the scheduling results of the block scheduling layer. Because the issued mrq tags cannot ensure that each time is sequential, especially when the IO load is heavy. In the fio performance test, we found that 4k random read data was sent to mmc_hsq to start calling request_atomic It takes nearly 200ms to process the request, while mmc_hsq has processed thousands of other requests. So we use fifo here to ensure the first in, first out feature of the request and avoid adding additional delay to the request.
Stable-dep-of: 5d132990475f ("mmc: hsq: Fix use-after-free in retry work")
--- drivers/mmc/host/mmc_hsq.c | 40 ++++++++++++++------------------------ drivers/mmc/host/mmc_hsq.h | 5 +++++ 2 files changed, 20 insertions(+), 25 deletions(-)
drivers/mmc/host/mmc_hsq.c +15 -25
@@ -13,9 +13,6 @@#include "mmc_hsq.h" -#define HSQ_NUM_SLOTS 64 -#define HSQ_INVALID_TAG HSQ_NUM_SLOTS -static void mmc_hsq_retry_handler (struct work_struct *work) { struct mmc_hsq *hsq = container_of(work, struct mmc_hsq, retry_work);
@@ -73,7 +70,6 @@ static void mmc_hsq_pump_requests(struct mmc_hsq *hsq)static void mmc_hsq_update_next_tag (struct mmc_hsq *hsq,int remains) { -struct hsq_slot *slot;int tag;/*
@@ -82,29 +78,12 @@ static void mmc_hsq_update_next_tag(struct mmc_hsq *hsq, int remains)*/ if (!remains) { hsq->next_tag =HSQ_INVALID_TAG ; + hsq->tail_tag =HSQ_INVALID_TAG ;return ; } -/* -* Increasing the next tag and check if the corresponding request is -* available, if yes, then we found a candidate request. -*/ -if (++hsq->next_tag !=HSQ_INVALID_TAG ) { - slot = &hsq->slot[hsq->next_tag]; -if (slot->mrq) -return ; - } - -/* Othersie we should iterate all slots to find a available tag. */ -for (tag =0 ; tag <HSQ_NUM_SLOTS ; tag++) { - slot = &hsq->slot[tag]; -if (slot->mrq) -break ; - } - -if (tag ==HSQ_NUM_SLOTS ) - tag =HSQ_INVALID_TAG ; - + tag = hsq->tag_slot[hsq->next_tag]; + hsq->tag_slot[hsq->next_tag] =HSQ_INVALID_TAG ; hsq->next_tag = tag; }
@@ -233,8 +212,14 @@ static int mmc_hsq_request(struct mmc_host *mmc, struct mmc_request *mrq)* Set the next tag as current request tag if no available * next tag. */ -if (hsq->next_tag ==HSQ_INVALID_TAG ) +if (hsq->next_tag ==HSQ_INVALID_TAG ) { hsq->next_tag = tag; + hsq->tail_tag = tag; + hsq->tag_slot[hsq->tail_tag] =HSQ_INVALID_TAG ; + }else { + hsq->tag_slot[hsq->tail_tag] = tag; + hsq->tail_tag = tag; + } hsq->qcnt++;
@@ -339,8 +324,10 @@ static const struct mmc_cqe_ops mmc_hsq_ops = {int mmc_hsq_init (struct mmc_hsq *hsq,struct mmc_host *mmc) { +int i; hsq->num_slots =HSQ_NUM_SLOTS ; hsq->next_tag =HSQ_INVALID_TAG ; + hsq->tail_tag =HSQ_INVALID_TAG ; hsq->slot =devm_kcalloc (mmc_dev (mmc), hsq->num_slots,sizeof (struct hsq_slot ),GFP_KERNEL );
@@ -351,6 +338,9 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) hsq->mmc->cqe_private = hsq; mmc->cqe_ops = &mmc_hsq_ops; +for (i =0 ; i <HSQ_NUM_SLOTS ; i++) + hsq->tag_slot[i] =HSQ_INVALID_TAG ; +INIT_WORK (&hsq->retry_work, mmc_hsq_retry_handler);spin_lock_init (&hsq->lock);init_waitqueue_head (&hsq->wait_queue);
drivers/mmc/host/mmc_hsq.h +5 -0
@@ -2,6 +2,9 @@#ifndef LINUX_MMC_HSQ_H #define LINUX_MMC_HSQ_H +#define HSQ_NUM_SLOTS 64 +#define HSQ_INVALID_TAG HSQ_NUM_SLOTS +struct hsq_slot {struct mmc_request *mrq; };
@@ -17,6 +20,8 @@ struct mmc_hsq {int next_tag;int num_slots;int qcnt; +int tail_tag; +int tag_slot[HSQ_NUM_SLOTS ];bool enabled;bool waiting_for_idle;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/2857 mmc: hsq: Fix use-after-free in retry work
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 5d132990475f02cfa1debe03d50b479432864ebd ]
mmc_hsq_pump_requests() queues retry_work when request_atomic() returns -EBUSY; today sdhci-sprd is the only consumer that implements request_atomic(). The work is embedded in a devm-allocated mmc_hsq, but is never cancelled during driver removal. Work still pending at unbind can therefore run after the devm allocation has been released and dereference hsq->mmc and hsq->mrq.
Use devm_work_autocancel() to cancel and drain retry_work before the devm allocation is released. By the time devres cleanup begins, mmc_remove_host() has already stopped the host, so no new requests can arm the work.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mmc_hsq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/host/mmc_hsq.c +7 -1
@@ -7,6 +7,7 @@* Author: Baolin Wang <[email protected]> */ +#include <linux/devm-helpers.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> #include <linux/module.h>
@@ -324,6 +325,7 @@ static const struct mmc_cqe_ops mmc_hsq_ops = {int mmc_hsq_init (struct mmc_hsq *hsq,struct mmc_host *mmc) { +int ret;int i; hsq->num_slots =HSQ_NUM_SLOTS ; hsq->next_tag =HSQ_INVALID_TAG ;
@@ -341,7 +343,11 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc)for (i =0 ; i <HSQ_NUM_SLOTS ; i++) hsq->tag_slot[i] =HSQ_INVALID_TAG ; -INIT_WORK (&hsq->retry_work, mmc_hsq_retry_handler); + ret =devm_work_autocancel (mmc_dev (mmc), &hsq->retry_work, + mmc_hsq_retry_handler); +if (ret) +return ret; +spin_lock_init (&hsq->lock);init_waitqueue_head (&hsq->wait_queue);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/2857 irqchip/stm32mp-exti: Fix the unit of the hwspinlock timeout
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ju Nan <[email protected]>
[ Upstream commit d31fbbade43f880b7e59e2b3a72722fe2725d93f ]
HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:
atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
if (atomic_delay > to * 1000)
return -ETIMEDOUT;So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.
The hwspinlock core documents this explicitly:
If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.
--- drivers/irqchip/irq-stm32-exti.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/irqchip/irq-stm32-exti.c +3 -3
@@ -24,7 +24,7 @@#define IRQS_PER_BANK 32 -#define HWSPNLCK_TIMEOUT 1000/* usec */ +#define HWSPNLCK_TIMEOUT_MS 1struct stm32_exti_bank {u32 imr_ofst;
@@ -363,7 +363,7 @@ static int stm32_irq_set_type(struct irq_data *d, unsigned int type)irq_gc_lock (gc);if (hwlock) { - err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {pr_err ("%s can't get hwspinlock (%d)\n" , __func__, err); goto unlock;
@@ -567,7 +567,7 @@ static int stm32_exti_h_set_type(struct irq_data *d, unsigned int type)raw_spin_lock (&chip_data->rlock);if (hwlock) { - err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {pr_err ("%s can't get hwspinlock (%d)\n" , __func__, err); goto unlock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/2857 ALSA: usbusx2y: validate URB actual_length in interrupt callback
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
[ Upstream commit 8f5ef203abda9dd36b2af473c7b737d544f807bd ]
i_usx2y_in04_int() processes the interrupt URB data without checking urb->actual_length. A short transfer from a malfunctioning device would cause the handler to process uninitialized heap data from the kmalloc-allocated in04_buf, which is then copied to the mmap-accessible ctl_snapshot[] array.
Fix by using kzalloc() for in04_buf to zero-initialize the buffer, and adding an actual_length check to skip processing on short transfers while still resubmitting the URB.
--- sound/usb/usx2y/usbusx2y.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
sound/usb/usx2y/usbusx2y.c +6 -1
@@ -190,6 +190,10 @@ static void i_usx2y_in04_int(struct urb *urb) }// printk("%i:0x%02X ", 8, (int)((unsigned char*)usx2y->in04_buf)[8]); Master volume shows 0 here if fader is at max during boot ?!? + +if (urb->actual_length <USX2Y_IN04_SIZE ) + goto resubmit; +if (us428ctls) { diff =-1 ;if (us428ctls->ctl_snapshot_last ==-2 ) {
@@ -254,6 +258,7 @@ static void i_usx2y_in04_int(struct urb *urb)if (err)snd_printk (KERN_ERR "in04_int() usb_submit_urb err=%i\n" , err); +resubmit: urb->dev = usx2y->dev;usb_submit_urb (urb,GFP_ATOMIC ); }
@@ -306,7 +311,7 @@ int usx2y_in04_init(struct usx2ydev *usx2y) goto error; } - usx2y->in04_buf =kmalloc (USX2Y_IN04_SIZE ,GFP_KERNEL ); + usx2y->in04_buf =kzalloc (USX2Y_IN04_SIZE ,GFP_KERNEL );if (!usx2y->in04_buf) { err = -ENOMEM ; goto error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/2857 xfs: strengthen the "is cow staging" helpers in scrub
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 0d43368844a75ad13561a1198a3b027940730756 ]
LOLLM pointed out a bug in both of the refcount scrub predicates that determine if a range of blocks is marked as CoW staging in the btree. While it compares blockcount < len, this isn't enough to determine that the CoW staging record is at least as large as the range passed into the helper. Fix both of them.
--- fs/xfs/scrub/refcount.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/refcount.c +5 -1
@@ -443,8 +443,12 @@ xchk_xref_is_cow_staging(if (rc.rc_domain !=XFS_REFC_DOMAIN_COW )xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Can't start after bno */ +if (rc.rc_startblock > agbno) +xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Must be at least as long as what was passed in */ -if (rc.rc_blockcount < len) +if (rc.rc_startblock + rc.rc_blockcount < agbno + len)xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/2857 path: add cleanup helper
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit ff2c570ef7eaa9ded58e7a02dd7a68874a897508 ]
Add a simple cleanup helper so we can cleanup struct path easily. No need for any extra machinery. Avoid DEFINE_FREE() as it causes a local copy of struct path to be used. Just rely on path_put() directly called from a cleanup helper.
Stable-dep-of: a7c1290eef60 ("configfs: pin the symlink target's dirent instead of chasing ->ci_dentry")
--- include/linux/path.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/path.h +9 -0
@@ -24,4 +24,13 @@ static inline void path_put_init(struct path *path) *path = (struct path) { }; } +/* +* Cleanup macro for use with __free(path_put). Avoids dereference and +* copying @path unlike DEFINE_FREE(). path_put() will handle the empty +* path correctly just ensure @path is initialized: +* +* struct path path __free(path_put) = {}; +*/ +#define __free_path_put path_put +#endif /* _LINUX_PATH_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/2857 configfs:get_target() - release path as soon as we grab configfs_item reference
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 1b25dea3867abc9bad6f0337d395c6f0ce4e4f6f ]
... and get rid of path argument - it turns into a local variable in get_target()
Stable-dep-of: a7c1290eef60 ("configfs: pin the symlink target's dirent instead of chasing ->ci_dentry")
--- fs/configfs/symlink.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
fs/configfs/symlink.c +13 -20
@@ -114,26 +114,21 @@ static int create_link(struct config_item *parent_item, } -static int get_target (const char *symname,struct path *path, -struct config_item **target,struct super_block *sb) +static int get_target (const char *symname,struct config_item **target, +struct super_block *sb) { + struct path path __free(path_put) = {};int ret; - ret =kern_path (symname,LOOKUP_FOLLOW |LOOKUP_DIRECTORY , path); -if (!ret) { -if (path->dentry->d_sb == sb) { - *target =configfs_get_config_item (path->dentry); -if (!*target) { - ret = -ENOENT ; -path_put (path); - } - }else { - ret = -EPERM ; -path_put (path); - } - } - -return ret; + ret =kern_path (symname,LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &path); +if (ret) +return ret; +if (path.dentry->d_sb != sb) +return -EPERM ; + *target =configfs_get_config_item (path.dentry); +if (!*target) +return -ENOENT ; +return 0 ; }
@@ -141,7 +136,6 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, const char *symname) { int ret; -struct path path;struct configfs_dirent *sd;struct config_item *parent_item;struct config_item *target_item =NULL ;
@@ -188,7 +182,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,* AV, a thoroughly annoyed bastard. */ inode_unlock (dir); - ret =get_target (symname, &path, &target_item, dentry->d_sb); + ret =get_target (symname, &target_item, dentry->d_sb);inode_lock (dir);if (ret) goto out_put;
@@ -210,7 +204,6 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, }config_item_put (target_item); -path_put (&path); out_put:config_item_put (parent_item);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/2857 configfs: pin the symlink targets dirent instead of chasing ->ci_dentry
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasileios Almpanis <[email protected]>
[ Upstream commit a7c1290eef60711c10289c056ad32ed1f2b47b12 ]
create_link() reads the target's configfs_dirent from item->ci_dentry->d_fsdata, relying on the item reference taken by get_target(). That reference pins the item, not its dentry: the dentry is pinned by DCACHE_PERSISTENT, which configfs_remove_dir() releases via simple_rmdir() while the item is still alive. A symlink racing with rmdir of its target can therefore find ->ci_dentry freed and its dirent released, triggering WARN_ON(!atomic_read(&sd->s_count)) in configfs_get().
Take the dirent in get_target() as well, under ->d_lock and atomically with the item reference, and pass it down to create_link(). A hashed dentry has not been killed yet, so its ->d_fsdata reference keeps the dirent alive there.
--- fs/configfs/symlink.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
fs/configfs/symlink.c +20 -4
@@ -76,9 +76,9 @@ static int configfs_get_target_path(struct config_item *item,static int create_link (struct config_item *parent_item,struct config_item *item, +struct configfs_dirent *target_sd,struct dentry *dentry) { -struct configfs_dirent *target_sd = item->ci_dentry->d_fsdata;char *body;int ret;
@@ -115,6 +115,7 @@ static int create_link(struct config_item *parent_item,static int get_target (const char *symname,struct config_item **target, +struct configfs_dirent **target_sd,struct super_block *sb) { struct path path __free(path_put) = {};
@@ -125,7 +126,20 @@ static int get_target(const char *symname, struct config_item **target,return ret;if (path.dentry->d_sb != sb)return -EPERM ; - *target =configfs_get_config_item (path.dentry); +/* +* A hashed dentry guarantees that neither the item nor the dirent +* have been released yet, as removals unhash before dropping. +* Grab both references here. An item reference alone would not keep +* ->ci_dentry alive. +*/ +spin_lock (&path.dentry->d_lock); +if (!d_unhashed (path.dentry)) { +struct configfs_dirent *sd = path.dentry->d_fsdata; + + *target =config_item_get (sd->s_element); + *target_sd =configfs_get (sd); + } +spin_unlock (&path.dentry->d_lock);if (!*target)return -ENOENT ;return 0 ;
@@ -139,6 +153,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,struct configfs_dirent *sd;struct config_item *parent_item;struct config_item *target_item =NULL ; +struct configfs_dirent *target_sd =NULL ;const struct config_item_type *type; sd = dentry->d_parent->d_fsdata;
@@ -182,7 +197,7 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,* AV, a thoroughly annoyed bastard. */ inode_unlock (dir); - ret =get_target (symname, &target_item, dentry->d_sb); + ret =get_target (symname, &target_item, &target_sd, dentry->d_sb);inode_lock (dir);if (ret) goto out_put;
@@ -196,13 +211,14 @@ int configfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, ret = type->ct_item_ops->allow_link (parent_item, target_item);if (!ret) {mutex_lock (&configfs_symlink_mutex); - ret =create_link (parent_item, target_item, dentry); + ret =create_link (parent_item, target_item, target_sd, dentry);mutex_unlock (&configfs_symlink_mutex);if (ret && type->ct_item_ops->drop_link) type->ct_item_ops->drop_link (parent_item, target_item); } +configfs_put (target_sd);config_item_put (target_item); out_put:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/2857 configfs: unhash the dentry before dropping the item in rmdir
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasileios Almpanis <[email protected]>
[ Upstream commit f06c2d26d1999d37e93299db0ecead04ca7d0b9f ]
configfs_get_config_item() treats a hashed dentry as proof that sd->s_element is a live config_item. configfs_rmdir() breaks that:simple_rmdir() leaves the dentry hashed, the last reference to the item is dropped right after, and the dentry is only unhashed by d_delete() once ->rmdir() has returned. configfs_symlink() resolves its target holding no lock on it, so get_target() can land in that window:
BUG: KASAN: slab-use-after-free in config_item_get+0x26/0x90 get_target fs/configfs/symlink.c:128 [inline] configfs_symlink+0x4ab/0x1030 fs/configfs/symlink.c:185
Unhash in configfs_remove_dir(), while the item is still guaranteed to be there. A reference obtained just before that stays harmless, as create_link() rechecks CONFIGFS_USET_DROPPING, already set by configfs_detach_prep(). Both configfs_unregister_subsystem() paths d_drop() after detaching, so this only makes rmdir match them.
--- fs/configfs/dir.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/configfs/dir.c +11 -2
@@ -395,8 +395,17 @@ static void remove_dir(struct dentry * d)configfs_remove_dirent (d); -if (d_really_is_positive (d)) -simple_rmdir (d_inode (parent),d); +if (d_really_is_positive (d)) { +if (!simple_rmdir (d_inode (parent), d)) +/* +* configfs_get_config_item() takes a hashed dentry as +* proof that ->s_element is still alive. Our caller +* is about to drop the last reference to the item and +* the VFS will not unhash until after we return, so +* unhash it here. +*/ +d_drop (d); + }pr_debug (" o %pd removing done (%d)\n" , d,d_count (d));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/2857 EDAC/altera: Use ECC manager compatible to select A10/S10 IRQ layout
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rounak Das <[email protected]>
[ Upstream commit d4486fc3098e176cb4a29fee037216484761f9ca ]
The SDMMC ECC IRQ layout selection uses CONFIG_64BIT to distinguish between Arria10 and Stratix10 paths.
Detect the SoC once at probe via the device match table (.data) store it in struct altr_arria10_edac, and use it instead of CONFIG_64BIT.
This keeps the decision correct for every ECC child device (OCRAM, SD/MMC, etc.) and avoids any runtime compatible lookup.
Stable-dep-of: 9868f5c077df ("EDAC/altera: Use parent device for devres in altr_portb_setup()")
--- drivers/edac/altera_edac.c | 107 +++++++++++++++++++------------------ drivers/edac/altera_edac.h | 1 + 2 files changed, 55 insertions(+), 53 deletions(-)
drivers/edac/altera_edac.c +54 -53
@@ -1517,6 +1517,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)int edac_idx, rc;struct device_node *np;const struct edac_device_prv_data *prv = &a10_sdmmceccb_data; +bool is_s10 = device->edac->is_s10; rc =altr_check_ecc_deps (device);if (rc)
@@ -1558,15 +1559,14 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)/* * Update the PortB IRQs - A10 has 4, S10 has 2, Index accordingly -* -* FIXME: Instead of ifdefs with different architectures the driver -* should properly use compatibles. */ -#ifdef CONFIG_64BIT - altdev->sb_irq =irq_of_parse_and_map (np,1 ); -#else - altdev->sb_irq =irq_of_parse_and_map (np,2 ); -#endif + +/* Using compatibles to determine the IRQ Index */ +if (is_s10) + altdev->sb_irq =irq_of_parse_and_map (np,1 ); +else + altdev->sb_irq =irq_of_parse_and_map (np,2 ); +if (!altdev->sb_irq) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB SBIRQ alloc\n" ); rc = -ENODEV ;
@@ -1580,29 +1580,28 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) goto err_release_group_1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Error PortB DBIRQ alloc\n" ); - goto err_release_group_1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,3 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); - rc = -ENODEV ; - goto err_release_group_1; - } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, - prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); - goto err_release_group_1; +if (is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + goto err_release_group_1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,3 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + rc = -ENODEV ; + goto err_release_group_1; + } + rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); + goto err_release_group_1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -1985,29 +1984,29 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac, goto err_release_group1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Unable to parse DB IRQ index\n" ); - goto err_release_group1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,1 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); - rc = -ENODEV ; - goto err_release_group1; - } - rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, -IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); - goto err_release_group1; +if (edac->is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE , +"Unable to parse DB IRQ index\n" ); + goto err_release_group1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,1 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); + rc = -ENODEV ; + goto err_release_group1; + } + rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, +IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); + goto err_release_group1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -2133,6 +2132,8 @@ static int altr_edac_a10_probe(struct platform_device *pdev)platform_set_drvdata (pdev, edac);INIT_LIST_HEAD (&edac->a10_ecc_devices); + edac->is_s10 = !!device_get_match_data (&pdev->dev); + edac->ecc_mgr_map =altr_sysmgr_regmap_lookup_by_phandle (pdev->dev.of_node,"altr,sysmgr-syscon" );
@@ -2221,7 +2222,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev)static const struct of_device_id altr_edac_a10_of_match[] = { { .compatible ="altr,socfpga-a10-ecc-manager" }, - { .compatible ="altr,socfpga-s10-ecc-manager" }, + { .compatible ="altr,socfpga-s10-ecc-manager" , .data = (void *)1 }, {}, };MODULE_DEVICE_TABLE (of, altr_edac_a10_of_match);
drivers/edac/altera_edac.h +1 -0
@@ -395,6 +395,7 @@ struct altr_arria10_edac {struct irq_chip irq_chip;struct list_head a10_ecc_devices;struct notifier_block panic_notifier; + bool is_s10; };#endif /* #ifndef _ALTERA_EDAC_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/2857 EDAC/altera: Use parent device for devres in altr_portb_setup()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dinh Nguyen <[email protected]>
[ Upstream commit 9868f5c077dfe0b606331f2e782484f91a5789a5 ]
Anchor the devres group and the devm-managed IRQ requests in altr_portb_setup() to the actual parent device (device->edac->dev) instead of the embedded struct device inside the copied per-port altr_edac_device_dev.
This keeps devres_open_group(), devm_request_irq(), devres_remove_group() and devres_release_group() all referring to the same long-lived device so the group and the resources allocated inside it are torn down together.
--- drivers/edac/altera_edac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/edac/altera_edac.c +5 -5
@@ -1544,7 +1544,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) altdev = dci->pvt_info; *altdev = *device; -if (!devres_open_group (&altdev->ddev, altr_portb_setup,GFP_KERNEL )) +if (!devres_open_group (device->edac->dev, altr_portb_setup,GFP_KERNEL ))return -ENOMEM ;/* Update PortB specific values */
@@ -1572,7 +1572,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->sb_irq, + rc =devm_request_irq (device->edac->dev, altdev->sb_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1594,7 +1594,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + rc =devm_request_irq (device->edac->dev, altdev->db_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1614,13 +1614,13 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)list_add (&altdev->next, &altdev->edac->a10_ecc_devices); -devres_remove_group (&altdev->ddev, altr_portb_setup); +devres_remove_group (device->edac->dev, altr_portb_setup);return 0 ; err_release_group_1:edac_device_free_ctl_info (dci); -devres_release_group (&altdev->ddev, altr_portb_setup); +devres_release_group (device->edac->dev, altr_portb_setup);edac_printk (KERN_ERR ,EDAC_DEVICE ,"%s:Error setting up EDAC device: %d\n" , ecc_name, rc);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/2857 s390/crypto: Fix skcipher_walk return code handling in aes_s390
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
[ Upstream commit 15fa028589c3a2545f0bff355eff06d5844196bf ]
The return codes from skcipher_walk_virt() were not properly checked before entering the processing loops in ecb_aes_crypt() and ctr_aes_crypt(). If skcipher_walk_virt() fails, the walk structure may be in an undefined state, and attempting to process data could lead to incorrect behavior or accessing uninitialized memory.
Add proper return code checking to ensure correct handling of the walk initialization and walk advance and eventually return to the caller with that return code.
--- arch/s390/crypto/aes_s390.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/s390/crypto/aes_s390.c +5 -5
@@ -231,7 +231,7 @@ static int ecb_aes_crypt(struct skcipher_request *req, unsigned long modifier)return fallback_skcipher_crypt (sctx, req, modifier); ret =skcipher_walk_virt (&walk, req, false); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_km(sctx->fc | modifier, sctx->key,
@@ -335,7 +335,7 @@ static int cbc_aes_crypt(struct skcipher_request *req, unsigned long modifier)return ret;memcpy (param.iv, walk.iv,AES_BLOCK_SIZE );memcpy (param.key, sctx->key, sctx->key_len); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_kmc(sctx->fc | modifier, ¶m,
@@ -465,7 +465,7 @@ static int xts_aes_crypt(struct skcipher_request *req, unsigned long modifier)memcpy (xts_param.key + offset, xts_ctx->key, xts_ctx->key_len);memcpy (xts_param.init, pcc_param.xts,16 ); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_km(xts_ctx->fc | modifier, xts_param.key + offset,
@@ -581,7 +581,7 @@ static int ctr_aes_crypt(struct skcipher_request *req) locked =mutex_trylock (&ctrblk_lock); ret =skcipher_walk_virt (&walk, req, false); -while ((nbytes = walk.nbytes) >=AES_BLOCK_SIZE ) { +while (!ret && ((nbytes = walk.nbytes) >=AES_BLOCK_SIZE )) { n =AES_BLOCK_SIZE ;if (nbytes >=2 *AES_BLOCK_SIZE && locked)
@@ -600,7 +600,7 @@ static int ctr_aes_crypt(struct skcipher_request *req)/* * final block may be < AES_BLOCK_SIZE, copy only nbytes */ -if (nbytes) { +if (!ret && nbytes) {memset (buf,0 ,AES_BLOCK_SIZE );memcpy (buf, walk.src.virt.addr, nbytes); cpacf_kmctr(sctx->fc, sctx->key, buf, buf,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/2857 io_uring/rw: end write accounting from ->ki_complete
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
[ Upstream commit 796aa0547557e63338657ed1c487906f9fac4c73 ]
Commit b000145e9907 moved both the fsnotify calls and the write accounting out of the kiocb completion handler and into the io_req_rw_complete() task_work. However, only the fsnotify part actually needed to move as it may sleep. Ending the write accounting is just a percpu_up_read() on the superblock writers sem.
Deferring it is a problem, because it makes dropping SB_FREEZE_WRITE protection depend on the ring owner getting to running task_work. But the task may be blocked in freeze_super(), causing it to never get to that:
task io-wq worker
--------------------------------------------------------------
io_write()
io_kiocb_start_write() (takes sb_writers, hidden from
lockdep by __sb_writers_release)
write_iter() -> -EIOCBQUEUED
ioctl(FS_IOC_SHUTDOWN)
bdev_freeze()
freeze_super()
percpu_down_write() <- waits for the reader above
io_write()
kiocb_start_write()
percpu_down_read() <- queued
behind the writer
<bio completes>
io_complete_rw()
queues io_req_rw_complete() <- never runs, task is in D state
End the write from io_complete_rw() instead, and leave only the fsnotify calls in task_work.
--- io_uring/rw.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
io_uring/rw.c +20 -10
@@ -215,20 +215,25 @@ static void io_req_end_write(struct io_kiocb *req) } } -/* -* Trigger the notifications after having done some IO, and finish the write -* accounting, if any. -*/ -static void io_req_io_end (struct io_kiocb *req) +/* Trigger the notifications after having done some IO. */ +static void io_req_io_notify (struct io_kiocb *req) { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); -if (rw->kiocb.ki_flags &IOCB_WRITE ) { -io_req_end_write (req); +if (rw->kiocb.ki_flags &IOCB_WRITE )fsnotify_modify (req->file); - }else { +else fsnotify_access (req->file); - } +} + +/* Finish write accounting and notify, for inline completions only. */ +static void io_req_io_end (struct io_kiocb *req) +{ + struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); + +if (rw->kiocb.ki_flags &IOCB_WRITE ) +io_req_end_write (req); +io_req_io_notify (req); }static bool __io_complete_rw_common (struct io_kiocb *req,long res)
@@ -266,7 +271,7 @@ static inline int io_fixup_rw_res(struct io_kiocb *req, long res)static void io_req_rw_complete (struct io_kiocb *req,bool *locked) { -io_req_io_end (req); +io_req_io_notify (req);io_req_task_complete (req, locked); }
@@ -277,6 +282,11 @@ static void io_complete_rw(struct kiocb *kiocb, long res)if (__io_complete_rw_common (req, res))return ; + +/* ring owner may block in freeze_super() before task_work runs */ +if (kiocb->ki_flags &IOCB_WRITE ) +io_req_end_write (req); +io_req_set_res (req,io_fixup_rw_res (req, res),0 ); req->io_task_work.func = io_req_rw_complete;io_req_task_work_add (req);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/2857 swiotlb: use the adjusted address for the highmem page lookup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit b7d7914a9ae3097e63d113007e4fb44d33d515b1 ]
swiotlb_bounce() reads the page frame number from the slot's recorded orig_addr, then advances orig_addr by tlb_offset to reach the address the caller asked about. The highmem branch mixes the two: the offset within the page comes from the adjusted address, the page from the value before it.
Once the adjustment crosses a page boundary the pair no longer describes one location, and the whole copy lands one page below the intended one for a positive tlb_offset, one above for a negative one. DMA_FROM_DEVICE writes the device data over the wrong page and leaves the intended one stale, DMA_TO_DEVICE feeds the device from a page the mapping may not cover. Partial syncs through dma_sync_single_range_for_*() are what make tlb_offset non-zero.
The branch test is picked the same way, so a slot recorded in lowmem can be adjusted into highmem and the lowmem path then hands a highmem address to phys_to_virt().
Take both from orig_addr once it is final and keep pfn in the branch that uses it. PhysHighMem() asks the question straight from the address, as dma-debug already does.
--- kernel/dma/swiotlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/dma/swiotlb.c +2 -2
@@ -556,7 +556,6 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t sizeint index = (tlb_addr - mem->start) >>IO_TLB_SHIFT ;phys_addr_t orig_addr = mem->slots[index].orig_addr;size_t alloc_size = mem->slots[index].alloc_size; -unsigned long pfn =PFN_DOWN (orig_addr);unsigned char *vaddr = mem->vaddr + tlb_addr - mem->start;unsigned int tlb_offset, orig_addr_offset;
@@ -590,7 +589,8 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size size = alloc_size; } -if (PageHighMem (pfn_to_page (pfn))) { +if (PageHighMem (pfn_to_page (PFN_DOWN (orig_addr)))) { +unsigned long pfn =PFN_DOWN (orig_addr);unsigned int offset = orig_addr & ~PAGE_MASK ;struct page *page;unsigned int sz =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/2857 drm/bridge: tc358768: Enforce input bus flags via atomic_check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leonardo Costa <[email protected]>
[ Upstream commit ed761e0693950fcb4f6b0f60387a3961b972adf3 ]
The tc358768 declares static bridge timings requiring pixel data to be sampled on the positive clock edge.
However, the DRM core default propagation simply copies the output-side bus flags, coming from the next bridge, connector or panel, to the input side. If the propagated flags are incompatible with the bridge ones, the data is wrongly sampled, typically resulting in visual artifacts on the panel.
Implement the atomic_check hook, replacing the mutually exclusive mode_fixup, and set the bridge state input bus flags to the ones required by the tc358768. The sync polarity defaulting previously done in mode_fixup is carried over into atomic_check unchanged.
--- drivers/gpu/drm/bridge/tc358768.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/bridge/tc358768.c +11 -0
@@ -1146,9 +1146,20 @@ tc358768_atomic_get_input_bus_fmts(struct drm_bridge *bridge,return input_fmts; } +static int tc358768_bridge_atomic_check (struct drm_bridge *bridge, +struct drm_bridge_state *bridge_state, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) +{ + bridge_state->input_bus_cfg.flags = bridge->timings->input_bus_flags; + +return 0 ; +} +static const struct drm_bridge_funcs tc358768_bridge_funcs = { .attach = tc358768_bridge_attach, .mode_valid = tc358768_bridge_mode_valid, + .atomic_check = tc358768_bridge_atomic_check, .pre_enable = tc358768_bridge_pre_enable, .enable = tc358768_bridge_enable, .disable = tc358768_bridge_disable,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/2857 fs/ntfs3: use d_instantiate_new() in ntfs_create_inode() and murder syzbots "WARNING in do_new_mount" saga
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 1abd643f3783ea8f8e273c18697ff0413aa92dc7 ]
ntfs_create_inode() creates a new inode via ntfs_new_inode(). It hashes it with insert_inode_locked() and so it's marked as I_NEW until unlock_new_inode().
ntfs 3 calls d_instantiate() in between though... Since the dentry was already hashed by the lookup before the create any path walk finds it without touching the parent's i_rwsem and so can lock the inode.
If the inode is a directory unlock_new_inode() calls lockdep_annotate_inode_mutex_key() and marks i_rwsem with the i_mutex_dir_key class.
That resets the count and the owner of a lock somebody else may already hold by now...
syzbot has been spamming us with the same godforsaken bug
"WARNING in do_new_mount"
since 2023. I can't take it anymore so I went looking. Afaict, syzbot's executor chdirs into a freshly mounted ntfs3 image, creates a directory and then mounts some pseudofs on it. Everytime the mkdir() takes longer than syzbot waits mount() runs concurrently:
mkdir("./sys") mount(NULL, "./sys", "sysfs")
ntfs_create_inode()
d_instantiate()
user_path_at() finds the dentry
do_lock_mount()
inode_lock(inode)
namespace_lock()
unlock_new_inode()
lockdep_annotate_inode_mutex_key()
init_rwsem(&inode->i_rwsem)
unlock_mount()
inode_unlock(inode)The mount side then releases a lock that according to the rwsem nobody holds:
DEBUG_RWSEMS_WARN_ON((rwsem_owner(sem) != current) && ...):
count = 0x0, magic = 0xffff888043a854e8, owner = 0x0, curr 0xffff888000244880, list empty
WARNING: CPU: 0 PID: 5346 at kernel/locking/rwsem.c:1368 __up_write Call Trace: inode_unlock include/linux/fs.h:877 [inline] unlock_mount fs/namespace.c:2892 [inline] do_new_mount_fc fs/namespace.c:3828 [inline] do_new_mount+0x777/0xa40 fs/namespace.c:3887
On PREEMPT_RT the same thing shows up as
DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current)
WARNING: kernel/locking/rtmutex_common.h:193 at rt_mutex_slowunlock
The up_write() underflows the reset count. A following inode_lock() on that directory then never returns. A path walk into the new directory racing with the mkdir() corrupts the lock the same way via inode_lock_shared() in lookup_slow().
Switch to d_instantiate_new() and drop the trailing unlock_new_inode(). All error paths bail out before that point with I_NEW still set and keep using discard_new_inode().
May we never see this fscking bug report again.
--- fs/ntfs3/inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ntfs3/inode.c +2 -4
@@ -1642,10 +1642,10 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, }/* -* Call 'd_instantiate' after inode->i_op is set +* Call 'd_instantiate_new' after inode->i_op is set * but before finish_open. */ -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);ntfs_save_wsl_perm (inode);mark_inode_dirty (dir);
@@ -1696,8 +1696,6 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,return ERR_PTR (err); } -unlock_new_inode (inode); -return inode; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/2857 net: macb: initialize PTP state before registering clock
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 e1406330d70e56dd44fa6fbafc86e77e5c80c122 ]
gem_ptp_init() registers the PTP clock before initializing bp->tsu_clk_lock and the TSU hardware. Since ptp_clock_register() publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready.
In addition, gem_ptp_init() is called from both the interface open and resume paths. Reinitializing tsu_clk_lock there can reset the lock while timestamp processing is using it.
This race is theoretical and has not been observed in practice.
Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock.
--- drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/cadence/macb_ptp.c | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -5104,6 +5104,7 @@ static int macb_probe(struct platform_device *pdev)spin_lock_init (&bp->lock);spin_lock_init (&bp->stats_lock); +spin_lock_init (&bp->tsu_clk_lock);/* setup capabilities */ macb_configure_caps (bp, macb_config);
drivers/net/ethernet/cadence/macb_ptp.c +1 -3
@@ -381,6 +381,7 @@ void gem_ptp_init(struct net_device *dev) bp->tsu_rate = bp->ptp_info->get_tsu_rate (bp); bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj ();gem_ptp_init_timer (bp); +gem_ptp_init_tsu (bp); bp->ptp_clock =ptp_clock_register (&bp->ptp_clock_info, &dev->dev);if (IS_ERR (bp->ptp_clock)) { pr_err("ptp clock register failed: %ld\n",
@@ -392,15 +393,12 @@ void gem_ptp_init(struct net_device *dev)return ; } -spin_lock_init (&bp->tsu_clk_lock);for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { queue->tx_ts_head =0 ; queue->tx_ts_tail =0 ;INIT_WORK (&queue->tx_ts_task, gem_tx_timestamp_flush); } -gem_ptp_init_tsu (bp); -dev_info (&bp->pdev->dev,"%s ptp clock registered.\n" ,GEM_PTP_TIMER_NAME ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/2857 drm/amdgpu/pm: add workload profile pause helper
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit 7f991dd3641ef52e0a25b43f27cc61440c4bdcb4 ]
To be used for display idle optimizations when
we want to pause non-default profiles.
Stable-dep-of: 1f1d43418d61 ("drm/amdgpu: skip gfx switch_power_profile during GPU reset")
--- .../gpu/drm/amd/include/kgd_pp_interface.h | 1 + drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 19 +++++++++++++++++++ drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 2 ++ 3 files changed, 22 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
@@ -340,6 +340,7 @@ struct amd_pm_funcs {int (*set_pp_table)(void *handle,const char *buf,size_t size);void (*debugfs_print_current_performance_level)(void *handle,struct seq_file *m);int (*switch_power_profile)(void *handle,enum PP_SMC_POWER_PROFILE type,bool en); +int (*pause_power_profile)(void *handle,bool pause);/* export to amdgpu */ struct amd_vce_state *(*get_vce_clock_state)(void *handle,u32 idx); int (*dispatch_tasks)(void *handle, enum amd_pp_task task_id,
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +19 -0
@@ -301,6 +301,25 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,return ret; } +int amdgpu_dpm_pause_power_profile (struct amdgpu_device *adev, +bool pause) +{ +const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs; +int ret =0 ; + +if (amdgpu_sriov_vf (adev)) +return 0 ; + +if (pp_funcs && pp_funcs->pause_power_profile) { +mutex_lock (&adev->pm.mutex); + ret = pp_funcs->pause_power_profile ( + adev->powerplay.pp_handle, pause); +mutex_unlock (&adev->pm.mutex); + } + +return ret; +} +int amdgpu_dpm_set_xgmi_pstate (struct amdgpu_device *adev,uint32_t pstate) {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
@@ -384,6 +384,8 @@ int amdgpu_dpm_set_xgmi_pstate(struct amdgpu_device *adev,int amdgpu_dpm_switch_power_profile (struct amdgpu_device *adev,enum PP_SMC_POWER_PROFILE type,bool en); +int amdgpu_dpm_pause_power_profile (struct amdgpu_device *adev, +bool pause);int amdgpu_dpm_baco_reset (struct amdgpu_device *adev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/2857 drm/amdgpu: skip gfx switch_power_profile during GPU reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prike Liang <[email protected]>
[ Upstream commit 1f1d43418d61c8511779e0f63a954a78b9433b43 ]
During resume from GPU reset, the gfx idle work may invoke switch_power_profile before the reset completes. This causes the following assert error because the register access occurs without first releasing the GPU reset semaphore:
[ 1576.768935] CR2: 0000559ea133ead0 CR3: 00000002e6c42000 CR4: 0000000000350ef0 [ 1576.768940] Call Trace: [ 1576.768944] <TASK> [ 1576.768953] amdgpu_device_rreg+0x21/0x50 [amdgpu] [ 1576.769158] smu_msg_v1_send_msg+0x1a4/0x6e0 [amdgpu] [ 1576.769437] smu_cmn_send_smc_msg_with_params_ext+0xba/0x120 [amdgpu] [ 1576.769721] smu_cmn_send_smc_msg_with_param+0x33/0x40 [amdgpu] [ 1576.769993] smu_v13_0_0_set_power_profile_mode+0x192/0x2b0 [amdgpu] [ 1576.770267] smu_bump_power_profile_mode+0x5d/0x80 [amdgpu] [ 1576.770538] smu_switch_power_profile+0xa4/0xf0 [amdgpu] [ 1576.770839] amdgpu_dpm_switch_power_profile+0x6f/0x90 [amdgpu] [ 1576.771210] amdgpu_gfx_profile_idle_work_handler+0xe9/0x130 [amdgpu] [ 1576.771460] process_one_work+0x23e/0x6f0 [ 1576.771491] worker_thread+0x1c4/0x380 [ 1576.771506] kthread+0x10c/0x150 [ 1576.771512] ? __pfx_worker_thread+0x10/0x10 [ 1576.771518] ? __pfx_kthread+0x10/0x10 [ 1576.771530] ret_from_fork+0x314/0x390 [ 1576.771537] ? __pfx_kthread+0x10/0x10 [ 1576.771546] ret_from_fork_asm+0x1a/0x30
--- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -2
@@ -288,7 +288,8 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;int ret =0 ; -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) || +amdgpu_in_reset (adev))return 0 ;if (pp_funcs && pp_funcs->switch_power_profile) {
@@ -307,7 +308,8 @@ int amdgpu_dpm_pause_power_profile(struct amdgpu_device *adev,const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;int ret =0 ; -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) || +amdgpu_in_reset (adev))return 0 ;if (pp_funcs && pp_funcs->pause_power_profile) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/2857 drm/msm: RCU-free the scheduler-containing ring and VM objects
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonghyuk Kim(MalHyuk) <[email protected]>
[ Upstream commit 01c8d1f385f788f1bbbbb7687c4386d614281218 ]
Both struct msm_ringbuffer and struct msm_gem_vm embed a struct drm_gpu_scheduler. msm_ringbuffer_destroy() and the VM free callback msm_gem_vm_free() call drm_sched_fini() on the embedded scheduler and then free the containing object with plain kfree().
drm_sched_fence_get_timeline_name() returns fence->sched->name, and the scheduler fence keeps a .release callback so it is not ops-detached on signalling. A finished fence exported to userspace (the submit out-fence, or a VM_BIND fence, via sync_file / drm_syncobj) keeps pointing at the embedded scheduler after the ring/VM is freed, so a later get_timeline_name() -- reachable unprivileged through SYNC_IOC_FILE_INFO -- dereferences freed slab memory (KASAN slab-use-after-free read).
Per the dma-fence lifetime contract the exporter must keep the data backing a signalled fence alive for an RCU grace period. Free the scheduler-containing objects with kfree_rcu() instead of kfree().
Patchwork: https://patchwork.freedesktop.org/patch/750234/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_ringbuffer.c +1 -1
@@ -130,5 +130,5 @@ void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)msm_gem_kernel_put (ring->bo, ring->gpu->aspace); -kfree (ring); +kfree_rcu (ring, rcu); }
drivers/gpu/drm/msm/msm_ringbuffer.h +1 -0
@@ -49,6 +49,7 @@ struct msm_ringbuffer {/* * The job scheduler for this ring. */ +struct rcu_head rcu;struct drm_gpu_scheduler sched;bool sched_initialized;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/2857 arm64: Use load LSE atomics for the non-return per-CPU atomic operations
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catalin Marinas <[email protected]>
[ Upstream commit 535fdfc5a228524552ee8810c9175e877e127c27 ]
The non-return per-CPU this_cpu_*() atomic operations are implemented as STADD/STCLR/STSET when FEAT_LSE is available. On many microarchitecture implementations, these instructions tend to be executed "far" in the interconnect or memory subsystem (unless the data is already in the L1 cache). This is in general more efficient when there is contention as it avoids bouncing cache lines between CPUs. The load atomics (e.g. LDADD without XZR as destination), OTOH, tend to be executed "near" with the data loaded into the L1 cache.
STADD executed back to back as in srcu_read_{lock,unlock}*() incur an additional overhead due to the default posting behaviour on several CPU implementations. Since the per-CPU atomics are unlikely to be used concurrently on the same memory location, encourage the hardware to to execute them "near" by issuing load atomics - LDADD/LDCLR/LDSET - with the destination register unused (but not XZR).
Stable-dep-of: 8cf2093f5372 ("arm64: percpu: Fix LSE operations on {8,16}-bit types")
--- arch/arm64/include/asm/percpu.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
arch/arm64/include/asm/percpu.h +11 -4
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %[ptr]\n" \ +#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -124,9 +124,16 @@ PERCPU_RW_OPS(8) PERCPU_RW_OPS(16) PERCPU_RW_OPS(32)PERCPU_RW_OPS (64 ) -PERCPU_OP(add, add, stadd) -PERCPU_OP(andnot, bic, stclr) -PERCPU_OP(or, orr, stset) + +/* +* Use value-returning atomics for CPU-local ops as they are more likely +* to execute "near" to the CPU (e.g. in L1$). +* +* https://lore.kernel.org/r/e7d539ed-ced0-4b96-8ecd-048a5b803b85@paulmck-laptop + */ +PERCPU_OP(add, add, ldadd) +PERCPU_OP(andnot, bic, ldclr) +PERCPU_OP(or, orr, ldset) PERCPU_RET_OP(add, add, ldadd)#undef PERCPU_RW_OPS
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/2857 arm64: percpu: Fix LSE operations on {8,16}-bit types
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
[ Upstream commit 8cf2093f5372952a9ebc805c418d45df7112cd14 ]
The assembly for __percpu_##name##_case_##sz() and __percpu_##name##_return_case_##sz() doesn't use the 'sfx' macro argument to form the LSE instruction. Without 'sfx', a W register argument will imply a 32-bit memory location, and consequently {8,16}-bit ops will erroneously read and write 32 bits of memory when the LSE instruction is used.
Fix this by appending 'sfx' to 'op_lse' to LSE instruction. It is not necessary (and not valid) to append 'sfx' to 'op_llsc', as 'op_llsc' is a register-register operation which does not access memory (and does not take a size suffix).
--- arch/arm64/include/asm/percpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/percpu.h +2 -2
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -98,7 +98,7 @@ __percpu_##name##_return_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[ret], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ #op_llsc "\t%" #w "[ret], %" #w "[ret], %" #w "[val]\n" \ __nops(2)) \ : [loop] "=&r" (loop), [ret] "=&r" (ret), \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/2857 tools/bootconfig: Fix integer overflow and truncation in size checks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 462d0b066b613103f579793031429db2ca23abc0 ]
Sashiko reported that on 32-bit systems, if an attacker crafts size in the bootconfig footer such that adding BOOTCONFIG_FOOTER_SIZE wraps around (for instance, if size is 0xFFFFFFFF), the size check in load_xbc_from_initrd() can be bypassed:
if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
pr_err("bootconfig size is too big\n");
return -E2BIG;
}Furthermore, on 64-bit systems with an initrd > 4.29 GB, comparing a corrupted 32-bit size (e.g. 0xFFFFFFFF) against
stat.st_size - BOOTCONFIG_FOOTER_SIZE can also bypass the check if size is not bounded. Similarly, load_xbc_file() passes 64-bit stat.st_size directly into the 32-bit int size parameter of load_xbc_fd(), truncating large standalone files (>= 2GB).
In both cases, passing 0xFFFFFFFF to load_xbc_fd() truncates to -1, resulting in malloc(0), an integer overflow in read(), and an out-of-bounds null-byte write.
Fix this by:
1. Rejecting size > XBC_DATA_MAX or
size > stat.st_size - BOOTCONFIG_FOOTER_SIZE in load_xbc_from_initrd().
2. Rejecting stat.st_size > XBC_DATA_MAX in load_xbc_file() before passing it to load_xbc_fd().
3. Checking size < 0 || size > XBC_DATA_MAX defensively in load_xbc_fd().
--- tools/bootconfig/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
tools/bootconfig/main.c +12 -1
@@ -139,6 +139,9 @@ static int load_xbc_fd(int fd, char **buf, int size) {int ret; +if (size <0 || size >XBC_DATA_MAX ) +return -EINVAL ; + *buf =malloc (size +1 );if (!*buf)return -ENOMEM ;
@@ -167,6 +170,13 @@ static int load_xbc_file(const char *path, char **buf)return ret; } +if (stat.st_size >XBC_DATA_MAX ) { +pr_err ("%s size is too big\n" , path); + ret = -E2BIG ; +close (fd); +return ret; + } + ret =load_xbc_fd (fd, buf, stat.st_size);close (fd);
@@ -217,7 +227,8 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) { +if (size >XBC_DATA_MAX || + size > stat.st_size -BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/2857 bootconfig: Fix integer overflow in initrd size check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 7812d6dab0698001e50e8c2f901e17da3eb6f429 ]
Sashiko reported that in get_boot_config_from_initrd(), a crafted initrd with a huge bootconfig size (such as 0xFFFFFFFF) can cause the pointer arithmetic:
data = ((void *)hdr) - size;
to wrap around on 32-bit systems (or when pointer subtraction overflows). Because data wraps around, the subsequent bounds check:
if ((unsigned long)data < initrd_start)
evaluates to false, bypassing the check. The kernel then calls xbc_calc_checksum(data, size), which attempts to read 4GB of memory, hitting unmapped pages and triggering a fatal kernel page fault during early boot. Furthermore, on 64-bit systems with an initrd > 4.29 GB, an unbounded 32-bit size can similarly bypass the initrd_start check.
Fix this by:
1. Ensuring the initrd is at least large enough to contain the bootconfig footer and verifying hdr is within the initrd bounds.
2. Checking that size does not exceed XBC_DATA_MAX and does not exceed the available space between initrd_start and hdr before performing pointer subtraction.
--- init/main.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
init/main.c +15 -10
@@ -275,7 +275,8 @@ static void * __init get_boot_config_from_initrd(size_t *_size)u32 *hdr;int i; -if (!initrd_end) +if (!initrd_end || initrd_end < initrd_start || + initrd_end - initrd_start <BOOTCONFIG_MAGIC_LEN +8 )return NULL ; data = (char *)initrd_end -BOOTCONFIG_MAGIC_LEN ;
@@ -292,16 +293,26 @@ static void * __init get_boot_config_from_initrd(size_t *_size) found: hdr = (u32 *)(data -8 ); +if ((unsigned long )hdr < initrd_start) +return NULL ; + size =le32_to_cpu (hdr[0 ]); csum =le32_to_cpu (hdr[1 ]); - data = ((void *)hdr) - size; -if ((unsigned long )data < initrd_start) { -pr_err ("bootconfig size %d is greater than initrd size %ld\n" , +if (size >XBC_DATA_MAX ) { +pr_err ("bootconfig size %u is greater than max size %d\n" , + size,XBC_DATA_MAX ); +return NULL ; + } + +if (size > ((unsigned long )hdr - initrd_start)) { +pr_err ("bootconfig size %u is greater than initrd size %lu\n" , size, initrd_end - initrd_start);return NULL ; } + data = ((void *)hdr) - size; +if (xbc_calc_checksum (data, size) != csum) {pr_err ("bootconfig checksum failed\n" );return NULL ;
@@ -400,12 +411,6 @@ static void __init setup_boot_config(void)return ; } -if (size >=XBC_DATA_MAX ) { -pr_err ("bootconfig size %ld greater than max size %d\n" , - (long )size,XBC_DATA_MAX ); -return ; - } - ret =xbc_init (data, size, &msg, &pos);if (ret <0 ) {if (pos <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/2857 tracing: Undo the registration when enabling the histogram trigger fails
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 92383cef66791a0c63a2f27755cadbdb2fbf270b ]
Commit 6f86bdeab633 ("tracing: Fix bad hist from corrupting named_triggers list") described how a trigger that is registered but not on file->triggers ends up freed while still on the global named_triggers list, and moved the registration down so that hist_trigger_enable() follows it immediately. One path still gets there. hist_trigger_enable() adds the trigger and takes it straight back out when the event cannot be enabled:
list_add_tail_rcu(&data->list, &file->triggers);
update_cond_flag(file);
if (trace_event_trigger_enable_disable(file, 1) < 0) {
list_del_rcu(&data->list);
update_cond_flag(file);
ret--;
}so the list walk in hist_unregister_trigger() matches nothing, test stays NULL, and the ->free() that would call del_named_trigger() is skipped. out_unreg falls through to out_free, which frees the trigger anyway:
BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff8880091d3160 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0xa00 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 69: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160
Leave the trigger where hist_unregister_trigger() can find it and let that undo the registration, which is the only code that knows all of what cmd_ops->init() took: the named list entry, the hist_pad reference, the reference on the trigger a named histogram is shared with, and the copied cmd_ops. It also pairs the failed trace_event_trigger_enable_disable(), whose sm_ref and buffered event reference are otherwise left behind.
Since ->free() releases trigger_data and, for a trigger that does not share its histogram, hist_data with it, out_unreg can no longer fall through to out_free. For a trigger that does share, hist_register_trigger() has already destroyed the caller's hist_data, so the fall-through was reading freed memory there as well.
Move the enable_timestamps check in hist_unregister_trigger() above the ->free() call for the same reason: hist_data does not outlive it once the trigger being removed is the one that owns it.
--- kernel/trace/trace_events_hist.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
kernel/trace/trace_events_hist.c +10 -7
@@ -6302,11 +6302,12 @@ static int hist_trigger_enable(struct event_trigger_data *data,update_cond_flag (file); -if (trace_event_trigger_enable_disable (file,1 ) <0 ) { -list_del_rcu (&data->list); -update_cond_flag (file); +/* +* On failure the caller undoes the registration, and +* hist_unregister_trigger() can only find the trigger here. +*/ +if (trace_event_trigger_enable_disable (file,1 ) <0 ) ret--; - }return ret; }
@@ -6384,13 +6385,13 @@ static void hist_unregister_trigger(char *glob, } } -if (test && test->ops->free) - test->ops->free (test); -if (hist_data->enable_timestamps) {if (!hist_data->remove || test)tracing_set_filter_buffering (file->tr, false); } + +if (test && test->ops->free) + test->ops->free (test); }static bool hist_file_check_refs (struct trace_event_file *file)
@@ -6590,6 +6591,8 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,return ret; out_unreg:event_trigger_unregister (cmd_ops, file, glob+1 , trigger_data); +/* The unregister frees trigger_data, skip out_free */ + goto out; out_free:event_trigger_reset_filter (cmd_ops, trigger_data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/2857 tracing: Take trace_array reference when opening a tracer options file
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit ed0aff60f83a9bdc2f6556376ac79c96b3ce7e80 ]
When a tracer option file is opened, it is passed a descriptor that points to an element on the trace_array's topts array. This element has information to find the trace array and other information. It uses this element to take a reference of the trace_array so that the trace_array does not get removed while this file is opened.
Unfortunately, there's a race condition where the element itself could be freed by the removal of the instance the trace_array represents causing a use-after-free as this element that is used to find the trace_array to increment its reference counter is also freed when the instance is removed.
To solve this, add a trace_array_tracer_options_get() helper function that will take the address of the element that is passed to the open function by the inode->i_private pointer and search all the trace_arrays under a lock to find the one that the element's address is in the range of the trace_arrays topts array elements. When a match happens, that trace_array's reference would be increased.
Note, there's a race where if an admin was deleting and creating trace instances at the same time and the memory of the old trace_array's array matched the memory of the new trace_array that it could in theory open the option from the wrong trace array. But we do not care because it would be stupid to perform that kind of action. As long as the only thing that can happen is that the option from the wrong trace array is used and doesn't crash the kernel it will only make the user confused. But if they are doing something stupid like this, they are already confused, so no harm done.
--- kernel/trace/trace.c | 48 +++++++++++++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 1 + 2 files changed, 48 insertions(+), 1 deletion(-)
kernel/trace/trace.c +47 -1
@@ -8919,12 +8919,57 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,return cnt; } +static bool tr_option_match (struct trace_array *tr,void *topt) +{ +for (int i =0 ; i < tr->nr_topts; i++) { +struct trace_options *tr_topts = &tr->topts[i]; + +if (topt >= (void *)&tr_topts->topts[0 ] && + topt < (void *)&tr_topts->topts[tr_topts->nr_topts]) +return true; + } +return false; +} + +/* +* The topt is the address of a trace_array->topts[] element that holds the +* the tracer options descriptor. But since the trace_array reference has not +* been taken yet, it cannot be dereferenced as it could have been freed by +* a rmdir of the instance the trace_array represents. +* +* Search the list of trace_arrays and compare the topt to the address of +* the entire trace_array topts array for each trace_array in the list. +* If one is matched, then take the reference and return it. If not, the +* trace_array no longer exits. +*/ +static int trace_array_tracer_options_get (void *topt) +{ +struct trace_array *tr; +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; + +if (tracing_disabled) +return -ENODEV ; + +guard (mutex)(&trace_types_lock); +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (tr_option_match (tr, topt)) { + tr->ref++; +return 0 ; + } + } +return -ENODEV ; +} +static int tracing_open_options (struct inode *inode,struct file *filp) {struct trace_option_dentry *topt = inode->i_private;int ret; - ret =tracing_check_open_get_tr (topt->tr); + ret =trace_array_tracer_options_get (topt);if (ret)return ret;
@@ -9208,6 +9253,7 @@ create_trace_option_files(struct trace_array *tr, struct tracer *tracer) tr->topts = tr_topts; tr->topts[tr->nr_topts].tracer = tracer; tr->topts[tr->nr_topts].topts = topts; + tr->topts[tr->nr_topts].nr_topts = cnt; tr->nr_topts++;for (cnt =0 ; opts[cnt].name; cnt++) {
kernel/trace/trace.h +1 -0
@@ -202,6 +202,7 @@ struct array_buffer {struct trace_options {struct tracer *tracer;struct trace_option_dentry *topts; +int nr_topts; };struct trace_pid_list *trace_pid_list_alloc (void );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/2857 KEYS: encrypted: fix integer overflow of datablob_len
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 8697c431e297eb0d0ab13dda6bc172b48a34f05c ]
encrypted_key_alloc() stores datablob_len in a u16. It is computed from multiple string and payload lengths. If the result exceeds U16_MAX, the assignment truncates the allocation size. KASAN reports a 32760-byte slab-out-of-bounds write when __ekey_init() copies the master key description into the undersized buffer.
The total payload length stored in key->datalen is also a u16. Use check_add_overflow() to reject values that do not fit either destination, and use kzalloc_flex() for the flexible-array allocation.
--- security/keys/encrypted-keys/encrypted.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
security/keys/encrypted-keys/encrypted.c +14 -6
@@ -18,6 +18,7 @@#include <linux/parser.h> #include <linux/string.h> #include <linux/err.h> +#include <linux/overflow.h> #include <keys/user-type.h> #include <keys/trusted-type.h> #include <keys/encrypted-type.h>
@@ -606,6 +607,7 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, {struct encrypted_key_payload *epayload =NULL ;unsigned short datablob_len; +unsigned short payload_totallen;unsigned short decrypted_datalen;unsigned short payload_datalen;unsigned int encrypted_datalen;
@@ -659,16 +661,22 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, encrypted_datalen =roundup (decrypted_datalen, blksize); - datablob_len = format_len +1 +strlen (master_desc) +1 - +strlen (datalen) +1 + ivsize +1 + encrypted_datalen; +if (check_add_overflow (format_len +1 +strlen (master_desc) +1 + +strlen (datalen) +1 + ivsize +1 , + encrypted_datalen, &datablob_len)) +return ERR_PTR (-EINVAL ); + +if (check_add_overflow (datablob_len, + payload_datalen +HASH_SIZE +1 , + &payload_totallen)) +return ERR_PTR (-EINVAL ); - ret =key_payload_reserve (key, payload_datalen + datablob_len - +HASH_SIZE +1 ); + ret =key_payload_reserve (key, payload_totallen);if (ret <0 )return ERR_PTR (ret); - epayload =kzalloc (sizeof (*epayload) + payload_datalen + - datablob_len +HASH_SIZE +1 ,GFP_KERNEL ); + epayload =kzalloc (struct_size (epayload, payload_data, payload_totallen), +GFP_KERNEL );if (!epayload)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/2857 ALSA: core: Make snd_card_disconnect() return void
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 663f922fd7a9e9342dca512db339c7fb2b59b8e6 ]
All callers from other files ignore the return value of this function. And it can only ever return a non-zero value if the parameter card is NULL.
Move the check for card being NULL into snd_card_free_when_closed() to keep the previous behaviour. Note this isn't necessary for snd_card_disconnect_sync() because if card was NULL in there the dereference of card for dev_err() would oops the kernel. Replace this by an oops triggered by the dereference of card for spin_lock_irq().
Stable-dep-of: fd95e68df6fe ("ALSA: core: Fix potential UAF after asynchronous card release")
--- include/sound/core.h | 2 +- sound/core/init.c | 24 ++++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-)
include/sound/core.h +1 -1
@@ -286,7 +286,7 @@ int snd_devm_card_new(struct device *parent, int idx, const char *xid, struct module *module, size_t extra_size, struct snd_card **card_ret); -int snd_card_disconnect (struct snd_card *card); +void snd_card_disconnect (struct snd_card *card);void snd_card_disconnect_sync (struct snd_card *card);int snd_card_free (struct snd_card *card);int snd_card_free_when_closed (struct snd_card *card);
sound/core/init.c +8 -16
@@ -489,17 +489,17 @@ static const struct file_operations snd_shutdown_f_ops =* Note: The current implementation replaces all active file->f_op with special * dummy file operations (they do nothing except release). */ -int snd_card_disconnect (struct snd_card *card) +void snd_card_disconnect (struct snd_card *card) {struct snd_monitor_file *mfile;if (!card) -return -EINVAL ; +return ;spin_lock (&card->files_lock);if (card->shutdown) {spin_unlock (&card->files_lock); -return 0 ; +return ; } card->shutdown =1 ;
@@ -560,7 +560,6 @@ int snd_card_disconnect(struct snd_card *card)#ifdef CONFIG_PM snd_power_sync_ref (card);#endif -return 0 ; }EXPORT_SYMBOL (snd_card_disconnect);
@@ -575,15 +574,7 @@ EXPORT_SYMBOL(snd_card_disconnect);*/ void snd_card_disconnect_sync (struct snd_card *card) { -int err; - - err =snd_card_disconnect (card); -if (err <0 ) { -dev_err (card->dev, -"snd_card_disconnect error (%d), skipping sync\n" , - err); -return ; - } +snd_card_disconnect (card);spin_lock_irq (&card->files_lock); wait_event_lock_irq(card->remove_sleep,
@@ -629,9 +620,10 @@ static int snd_card_do_free(struct snd_card *card)*/ int snd_card_free_when_closed (struct snd_card *card) { -int ret =snd_card_disconnect (card); -if (ret) -return ret; +if (!card) +return -EINVAL ; + +snd_card_disconnect (card);put_device (&card->card_dev);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/2857 ALSA: core: Use guard() for locking
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 742ecf3ce1acdbcd0bc936178e1eaf346a0fd376 ]
We can simplify the code gracefully with new guard() macro and co for automatic cleanup of locks.
Only the code refactoring, and no functional changes.
Stable-dep-of: fd95e68df6fe ("ALSA: core: Fix potential UAF after asynchronous card release")
--- sound/core/init.c | 193 +++++++++++++++++++---------------------- sound/core/sound.c | 28 +++--- sound/core/sound_oss.c | 17 ++-- 3 files changed, 104 insertions(+), 134 deletions(-)
sound/core/init.c +88 -105
@@ -279,30 +279,31 @@ static int snd_card_init(struct snd_card *card, struct device *parent,if (xid)strscpy (card->id, xid,sizeof (card->id)); err =0 ; -mutex_lock (&snd_card_mutex); -if (idx <0 )/* first check the matching module-name slot */ - idx =get_slot_from_bitmask (idx, module_slot_match, module); -if (idx <0 )/* if not matched, assign an empty slot */ - idx =get_slot_from_bitmask (idx, check_empty_slot, module); -if (idx <0 ) - err = -ENODEV ; -else if (idx < snd_ecards_limit) { -if (test_bit (idx, snd_cards_lock)) - err = -EBUSY ;/* invalid */ - }else if (idx >=SNDRV_CARDS ) - err = -ENODEV ; + scoped_guard(mutex, &snd_card_mutex) { +if (idx <0 )/* first check the matching module-name slot */ + idx =get_slot_from_bitmask (idx, module_slot_match, module); +if (idx <0 )/* if not matched, assign an empty slot */ + idx =get_slot_from_bitmask (idx, check_empty_slot, module); +if (idx <0 ) + err = -ENODEV ; +else if (idx < snd_ecards_limit) { +if (test_bit (idx, snd_cards_lock)) + err = -EBUSY ;/* invalid */ + }else if (idx >=SNDRV_CARDS ) + err = -ENODEV ; +if (!err) { +set_bit (idx, snd_cards_lock);/* lock it */ +if (idx >= snd_ecards_limit) + snd_ecards_limit = idx +1 ;/* increase the limit */ + } + }if (err <0 ) { -mutex_unlock (&snd_card_mutex);dev_err (parent,"cannot find the slot for index %d (range 0-%i), error: %d\n" , - idx, snd_ecards_limit -1 , err); + idx, snd_ecards_limit -1 , err);if (!card->managed)kfree (card);/* manually free here, as no destructor called */ return err; } -set_bit (idx, snd_cards_lock);/* lock it */ -if (idx >= snd_ecards_limit) - snd_ecards_limit = idx +1 ;/* increase the limit */ -mutex_unlock (&snd_card_mutex); card->dev = parent; card->number = idx;#ifdef MODULE
@@ -381,11 +382,10 @@ struct snd_card *snd_card_ref(int idx) {struct snd_card *card; -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card)get_device (&card->card_dev); -mutex_unlock (&snd_card_mutex);return card; }EXPORT_SYMBOL_GPL (snd_card_ref);
@@ -393,12 +393,8 @@ EXPORT_SYMBOL_GPL(snd_card_ref);/* return non-zero if a card is already locked */ int snd_card_locked (int card) { -int locked; - -mutex_lock (&snd_card_mutex); - locked =test_bit (card, snd_cards_lock); -mutex_unlock (&snd_card_mutex); -return locked; +guard (mutex)(&snd_card_mutex); +return test_bit (card, snd_cards_lock); }static loff_t snd_disconnect_llseek (struct file *file,loff_t offset,int orig)
@@ -422,15 +418,15 @@ static int snd_disconnect_release(struct inode *inode, struct file *file) {struct snd_monitor_file *df =NULL , *_df; -spin_lock (&shutdown_lock); -list_for_each_entry (_df, &shutdown_files, shutdown_list) { -if (_df->file == file) { - df = _df; -list_del_init (&df->shutdown_list); -break ; + scoped_guard(spinlock, &shutdown_lock) { +list_for_each_entry (_df, &shutdown_files, shutdown_list) { +if (_df->file == file) { + df = _df; +list_del_init (&df->shutdown_list); +break ; + } } } -spin_unlock (&shutdown_lock);if (likely (df)) {if ((file->f_flags &FASYNC ) && df->disconnected_f_op->fasync)
@@ -496,27 +492,24 @@ void snd_card_disconnect(struct snd_card *card)if (!card)return ; -spin_lock (&card->files_lock); -if (card->shutdown) { -spin_unlock (&card->files_lock); -return ; - } - card->shutdown =1 ; + scoped_guard(spinlock, &card->files_lock) { +if (card->shutdown) +return ; + card->shutdown =1 ; -/* replace file->f_op with special dummy operations */ -list_for_each_entry (mfile, &card->files_list, list) { -/* it's critical part, use endless loop */ -/* we have no room to fail */ - mfile->disconnected_f_op = mfile->file->f_op; +/* replace file->f_op with special dummy operations */ +list_for_each_entry (mfile, &card->files_list, list) { +/* it's critical part, use endless loop */ +/* we have no room to fail */ + mfile->disconnected_f_op = mfile->file->f_op; -spin_lock (&shutdown_lock); -list_add (&mfile->shutdown_list, &shutdown_files); -spin_unlock (&shutdown_lock); + scoped_guard(spinlock, &shutdown_lock) +list_add (&mfile->shutdown_list, &shutdown_files); - mfile->file->f_op = &snd_shutdown_f_ops; -fops_get (mfile->file->f_op); + mfile->file->f_op = &snd_shutdown_f_ops; +fops_get (mfile->file->f_op); + } } -spin_unlock (&card->files_lock);#ifdef CONFIG_PM /* wake up sleepers here before other callbacks for avoiding potential
@@ -552,10 +545,10 @@ void snd_card_disconnect(struct snd_card *card) }/* disable fops (user space) operations for ALSA API */ -mutex_lock (&snd_card_mutex); - snd_cards[card->number] =NULL ; -clear_bit (card->number, snd_cards_lock); -mutex_unlock (&snd_card_mutex); + scoped_guard(mutex, &snd_card_mutex) { + snd_cards[card->number] =NULL ; +clear_bit (card->number, snd_cards_lock); + }#ifdef CONFIG_PM snd_power_sync_ref (card);
@@ -576,11 +569,10 @@ void snd_card_disconnect_sync(struct snd_card *card) {snd_card_disconnect (card); -spin_lock_irq (&card->files_lock); +guard (spinlock_irq)(&card->files_lock);wait_event_lock_irq (card->remove_sleep,list_empty (&card->files_list), card->files_lock); -spin_unlock_irq (&card->files_lock); }EXPORT_SYMBOL_GPL (snd_card_disconnect_sync);
@@ -782,9 +774,8 @@ void snd_card_set_id(struct snd_card *card, const char *nid)/* check if user specified own card->id */ if (card->id[0 ] !='\0' )return ; -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex);snd_card_set_id_no_lock (card, nid, nid); -mutex_unlock (&snd_card_mutex); }EXPORT_SYMBOL (snd_card_set_id);
@@ -812,14 +803,11 @@ static ssize_t id_store(struct device *dev, struct device_attribute *attr, }memcpy (buf1, buf, copy); buf1[copy] ='\0' ; -mutex_lock (&snd_card_mutex); -if (!card_id_ok (NULL , buf1)) { -mutex_unlock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); +if (!card_id_ok (NULL , buf1))return -EEXIST ; - }strcpy (card->id, buf1);snd_info_card_id_change (card); -mutex_unlock (&snd_card_mutex);return count; }
@@ -912,26 +900,27 @@ int snd_card_register(struct snd_card *card) err =snd_device_register_all (card);if (err <0 )return err; -mutex_lock (&snd_card_mutex); -if (snd_cards[card->number]) { -/* already registered */ -mutex_unlock (&snd_card_mutex); -return snd_info_card_register (card);/* register pending info */ - } -if (*card->id) { -/* make a unique id name from the given string */ -char tmpid[sizeof (card->id)]; -memcpy (tmpid, card->id,sizeof (card->id)); -snd_card_set_id_no_lock (card, tmpid, tmpid); - }else { -/* create an id from either shortname or longname */ -const char *src; - src = *card->shortname ? card->shortname : card->longname; -snd_card_set_id_no_lock (card, src, -retrieve_id_from_card_name (src)); + scoped_guard(mutex, &snd_card_mutex) { +if (snd_cards[card->number]) { +/* already registered */ +return snd_info_card_register (card);/* register pending info */ + } +if (*card->id) { +/* make a unique id name from the given string */ +char tmpid[sizeof (card->id)]; + +memcpy (tmpid, card->id,sizeof (card->id)); +snd_card_set_id_no_lock (card, tmpid, tmpid); + }else { +/* create an id from either shortname or longname */ +const char *src; + + src = *card->shortname ? card->shortname : card->longname; +snd_card_set_id_no_lock (card, src, +retrieve_id_from_card_name (src)); + } + snd_cards[card->number] = card; } - snd_cards[card->number] = card; -mutex_unlock (&snd_card_mutex); err =snd_info_card_register (card);if (err <0 )return err;
@@ -952,7 +941,7 @@ static void snd_card_info_read(struct snd_info_entry *entry,struct snd_card *card;for (idx = count =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card) { count++;
@@ -964,7 +953,6 @@ static void snd_card_info_read(struct snd_info_entry *entry,snd_iprintf (buffer," %s\n" , card->longname); } -mutex_unlock (&snd_card_mutex); }if (!count)snd_iprintf (buffer,"--- no soundcards ---\n" );
@@ -977,13 +965,12 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer)struct snd_card *card;for (idx = count =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card) { count++;snd_iprintf (buffer,"%s\n" , card->longname); } -mutex_unlock (&snd_card_mutex); }if (!count) {snd_iprintf (buffer,"--- no soundcards ---\n" );
@@ -1000,12 +987,11 @@ static void snd_card_module_info_read(struct snd_info_entry *entry,struct snd_card *card;for (idx =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card)snd_iprintf (buffer,"%2i %s\n" , idx, card->module->name); -mutex_unlock (&snd_card_mutex); } }#endif
@@ -1087,15 +1073,13 @@ int snd_card_file_add(struct snd_card *card, struct file *file) mfile->file = file; mfile->disconnected_f_op =NULL ;INIT_LIST_HEAD (&mfile->shutdown_list); -spin_lock (&card->files_lock); +guard (spinlock)(&card->files_lock);if (card->shutdown) { -spin_unlock (&card->files_lock);kfree (mfile);return -ENODEV ; }list_add (&mfile->list, &card->files_list);get_device (&card->card_dev); -spin_unlock (&card->files_lock);return 0 ; }EXPORT_SYMBOL (snd_card_file_add);
@@ -1117,22 +1101,21 @@ int snd_card_file_remove(struct snd_card *card, struct file *file) {struct snd_monitor_file *mfile, *found =NULL ; -spin_lock (&card->files_lock); -list_for_each_entry (mfile, &card->files_list, list) { -if (mfile->file == file) { -list_del (&mfile->list); -spin_lock (&shutdown_lock); -list_del (&mfile->shutdown_list); -spin_unlock (&shutdown_lock); -if (mfile->disconnected_f_op) -fops_put (mfile->disconnected_f_op); - found = mfile; -break ; + scoped_guard(spinlock, &card->files_lock) { +list_for_each_entry (mfile, &card->files_list, list) { +if (mfile->file == file) { +list_del (&mfile->list); + scoped_guard(spinlock, &shutdown_lock) +list_del (&mfile->shutdown_list); +if (mfile->disconnected_f_op) +fops_put (mfile->disconnected_f_op); + found = mfile; +break ; + } } +if (list_empty (&card->files_list)) +wake_up_all (&card->remove_sleep); } -if (list_empty (&card->files_list)) -wake_up_all (&card->remove_sleep); -spin_unlock (&card->files_lock);if (!found) {dev_err (card->dev,"card file remove problem (%p)\n" , file);return -ENOENT ;
sound/core/sound.c +11 -17
@@ -103,7 +103,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)if (minor >=ARRAY_SIZE (snd_minors))return NULL ; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex); mreg = snd_minors[minor];if (mreg && mreg->type == type) { private_data = mreg->private_data;
@@ -111,7 +111,6 @@ void *snd_lookup_minor_data(unsigned int minor, int type)get_device (&mreg->card_ptr->card_dev); }else private_data =NULL ; -mutex_unlock (&sound_mutex);return private_data; }EXPORT_SYMBOL (snd_lookup_minor_data);
@@ -150,17 +149,15 @@ static int snd_open(struct inode *inode, struct file *file)if (minor >=ARRAY_SIZE (snd_minors))return -ENODEV ; -mutex_lock (&sound_mutex); - mptr = snd_minors[minor]; -if (mptr ==NULL ) { - mptr =autoload_device (minor); -if (!mptr) { -mutex_unlock (&sound_mutex); -return -ENODEV ; + scoped_guard(mutex, &sound_mutex) { + mptr = snd_minors[minor]; +if (mptr ==NULL ) { + mptr =autoload_device (minor); +if (!mptr) +return -ENODEV ; } + new_fops =fops_get (mptr->f_ops); } - new_fops =fops_get (mptr->f_ops); -mutex_unlock (&sound_mutex);if (!new_fops)return -ENODEV ;replace_fops (file, new_fops);
@@ -276,7 +273,7 @@ int snd_register_device(int type, struct snd_card *card, int dev, preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex); minor =snd_find_free_minor (type, card, dev);if (minor <0 ) { err = minor;
@@ -291,7 +288,6 @@ int snd_register_device(int type, struct snd_card *card, int dev, snd_minors[minor] = preg; error: -mutex_unlock (&sound_mutex);if (err <0 )kfree (preg);return err;
@@ -312,7 +308,7 @@ int snd_unregister_device(struct device *dev)int minor;struct snd_minor *preg; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex);for (minor =0 ; minor <ARRAY_SIZE (snd_minors); ++minor) { preg = snd_minors[minor];if (preg && preg->dev == dev) {
@@ -322,7 +318,6 @@ int snd_unregister_device(struct device *dev)break ; } } -mutex_unlock (&sound_mutex);if (minor >=ARRAY_SIZE (snd_minors))return -ENOENT ;return 0 ;
@@ -362,7 +357,7 @@ static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buint minor;struct snd_minor *mptr; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex);for (minor =0 ; minor <SNDRV_OS_MINORS ; ++minor) { mptr = snd_minors[minor];if (!mptr)
@@ -380,7 +375,6 @@ static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_busnd_iprintf (buffer,"%3i: : %s\n" , minor,snd_device_type_name (mptr->type)); } -mutex_unlock (&sound_mutex); }int __init snd_minor_info_init (void )
sound/core/sound_oss.c +5 -12
@@ -29,7 +29,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)if (minor >=ARRAY_SIZE (snd_oss_minors))return NULL ; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); mreg = snd_oss_minors[minor];if (mreg && mreg->type == type) { private_data = mreg->private_data;
@@ -37,7 +37,6 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)get_device (&mreg->card_ptr->card_dev); }else private_data =NULL ; -mutex_unlock (&sound_oss_mutex);return private_data; }EXPORT_SYMBOL (snd_lookup_oss_minor_data);
@@ -106,7 +105,7 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev, preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); snd_oss_minors[minor] = preg; minor_unit =SNDRV_MINOR_OSS_DEVICE (minor);switch (minor_unit) {
@@ -130,7 +129,6 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev, goto __end; snd_oss_minors[track2] = preg; } -mutex_unlock (&sound_oss_mutex);return 0 ; __end:
@@ -139,7 +137,6 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,if (register1 >=0 )unregister_sound_special (register1); snd_oss_minors[minor] =NULL ; -mutex_unlock (&sound_oss_mutex);kfree (preg);return -EBUSY ; }
@@ -156,12 +153,10 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)return 0 ;if (minor <0 )return minor; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); mptr = snd_oss_minors[minor]; -if (mptr ==NULL ) { -mutex_unlock (&sound_oss_mutex); +if (mptr ==NULL )return -ENOENT ; - }switch (SNDRV_MINOR_OSS_DEVICE (minor)) {case SNDRV_MINOR_OSS_PCM : track2 =SNDRV_MINOR_OSS (cidx,SNDRV_MINOR_OSS_AUDIO );
@@ -176,7 +171,6 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)if (track2 >=0 ) snd_oss_minors[track2] =NULL ; snd_oss_minors[minor] =NULL ; -mutex_unlock (&sound_oss_mutex);/* call unregister_sound_special() outside sound_oss_mutex; * otherwise may deadlock, as it can trigger the release of a card
@@ -220,7 +214,7 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,int minor;struct snd_minor *mptr; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex);for (minor =0 ; minor <SNDRV_OSS_MINORS ; ++minor) { mptr = snd_oss_minors[minor];if (!mptr)
@@ -233,7 +227,6 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,snd_iprintf (buffer,"%3i: : %s\n" , minor,snd_oss_device_type_name (mptr->type)); } -mutex_unlock (&sound_oss_mutex); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/2857 ALSA: core: Fix potential UAF after asynchronous card release
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit fd95e68df6fe66344161a1329cbe5e5805e7b704 ]
Usually a sound driver releases the resources assigned to the card via snd_card_free(), and it synchronizes with the whole release procedure. However, when the card is released asynchronously via snd_card_free_when_closed() like USB-audio driver, the situation is slightly different; although the snd_card_disconnect() call at the disconnection guarantees that any newer accesses will be gated, the in-flight tasks might be still accessing to the underlying card->dev device even after the disconnection, which would cause a use-after-free in the end, as reported by fuzzers.
For addressing the bug above, this patch takes the refcount of card->dev at initialization of the card object, and releases at its
destructor. This assures the availability of the card->dev in its
whole lifecycle.
--- sound/core/init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/core/init.c +2 -1
@@ -304,7 +304,7 @@ static int snd_card_init(struct snd_card *card, struct device *parent,kfree (card);/* manually free here, as no destructor called */ return err; } - card->dev = parent; + card->dev =get_device (parent); card->number = idx;#ifdef MODULE WARN_ON (!module);
@@ -592,6 +592,7 @@ static int snd_card_do_free(struct snd_card *card)dev_warn (card->dev,"unable to free card info\n" );/* Not fatal error */ } +put_device (card->dev);if (card->release_completion)complete (card->release_completion);if (!managed)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/2857 phy: renesas: rcar-gen3-usb2: Avoid long delay in atomic context
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
[ Upstream commit 48e97c59a49c9e90270f5e3d221db253b76de5da ]
The OTG PHY initialization sequence needs to wait for 20 ms at a specific step, as described in commit 72c0339c115b ("phy: renesas:
rcar-gen3-usb2: follow the hardware manual procedure").
Commit 55a387ebb921 ("phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data") tried to address various problems in the rcar-gen3-usb2 driver and converted the mutex protecting HW register accesses to a spin lock, leaving, however, a long delay in the critical section protected by the spin lock. This may become a problem, especially on RT kernels.
To address this, release the spin lock before sleeping for 20 ms as required by the HW manual and reacquire it afterwards. To avoid other threads entering the critical section and configuring the HW while the software is waiting for the OTG initialization to complete, introduce the otg_initializing variable alongside the otg_init_done wait queue. Any other thread trying to configure the HW while the OTG PHY initialization is in progress waits for the wait queue instead of immediately returning errors to PHY users. The IRQs were also disabled while waiting for the OTG PHY initialization to complete, as the interrupt handler may also apply HW settings.
The OTG can only be initialized once. It is initialized by the first PHY that calls struct phy_ops::rcar_gen3_phy_usb2_init().
To avoid failures when multiple PHYs call struct phy_ops::rcar_gen3_phy_usb2_init() simultaneously, and the PHY responsible for initializing the OTG either fails or deinit quiqly and another PHY takes over the PHY init role), the code waiting for the channel->otg_init_done wait queue retries up to NUM_OF_PHYS times.
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 302 ++++++++++++++++++++--- 1 file changed, 261 insertions(+), 41 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +261 -41
@@ -25,6 +25,7 @@#include <linux/reset.h> #include <linux/string.h> #include <linux/usb/of.h> +#include <linux/wait.h> #include <linux/workqueue.h> /******* USB2.0 Host registers (original offset is +0x200) *******/
@@ -90,6 +91,13 @@#define USB2_OBINT_IDCHG_EN BIT(0)#define USB2_LINECTRL1_USB2_IDMON BIT(0) +/* +* The OTG initialization is expected to finish in 20ms. Choose a large enough +* timeout to avoid waiters exit prematurely the waiting section under heavy +* CPU load. +*/ +#define USB2_OTG_INIT_TIMEOUT msecs_to_jiffies(120) +#define NUM_OF_PHYS 4enum rcar_gen3_phy_index {PHY_INDEX_BOTH_HC ,
@@ -120,6 +128,7 @@ struct rcar_gen3_chan {struct rcar_gen3_phy rphys[NUM_OF_PHYS ];struct regulator *vbus;struct work_struct work; +wait_queue_head_t otg_init_done;spinlock_t lock;/* protects access to hardware and driver data structure. */ enum usb_dr_mode dr_mode;u32 obint_enable_bits;
@@ -127,6 +136,13 @@ struct rcar_gen3_chan {bool is_otg_channel;bool uses_otg_pins;bool soc_no_adp_ctrl; +/* +* The OTG can be initialized only once and needs to release the spinlock +* and wait for 20 ms due to hardware constraints. If a thread executes +* PHY configuration code while the OTG PHY is waiting for the 20 ms, the +* thread will have to wait for the OTG PHY initialization to complete. +*/ +bool otg_initializing; };struct rcar_gen3_phy_drv_data {
@@ -346,26 +362,58 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,struct rcar_gen3_chan *ch =dev_get_drvdata (dev);bool is_b_device;enum phy_mode cur_mode, new_mode; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret = -EIO ; -guard (spinlock_irqsave)(&ch->lock); +spin_lock_irqsave (&ch->lock, flags); -if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized (ch)) -return -EIO ; +if (!ch->is_otg_channel) + goto unlock; + +while (retries-- && ch->otg_initializing) { +spin_unlock_irqrestore (&ch->lock, flags); + + ret =wait_event_timeout (ch->otg_init_done, !ch->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto exit; + +spin_lock_irqsave (&ch->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (ch->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + +if (!rcar_gen3_is_any_otg_rphy_initialized (ch)) { + ret = -EIO ; + goto unlock; + } -if (sysfs_streq (buf,"host" )) +if (sysfs_streq (buf,"host" )) { new_mode =PHY_MODE_USB_HOST ; -else if (sysfs_streq (buf,"peripheral" )) + }else if (sysfs_streq (buf,"peripheral" )) { new_mode =PHY_MODE_USB_DEVICE ; -else -return -EINVAL ; + }else { + ret = -EINVAL ; + goto unlock; + }/* is_b_device: true is B-Device. false is A-Device. */ is_b_device =rcar_gen3_check_id (ch); cur_mode =rcar_gen3_get_phy_mode (ch);/* If current and new mode is the same, this returns the error */ -if (cur_mode == new_mode) -return -EINVAL ; +if (cur_mode == new_mode) { + ret = -EINVAL ; + goto unlock; + }if (new_mode ==PHY_MODE_USB_HOST ) {/* And is_host must be false */ if (!is_b_device)/* A-Peripheral */
@@ -379,7 +427,10 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,rcar_gen3_init_for_peri (ch); } -return count; +unlock: +spin_unlock_irqrestore (&ch->lock, flags); +exit: +return ret ?: count; } static ssize_t role_show(struct device *dev, struct device_attribute *attr,
@@ -395,14 +446,11 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RW (role); -static void rcar_gen3_init_otg (struct rcar_gen3_chan *ch) +static void rcar_gen3_init_otg_phase0 (struct rcar_gen3_chan *ch) {void __iomem *usb2_base = ch->base;u32 val; -if (!ch->is_otg_channel ||rcar_gen3_is_any_otg_rphy_initialized (ch)) -return ; -/* Should not use functions of read-modify-write a register */ val =readl (usb2_base +USB2_LINECTRL1 ); val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
@@ -416,7 +464,11 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) val =readl (usb2_base +USB2_ADPCTRL );writel (val |USB2_ADPCTRL_IDPULLUP , usb2_base +USB2_ADPCTRL ); } -mdelay (20 ); +} + +static void rcar_gen3_init_otg_phase1 (struct rcar_gen3_chan *ch) +{ +void __iomem *usb2_base = ch->base;writel (0xffffffff , usb2_base +USB2_OBINTSTA );writel (ch->obint_enable_bits, usb2_base +USB2_OBINTEN );
@@ -430,6 +482,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)void __iomem *usb2_base = ch->base;struct device *dev = ch->dev;irqreturn_t ret =IRQ_NONE ; +unsigned long flags;u32 status;pm_runtime_get_noresume (dev);
@@ -437,29 +490,98 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)if (pm_runtime_suspended (dev)) goto rpm_put; - scoped_guard(spinlock, &ch->lock) { - status =readl (usb2_base +USB2_OBINTSTA ); -if (status & ch->obint_enable_bits) { -dev_vdbg (dev,"%s: %08x\n" , __func__, status); -writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); -rcar_gen3_device_recognition (ch); - ret =IRQ_HANDLED ; - } +spin_lock_irqsave (&ch->lock, flags); + + status =readl (usb2_base +USB2_OBINTSTA ); +if (status & ch->obint_enable_bits) { +dev_vdbg (dev,"%s: %08x\n" , __func__, status); +writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); + + ret =IRQ_HANDLED ; + +/* This should not happen! */ +if (ch->otg_initializing) + goto unlock; + +rcar_gen3_device_recognition (ch); } +unlock: +spin_unlock_irqrestore (&ch->lock, flags); rpm_put:pm_runtime_put_noidle (dev);return ret; } +static void rcar_gen3_phy_usb2_irqs_mask_all (struct rcar_gen3_chan *channel, +u32 *masked_irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + *masked_irqs_bits = val & bitmask; + val &= ~bitmask; +writel (val, usb2_base +USB2_INT_ENABLE ); + +/* +* Don't report channel->obint_enable_bits IRQs. These are +* unmasked anyway in rcar_gen3_init_otg_phase1(). +*/ + val =readl (usb2_base +USB2_OBINTEN ); + val &= ~channel->obint_enable_bits; +writel (val, usb2_base +USB2_OBINTEN ); +} + +static void rcar_gen3_phy_usb2_irqs_unmask (struct rcar_gen3_chan *channel, +u32 irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + val &= ~bitmask; + val |= irqs_bits; +writel (val, usb2_base +USB2_INT_ENABLE ); +} +static int rcar_gen3_phy_usb2_init (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }/* Initialize USB2 part */ val =readl (usb2_base +USB2_INT_ENABLE );
@@ -472,12 +594,30 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) }/* Initialize otg part (only if we initialize a PHY with IRQs). */ -if (rphy->int_enable_bits) -rcar_gen3_init_otg (channel); +if (rphy->int_enable_bits && channel->is_otg_channel && + !rcar_gen3_is_any_otg_rphy_initialized (channel)) { +u32 masked_irq_bits =0 ; + +rcar_gen3_init_otg_phase0 (channel); +rcar_gen3_phy_usb2_irqs_mask_all (channel, &masked_irq_bits); + channel->otg_initializing = true; +spin_unlock_irqrestore (&channel->lock, flags); + +fsleep (20000 ); + +spin_lock_irqsave (&channel->lock, flags); +rcar_gen3_phy_usb2_irqs_unmask (channel, masked_irq_bits); +rcar_gen3_init_otg_phase1 (channel); + channel->otg_initializing = false; +wake_up_all (&channel->otg_init_done); + } rphy->initialized = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +return ret; }static int rcar_gen3_phy_usb2_exit (struct phy *p)
@@ -485,9 +625,32 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } rphy->initialized = false;
@@ -497,7 +660,9 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) val &= ~USB2_INT_ENABLE_UCOM_INTEN ;writel (val, usb2_base +USB2_INT_ENABLE ); -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); +return ret; }static int rcar_gen3_phy_usb2_power_on (struct phy *p)
@@ -505,8 +670,10 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; -int ret =0 ; +int ret;if (channel->vbus) { ret =regulator_enable (channel->vbus);
@@ -514,7 +681,27 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)return ret; } -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto disable_regulator; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }if (!rcar_gen3_are_all_rphys_power_off (channel)) goto out;
@@ -529,27 +716,59 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)/* The powered flag should be set for any other phys anyway */ rphy->powered = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +disable_regulator: +if (ret && channel->vbus) +regulator_disable (channel->vbus); + +return ret; }static int rcar_gen3_phy_usb2_power_off (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch; -int ret =0 ; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret; - scoped_guard(spinlock_irqsave, &channel->lock) { - rphy->powered = false; +spin_lock_irqsave (&channel->lock, flags); -if (rcar_gen3_are_all_rphys_power_off (channel)) { -u32 val =readl (channel->base +USB2_USBCTR ); +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); - val |=USB2_USBCTR_PLL_RST ; -writel (val, channel->base +USB2_USBCTR ); - } + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + + rphy->powered = false; + +if (rcar_gen3_are_all_rphys_power_off (channel)) { +u32 val =readl (channel->base +USB2_USBCTR ); + + val |=USB2_USBCTR_PLL_RST ; +writel (val, channel->base +USB2_USBCTR ); } -if (channel->vbus) +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +if (!ret && channel->vbus) ret =regulator_disable (channel->vbus);return ret;
@@ -763,6 +982,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) channel->obint_enable_bits =USB2_OBINT_IDCHG_EN ;spin_lock_init (&channel->lock); +init_waitqueue_head (&channel->otg_init_done);for (i =0 ; i <NUM_OF_PHYS ; i++) { channel->rphys[i].phy =devm_phy_create (dev,NULL , phy_data->phy_usb2_ops);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/2857 smb: client: cancel reconnect work in clean_demultiplex_info()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit c65eae6f61d1778ff7a82e4aae4080e26f486af1 ]
clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:
cifs_demultiplex_thread()
cifs_readv_from_socket()
cifs_reconnect()
__cifs_reconnect()
cifs_queue_server_reconn()
mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
clean_demultiplex_info()
cancel_delayed_work_sync(&server->echo) // echo canceled
// reconnect NOT canceled
kfree_sensitive(server) // server freed ...later, on cifsiod_wq:
smb2_reconnect_server()
server->srv_count // UAF read of freed server
Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -989,6 +989,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)spin_unlock (&server->srv_lock);cancel_delayed_work_sync (&server->echo); +cancel_delayed_work_sync (&server->reconnect);spin_lock (&server->srv_lock); server->tcpStatus = CifsExiting;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/2857 smb: client: fix rlist race and missing initialization
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 5f270f091256da1338c3631083e15d7f83cc05e1 ]
TCP_Server_Info.rlist is allocated via kzalloc which zeros both ->next and ->prev to NULL instead of pointing to itself, making list_empty() always return false and list_add() dereference a NULL ->prev pointer.
Also, cifs_signal_cifsd_for_reconnect() can be called concurrently from multiple cifsd threads, allowing the same server's rlist node to be added twice into the local list, corrupting it.
--- fs/smb/client/connect.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/connect.c +7 -0
@@ -195,6 +195,8 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, nserver = ses->chans[i].server;if (!nserver)continue ; +if (!list_empty (&nserver->rlist)) +continue ; nserver->srv_count++;list_add (&nserver->rlist, &reco); }
@@ -203,11 +205,15 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, } } +spin_lock (&cifs_tcp_ses_lock);list_for_each_entry_safe (server, nserver, &reco, rlist) {list_del_init (&server->rlist);set_need_reco (server); +spin_unlock (&cifs_tcp_ses_lock);cifs_put_tcp_session (server,0 ); +spin_lock (&cifs_tcp_ses_lock); } +spin_unlock (&cifs_tcp_ses_lock); }/*
@@ -1762,6 +1768,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,spin_lock_init (&tcp_ses->mid_lock);INIT_LIST_HEAD (&tcp_ses->tcp_ses_list);INIT_LIST_HEAD (&tcp_ses->smb_ses_list); +INIT_LIST_HEAD (&tcp_ses->rlist);INIT_DELAYED_WORK (&tcp_ses->echo, cifs_echo_request);INIT_DELAYED_WORK (&tcp_ses->reconnect, smb2_reconnect_server);mutex_init (&tcp_ses->reconnect_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/2857 Input: hp_sdc - shut down kicker timer on module exit
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 309731e95917125bbd13626a7a5600490a5bf44f ]
hp_sdc_kicker() rearms hp_sdc.kicker with mod_timer() after scheduling the tasklet. The module exit path uses timer_delete_sync(). That waits for a callback already running but can still leave the timer rearmed.
A callback can therefore leave the timer pending while hp_sdc_exit() tears down the driver, allowing timer activity to access dismantled driver state.
Use timer_shutdown_sync() for final teardown. It waits for a running callback and prevents rearming after module exit begins.
--- drivers/input/serio/hp_sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/serio/hp_sdc.c +1 -1
@@ -980,7 +980,7 @@ static void hp_sdc_exit(void)free_irq (hp_sdc.irq, &hp_sdc);write_unlock_irq (&hp_sdc.lock); -del_timer_sync (&hp_sdc.kicker); +timer_shutdown_sync (&hp_sdc.kicker);tasklet_kill (&hp_sdc.task);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/2857 wifi: mac80211: refuse to make a monitor active when it has no queue
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 2b04d6556964ae9f89819b86a0a7801e39c3aae5 ]
A monitor interface only gets a TXQ if it's created active, and one can't be added later. Setting the flag on a down interface is still allowed, so the driver is handed a monitor with no queue. ath9k dereferences it:
BUG: kernel NULL pointer dereference, address: 0000000000000066 RIP: 0010:ath_tx_node_init+0x49/0x170 [ath9k] ath9k_add_interface+0x10c/0x140 [ath9k] drv_add_interface+0x54/0x250 [mac80211] ieee80211_do_open+0x32f/0x800 [mac80211]
Reached with CAP_NET_ADMIN by "iw dev X set monitor active" followed by "ip link set X up". RTNL is held, so netlink operations block behind it.
Refuse the flag when there is no queue to give.
--- net/mac80211/cfg.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mac80211/cfg.c +5 -0
@@ -104,6 +104,11 @@ static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,return -EBUSY ; } +/* TXQs are reserved in ieee80211_if_add() and cannot be added later */ +if ((params->flags &MONITOR_FLAG_ACTIVE ) && + local->ops->wake_tx_queue && !sdata->vif.txq) +return -EOPNOTSUPP ; +/* also validate MU-MIMO change */ monitor_sdata =wiphy_dereference (local->hw.wiphy, local->monitor_sdata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/2857 i2c: imx: disable autosuspend on remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit e0c3e9d76adbe522dd420a766ce42d03ce887c29 ]
i2c_imx_probe() enables runtime PM autosuspend with pm_runtime_use_autosuspend(). The probe error path correctly undoes this setting with pm_runtime_dont_use_autosuspend(), but the normal remove path only disables runtime PM.
The runtime PM API requires pm_runtime_use_autosuspend() to be undone with pm_runtime_dont_use_autosuspend() at driver exit unless runtime PM was enabled with devm_pm_runtime_enable(). Leaving the autosuspend flag set therefore leaves the runtime PM state incompletely cleaned up after the driver is unbound.
Add the missing pm_runtime_dont_use_autosuspend() call to the remove path.
This issue was found by manual code inspection.
--- drivers/i2c/busses/i2c-imx.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/busses/i2c-imx.c +1 -0
@@ -1660,6 +1660,7 @@ static int i2c_imx_remove(struct platform_device *pdev)pm_runtime_put_noidle (&pdev->dev);pm_runtime_disable (&pdev->dev); +pm_runtime_dont_use_autosuspend (&pdev->dev);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/2857 ata: libahci_platform: Simplify code with for_each_child_of_node_scoped()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Zekun <[email protected]>
[ Upstream commit aa3ca1faf3222af7aaa194a910995820135fc54e ]
for_each_child_of_node_scoped() can put the device_node automatically. So let's use it to make the code simpler by avoiding the need to explicitly call of_node_put().
Stable-dep-of: 0d1cb83337f1 ("ata: libahci_platform: Fix device reference leak in ahci_platform_get_resources()")
--- drivers/ata/libahci_platform.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
drivers/ata/libahci_platform.c +5 -14
@@ -418,7 +418,6 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,static int ahci_platform_get_firmware (struct ahci_host_priv *hpriv,struct device *dev) { -struct device_node *child;u32 port;if (!of_property_read_u32 (dev->of_node,"hba-cap" , &hpriv->saved_cap))
@@ -427,14 +426,12 @@ static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv,of_property_read_u32 (dev->of_node,"ports-implemented" , &hpriv->saved_port_map); -for_each_child_of_node (dev->of_node, child) { +for_each_child_of_node_scoped (dev->of_node, child) {if (!of_device_is_available (child))continue ; -if (of_property_read_u32 (child,"reg" , &port)) { -of_node_put (child); +if (of_property_read_u32 (child,"reg" , &port))return -EINVAL ; - }if (!of_property_read_u32 (child,"hba-port-cap" , &hpriv->saved_port_cap[port])) hpriv->saved_port_cap[port] &=PORT_CMD_CAP ;
@@ -482,7 +479,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,int child_nodes, rc = -ENOMEM , enabled_ports =0 ;struct device *dev = &pdev->dev;struct ahci_host_priv *hpriv; -struct device_node *child;u32 mask_port_map =0 ;u32 max_port;
@@ -604,7 +600,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, }if (child_nodes) { -for_each_child_of_node (dev->of_node, child) { +for_each_child_of_node_scoped (dev->of_node, child) {u32 port;struct platform_device *port_dev__maybe_unused ;
@@ -613,7 +609,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,if (of_property_read_u32 (child,"reg" , &port)) { rc = -EINVAL ; -of_node_put (child); goto err_out; }
@@ -631,18 +626,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,if (port_dev) { rc =ahci_platform_get_regulator (hpriv, port, &port_dev->dev); -if (rc == -EPROBE_DEFER ) { -of_node_put (child); +if (rc == -EPROBE_DEFER ) goto err_out; - } }#endif rc =ahci_platform_get_phy (hpriv, port, dev, child); -if (rc) { -of_node_put (child); +if (rc) goto err_out; - } enabled_ports++; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/2857 ata: libahci_platform: Fix device reference leak in ahci_platform_get_resources()
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 0d1cb83337f13af082afb68b28d3fdfe29cde7fb ]
of_find_device_by_node() takes a reference on the port platform device, which is only used to look up its port regulator and is never released, neither on success nor on the error paths. Drop the reference with put_device() once the regulator has been obtained, which covers both the success and error paths.
--- drivers/ata/libahci_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libahci_platform.c +1 -1
@@ -622,10 +622,10 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,of_platform_device_create (child,NULL ,NULL ); port_dev =of_find_device_by_node (child); -if (port_dev) { rc =ahci_platform_get_regulator (hpriv, port, &port_dev->dev); +put_device (&port_dev->dev);if (rc == -EPROBE_DEFER ) goto err_out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/2857 drm/amdkfd: Avoid integer underflow with ffs in EOP ring size calc
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Francis <[email protected]>
[ Upstream commit c883d0a132d430ef7ebb23fd94323be94d0fbdb8 ]
The low 6 bits of cp_hqd_eop_control store the base-2 logarithm of the EOP ring size. This was calculated as
ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1
But ffs can in theory return 1 or 0, so this could underflow (although in practice the ring buffer size cannot be less than 4096).
Change this to
ffs(q->eop_ring_buffer_size / sizeof(unsigned int) / 4)
using properties of logarithms.
--- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +1 -1
@@ -192,7 +192,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control =min (0xA , -ffs (q->eop_ring_buffer_size /sizeof (unsigned int )) -1 -1 ); +ffs (q->eop_ring_buffer_size /sizeof (unsigned int ) /4 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +1 -1
@@ -218,7 +218,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control =min (0xA , -ffs (q->eop_ring_buffer_size /sizeof (unsigned int )) -1 -1 ); +ffs (q->eop_ring_buffer_size /sizeof (unsigned int ) /4 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/2857 drm/amdkfd: Avoid integer underflow in EOP ring size calculation.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Francis <[email protected]>
[ Upstream commit 8ee521b8b189799e361d4233c5180ba56656d4d4 ]
The low 6 bits of cp_hqd_eop_control store the base-2 logarithm of the EOP ring size. This was calculated as
order_base_2(q->eop_ring_buffer_size / 4) - 1
But order_base_2 can in theory return 0, so this could underflow (although in practice the ring buffer size cannot be less than 4096).
Change this to
order_base_2(q->eop_ring_buffer_size / 8)
using properties of logarithms.
Also add to the above comment to make the mathematics more clear.
--- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +5 -1
@@ -237,6 +237,10 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,1 <<CP_HQD_IB_CONTROL__IB_EXE_DISABLE__SHIFT ;/* +* The lowest 6 bits of eop_control store the EOP ring size. If +* their value is X, the ring size is 2^(X + 1) dwords, or +* 2^(X + 3) bytes. +* * HW does not clamp this field correctly. Maximum EOP queue size * is constrained by per-SE EOP done signal count, which is 8-bit. * Limit is 0xFF EOP entries (= 0x7F8 dwords). CP will not submit
@@ -244,7 +248,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control =min (0xA , -order_base_2 (q->eop_ring_buffer_size /4 ) -1 ); +order_base_2 (q->eop_ring_buffer_size /8 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +4 -1
@@ -204,6 +204,9 @@ static void __update_mqd(struct mqd_manager *mm, void *mqd, mtype <<CP_HQD_IB_CONTROL__MTYPE__SHIFT ;/* +* The lowest 6 bits of eop_control store the EOP ring size. If +* their value is X, the ring size is 2^(X + 1) dwords, or +* 2^(X + 3) bytes. * HW does not clamp this field correctly. Maximum EOP queue size * is constrained by per-SE EOP done signal count, which is 8-bit. * Limit is 0xFF EOP entries (= 0x7F8 dwords). CP will not submit
@@ -211,7 +214,7 @@ static void __update_mqd(struct mqd_manager *mm, void *mqd,* is safe, giving a maximum field value of 0xA. */ m->cp_hqd_eop_control |=min (0xA , -order_base_2 (q->eop_ring_buffer_size /4 ) -1 ); +order_base_2 (q->eop_ring_buffer_size /8 )); m->cp_hqd_eop_base_addr_lo =lower_32_bits (q->eop_ring_buffer_address >>8 ); m->cp_hqd_eop_base_addr_hi =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/2857 drm/amdgpu: fix rmmio iounmap skipped on device removal
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengjun Yao <[email protected]>
[ Upstream commit 5155002b03b24ba3ef91c5c313b8cf0171b24904 ]
amdgpu_pci_remove() calls drm_dev_unplug() before fini_sw(), so drm_dev_enter() is already false there and the iounmap() guarded by it is skipped. This .remove path runs on both hot-unplug and plain rmmod, so the register BAR ioremap mapping leaks one instance per unload.
Unmap rmmio unconditionally (guard only on non-NULL) and drop the now unused idx.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -4
@@ -4189,7 +4189,6 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)void amdgpu_device_fini_sw (struct amdgpu_device *adev) { -int idx;bool px;amdgpu_device_ip_fini (adev);
@@ -4221,12 +4220,10 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)if ((adev->pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA )vga_client_unregister (adev->pdev); -if (drm_dev_enter (adev_to_drm (adev), &idx)) { - +if (adev->rmmio) {iounmap (adev->rmmio); adev->rmmio =NULL ;amdgpu_device_doorbell_fini (adev); -drm_dev_exit (idx); }if (IS_ENABLED (CONFIG_PERF_EVENTS ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/2857 x86/microcode/intel: Reject problematic loading on Granite Rapids systems
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chang S. Bae <[email protected]>
[ Upstream commit e7d3e2f46dd5a69046e6d95a0f189155a5516b93 ]
Microcode updates can usually jump revisions. However, there is an erratum on Granite Rapids systems. If they "jump over" revision 0x1000405, they result in an #MC. Avoid it.
--- arch/x86/kernel/cpu/microcode/intel.c | 55 ++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/intel.c +54 -1
@@ -261,6 +261,23 @@ static int microcode_sanity_check(void *mc, int print_err)return 0 ; } +static bool revision_is_safe (struct cpu_signature *sig,u32 rev) +{ +/* +* Erratum GNR98 can cause #MCs if "jumping over" revision 0x1000405. +* Avoid the jumps. +*/ +if (x86_family (sig->sig) ==6 && +x86_model (sig->sig) ==INTEL_FAM6_GRANITERAPIDS_X && +x86_stepping (sig->sig) ==1 && + sig->pf &0x95 && + sig->rev <0x1000405 && + rev >0x1000405 ) +return false; + +return true; +} +/* * Get microcode matching with BSP's model. Only CPUs with the same model as * BSP can stay in the platform.
@@ -292,8 +309,19 @@ scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save)continue ; } +if (!revision_is_safe (&uci->cpu_sig, mc_header->rev)) { + data += mc_size; +continue ; + } +if (save) { -save_microcode_patch (uci, data, mc_size); +/* +* Only cache what the BSP could have loaded: a newer +* revision was rejected as unsafe and must not be +* applied on resume or hotplug. +*/ +if (mc_header->rev <= uci->cpu_sig.rev) +save_microcode_patch (uci, data, mc_size); goto next; }
@@ -629,6 +657,11 @@ void load_ucode_intel_ap(void) *iup = patch; } +intel_cpu_collect_info (&uci); + +if (!revision_is_safe (&uci.cpu_sig, (*iup)->hdr.rev)) +return ; + uci.mc = *iup;apply_microcode_early (&uci, true);
@@ -646,6 +679,9 @@ static struct microcode_intel *find_patch(struct ucode_cpu_info *uci)if (phdr->rev <= uci->cpu_sig.rev)continue ; +if (!revision_is_safe (&uci->cpu_sig, phdr->rev)) +continue ; +if (!find_matching_signature (phdr, uci->cpu_sig.sig, uci->cpu_sig.pf))
@@ -706,6 +742,7 @@ static enum ucode_state apply_microcode_intel(int cpu)struct cpuinfo_x86 *c = &cpu_data (cpu);bool bsp = c->cpu_index == boot_cpu_data.cpu_index;struct microcode_intel *mc; +struct cpu_signature sig;enum ucode_state ret;static int prev_rev;u32 rev;
@@ -733,6 +770,17 @@ static enum ucode_state apply_microcode_intel(int cpu) goto out; } +/* +* uci->cpu_sig.rev can be stale, e.g. on resume. Check against the +* revision the CPU is really running. +*/ + sig = uci->cpu_sig; + sig.rev = rev; +if (!revision_is_safe (&sig, mc->hdr.rev)) { + ret =UCODE_NFOUND ; + goto out; + } +/* * Writeback and invalidate caches before updating microcode to avoid * internal issues depending on what the microcode is updating.
@@ -818,6 +866,11 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)break ; } +if (!revision_is_safe (&uci->cpu_sig, mc_header.rev)) { +pr_err_once ("Erratum GNR98: skipping revision 0x%x.\n" , mc_header.rev); +continue ; + } + csig = uci->cpu_sig.sig; cpf = uci->cpu_sig.pf;if (has_newer_microcode (mc, csig, cpf, new_rev)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/2857 mm/hugetlb: do not dissolve gigantic pages without runtime support
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Longlong Xia <[email protected]>
[ Upstream commit a363c62a653cc8b3e21da9545fa4e028ef50f9c3 ]
dissolve_free_hugetlb_folio() doesn't check hstate_is_gigantic_no_runtime(h) though remove_hugetlb_folio()/ update_and_free_hugetlb_folio() silently bail for such folios, so it frees a still-listed folio and, on vmemmap restore failure, the add_hugetlb_folio() rollback corrupts the free list.
--- mm/hugetlb.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
mm/hugetlb.c +10 -0
@@ -2352,6 +2352,16 @@ int dissolve_free_huge_page(struct page *page)if (!page_count (page)) {struct page *head =compound_head (page);struct hstate *h =page_hstate (head); + +/* +* remove_hugetlb_page()/update_and_free_page() bail +* for gigantic hstates without runtime support, so dissolving one +* here would leave it on the free list and, on vmemmap restore +* failure, the add_hugetlb_page() rollback corrupts that list. +*/ +if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ()) + goto out; +if (!available_huge_pages (h)) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/2857 mm/damon/vaddr: avoid hw-driven pte updates during damon_hugetlb_mkold()
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 39c0ceedd54557bdc1542de08d22b2ed33e534e4 ]
damon_hugetlb_mkold() reads the page table entry into a local variable, unsets the accessed bit in the variable, and updates the page table entry with the updated variable value. If hardware updates the same page table entry in parallel, the hw updates could be lost. For example, hardware-updated dirty bits might be lost.
Avoid the parallel updates by clearing the page table entry when reading it together, using huge_ptep_get_and_clear(). If a parallel write to the memory is made after the clearing, the hw will see the page table entry is cleared, trigger page fault and wait until it is handled. The page fault handling will wait for damon_hugetlb_mkold() due to the page table lock.
Because hugetlbfs is an in-memory file system and hugetlb pages cannot be reclaimed, no critical issue is expected to my best knowledge. But definitely this is a nasty bug that should be fixed sooner rather than later.
The issue was discovered [1] by Sashiko.
--- mm/damon/vaddr.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
mm/damon/vaddr.c +12 -5
@@ -332,6 +332,17 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr, }#ifdef CONFIG_HUGETLB_PAGE +static bool damon_hugetlb_ptep_mkold (pte_t *pte,struct mm_struct *mm, +struct vm_area_struct *vma,unsigned long addr,pte_t *entry) +{ +if (!pte_young (*entry)) +return false; + *entry =huge_ptep_get_and_clear (mm, addr, pte); + *entry =pte_mkold (*entry); +set_huge_pte_at (mm, addr, pte, *entry); +return true; +} +static void damon_hugetlb_mkold (pte_t *pte,struct mm_struct *mm,struct vm_area_struct *vma,unsigned long addr) {
@@ -341,11 +352,7 @@ static void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,get_page (page); -if (pte_young (entry)) { - referenced = true; - entry =pte_mkold (entry); -set_huge_pte_at (mm, addr, pte, entry); - } + referenced =damon_hugetlb_ptep_mkold (pte, mm, vma, addr, &entry);#ifdef CONFIG_MMU_NOTIFIER if (mmu_notifier_clear_young(mm, addr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/2857 smb: client: delete compound mids on send failure before unlock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adarsh Das <[email protected]>
[ Upstream commit 8f6f8a48399f82f4a83f7b9f25b9707e0062a4f9 ]
When sending a compound request fails, smb_send_rqst() kicks off a reconnect. compound_send_recv() still has those mids on pending_mid_q, but it unlocks the server without removing them first.
During reconnect, cifs_abort_connection() walks pending_mid_q and runs each mid callback. With no response yet, those callbacks return credits and drop in_flight. Then compound_send_recv()'s send-error path returns the same credits again. in_flight ends up decremented twice and smb2_add_credits() WARNs.
syzbot hits this during SMB2_negotiate when the socket send fails.
cifs_call_async() already calls delete_mid() before unlock on send failure. Do the same for compound chains and set cancelled_mid[] so the
out: path does not delete them again.
--- fs/smb/client/transport.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/smb/client/transport.c +4 -0
@@ -1200,6 +1200,10 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,if (rc <0 ) {revert_current_mid (server, num_rqst); server->sequence_number -=2 ; +for (i =0 ; i < num_rqst; i++) { +delete_mid (midQ[i]); + cancelled_mid[i] = true; + } }cifs_server_unlock (server);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 444/2857 i2c: qcom-cci: Stop complaining about DT set clock rate
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryan O'Donoghue <[email protected]>
[ Upstream commit 8284750a182937bf805f703311501730f02eb40e ]
It is common practice in the downstream and upstream CCI dt to set CCI clock rates to 19.2 MHz. It appears to be fairly common for initial code to set the CCI clock rate to 37.5 MHz.
Applying the widely used CCI clock rates from downstream ought not to cause warning messages in the upstream kernel where our general policy is to usually copy downstream hardware clock rates across the range of Qualcomm drivers.
Drop the warning it is pervasive across CAMSS users but doesn't add any information or warrant any changes to the DT to align the DT clock rate to the bootloader clock rate.
Stable-dep-of: 7362a1553eb0 ("i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()")
--- drivers/i2c/busses/i2c-qcom-cci.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +0 -8
@@ -603,14 +603,6 @@ static int cci_probe(struct platform_device *pdev) } } -if (cci_clk_rate != cci->data->cci_clk_rate) { -/* cci clock set by the bootloader or via assigned clock rate -* in DT. -*/ -dev_warn (dev,"Found %lu cci clk rate while %lu was expected\n" , - cci_clk_rate, cci->data->cci_clk_rate); - } - ret =cci_enable_clocks (cci);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 445/2857 i2c: qcom-cci: Remove the unused variable cci_clk_rate
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiapeng Chong <[email protected]>
[ Upstream commit b88c79699d72caa947ecaae85839b3563662ccce ]
Variable cci_clk_rate is not effectively used, so delete it.
drivers/i2c/busses/i2c-qcom-cci.c:526:16: warning: variable ‘cci_clk_rate’ set but not used.
Stable-dep-of: 7362a1553eb0 ("i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()")
--- drivers/i2c/busses/i2c-qcom-cci.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +0 -9
@@ -523,7 +523,6 @@ static const struct dev_pm_ops qcom_cci_pm = {static int cci_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -unsigned long cci_clk_rate =0 ;struct device_node *child;struct resource *r;struct cci *cci;
@@ -595,14 +594,6 @@ static int cci_probe(struct platform_device *pdev) } cci->nclocks = ret; -/* Retrieve CCI clock rate */ -for (i =0 ; i < cci->nclocks; i++) { -if (!strcmp (cci->clocks[i].id,"cci" )) { - cci_clk_rate =clk_get_rate (cci->clocks[i].clk); -break ; - } - } - ret =cci_enable_clocks (cci);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 446/2857 i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Zhenlong <[email protected]>
[ Upstream commit 7362a1553eb09a8cdf8be7e509bd5309a8342486 ]
The of_node_put() matching of_node_get() runs after i2c_del_adapter(), whose trailing memset() zeroes adap->dev and thus adap->dev.of_node, making the put a no-op and leaking the node on every adapter removal and error cleanup.
Use a devm action: the pointer is captured at registration, out of reach of that memset(), and devres runs the put once on probe failure and detach, replacing the three manual of_node_put() calls. The setup loop uses the scoped iterator form so the child node is released automatically if devm_add_action_or_reset() fails mid-loop.
--- drivers/i2c/busses/i2c-qcom-cci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +11 -9
@@ -520,10 +520,14 @@ static const struct dev_pm_ops qcom_cci_pm = { SET_RUNTIME_PM_OPS(cci_suspend_runtime, cci_resume_runtime, NULL) }; +static void cci_put_of_node (void *data) +{ +of_node_put (data); +} +static int cci_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct device_node *child;struct resource *r;struct cci *cci;int ret, i;
@@ -539,7 +543,7 @@ static int cci_probe(struct platform_device *pdev)if (!cci->data)return -ENOENT ; -for_each_available_child_of_node (dev->of_node, child) { +for_each_available_child_of_node_scoped (dev->of_node, child) {struct cci_master *master;u32 idx;
@@ -560,6 +564,9 @@ static int cci_probe(struct platform_device *pdev) master->adap.algo = &cci_algo; master->adap.dev.parent = dev; master->adap.dev.of_node =of_node_get (child); + ret =devm_add_action_or_reset (dev, cci_put_of_node, child); +if (ret) +return ret; master->master = idx; master->cci = cci;
@@ -634,10 +641,8 @@ static int cci_probe(struct platform_device *pdev)continue ; ret =i2c_add_adapter (&cci->master[i].adap); -if (ret <0 ) { -of_node_put (cci->master[i].adap.dev.of_node); +if (ret <0 ) goto error_i2c; - } }return 0 ;
@@ -645,10 +650,8 @@ static int cci_probe(struct platform_device *pdev) error_i2c:for (--i ; i >=0 ; i--) { -if (cci->master[i].cci) { +if (cci->master[i].cci)i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node); - } }disable_irq (cci->irq);
@@ -673,7 +676,6 @@ static int cci_remove(struct platform_device *pdev)for (i =0 ; i < cci->data->num_masters; i++) {if (cci->master[i].cci) {i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node);cci_halt (cci, i); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 447/2857 smb: client: clean up failed cached directory opens
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
[ Upstream commit d2ff5fb93ea83034025850266b5eed391f96b825 ]
open_cached_dir() sends CREATE and QUERY_INFO as a compound request. If the CREATE succeeds but a later command returns an error, the function must retain the CREATE FID so common cleanup can issue SMB2_close(). It also must not treat a response error as a valid CREATE.
Validate the CREATE response before using its fields, record the FIDs, and mark the handle open before handling errors from later compound commands. Move the -EREMCHG reconnect handling before response validation so a missing response does not hide the reconnect request. Count the handle when it is marked open; confirmed close responses decrement the counter, while existing close retry behavior remains best effort on transport failures.
--- fs/smb/client/cached_dir.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
fs/smb/client/cached_dir.c +23 -10
@@ -8,6 +8,7 @@#include <linux/namei.h> #include "cifsglob.h" #include "cifsproto.h" +#include "smb2status.h" #include "cifs_debug.h" #include "smb2proto.h" #include "cached_dir.h"
@@ -277,24 +278,37 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, rc =compound_send_recv (xid, ses, server, flags,2 , rqst, resp_buftype, rsp_iov); -if (rc) { -if (rc == -EREMCHG ) { - tcon->need_reconnect = true; -pr_warn_once ("server share %s deleted\n" , - tcon->tree_name); - } - goto oshr_free; +if (rc == -EREMCHG ) { + tcon->need_reconnect = true; +pr_warn_once ("server share %s deleted\n" , + tcon->tree_name); } - cfid->is_open = true; -spin_lock (&cfids->cfid_list_lock); +if (!rsp_iov[0 ].iov_base || rsp_iov[0 ].iov_len <sizeof (*o_rsp)) { +if (!rc) + rc = -EIO ; + goto oshr_free; + } o_rsp = (struct smb2_create_rsp *)rsp_iov[0 ].iov_base; +if (o_rsp->hdr.Status !=STATUS_SUCCESS ) { +if (!rc) + rc = -EIO ; + goto oshr_free; + } + oparms.fid->persistent_fid = o_rsp->PersistentFileId; oparms.fid->volatile_fid = o_rsp->VolatileFileId;#ifdef CONFIG_CIFS_DEBUG2 oparms.fid->mid =le64_to_cpu (o_rsp->hdr.MessageId);#endif /* CIFS_DEBUG2 */ + cfid->is_open = true; +atomic_inc (&tcon->num_remote_opens); + +if (rc) + goto oshr_free; + +spin_lock (&cfids->cfid_list_lock); rc = -EINVAL ;if (o_rsp->OplockLevel !=SMB2_OPLOCK_LEVEL_LEASE ) {
@@ -367,7 +381,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,free_cached_dir (cfid); }else { *ret_cfid = cfid; -atomic_inc (&tcon->num_remote_opens); }kfree (utf16_path);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 448/2857 KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails
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 10180a277549339020b08000206092c07e0bff5a ]
Re-pend GET_NESTED_STATE_PAGES before exiting to userspace if getting the nested pages fails in the KVM_RUN path. If userspace re-runs the vCPU, and vmcs02 holds valid PFNs from the *previous* run of L2, then KVM could re-enter L2 with stale, unpinned PFNs mapped into e.g. the vAPIC page.
Note, both SVM and VMX (as of commit 11722439fb20 ("KVM: nVMX: Ensure KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit") ensure the request is cleared on VM-Exit (including the "forced" case), i.e. there is no risk of double-mapping due to emulated VMLAUNCH/VMRESUME/VMRUN *and* the request trying to map the nested pages.
--- arch/x86/kvm/x86.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/x86.c +1 -0
@@ -10655,6 +10655,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) }if (kvm_check_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu)) {if (unlikely (!kvm_x86_ops.nested_ops->get_nested_state_pages (vcpu))) { +kvm_make_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu); r =0 ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 449/2857 KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages() error paths
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 c1214f293d77c6e425a379f90d09bdb4815993a8 ]
Fill kvm_run with "internal error, emulation" in the common error handling paths for getting nested state pages, as requiring each check to manually fill kvm_run is error prone and requires a non-trivial amount of copy+paste.
Specifically, both SVM and VMX fail to fill kvm_run if load_pdptrs() fails, and SVM fails to fill kvm_run if kvm_hv_verify_vp_assist() fails. If those flows fail, the *best* case scenario is that KVM will exit to userspace with KVM_EXIT_UNKNOWN. The worst case scenario is that KVM exits with a stale exit_reason and confuses userspace.
Note, SVM never exits to userspace if something goes sideways when dealing with vmcb12 assets while emulating VMRUN, i.e. lack of SVM-specific code is not a bug.
--- arch/x86/kvm/svm/nested.c | 7 +------ arch/x86/kvm/vmx/nested.c | 15 +++++---------- arch/x86/kvm/x86.c | 3 +++ 3 files changed, 9 insertions(+), 16 deletions(-)
arch/x86/kvm/svm/nested.c +1 -6
@@ -1729,13 +1729,8 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)if (CC (!load_pdptrs (vcpu, vcpu->arch.cr3)))return false; -if (!nested_svm_vmrun_msrpm (svm)) { - vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; - vcpu->run->internal.suberror = -KVM_INTERNAL_ERROR_EMULATION ; - vcpu->run->internal.ndata =0 ; +if (!nested_svm_vmrun_msrpm (svm))return false; - }return true; }
arch/x86/kvm/vmx/nested.c +5 -10
@@ -3220,10 +3220,6 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu) }else {pr_debug_ratelimited ("%s: no backing for APIC-access address in vmcs12\n" , __func__); - vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; - vcpu->run->internal.suberror = -KVM_INTERNAL_ERROR_EMULATION ; - vcpu->run->internal.ndata =0 ;return false; } }
@@ -3287,11 +3283,6 @@ static bool vmx_get_nested_state_pages(struct kvm_vcpu *vcpu)if (!nested_get_evmcs_page (vcpu)) {pr_debug_ratelimited ("%s: enlightened vmptrld failed\n" , __func__); - vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; - vcpu->run->internal.suberror = -KVM_INTERNAL_ERROR_EMULATION ; - vcpu->run->internal.ndata =0 ; -return false; }
@@ -3693,8 +3684,12 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch) vmentry_failed: vmx->nested.nested_run_pending =0 ; -if (status ==NVMX_VMENTRY_KVM_INTERNAL_ERROR ) +if (status ==NVMX_VMENTRY_KVM_INTERNAL_ERROR ) { + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ; + vcpu->run->internal.ndata =0 ;return 0 ; + }if (status ==NVMX_VMENTRY_VMEXIT )return 1 ;WARN_ON_ONCE (status !=NVMX_VMENTRY_VMFAIL );
arch/x86/kvm/x86.c +3 -0
@@ -10655,6 +10655,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) }if (kvm_check_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu)) {if (unlikely (!kvm_x86_ops.nested_ops->get_nested_state_pages (vcpu))) { + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ; + vcpu->run->internal.ndata =0 ;kvm_make_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu); r =0 ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 450/2857 virtio_net: copy zerocopy frags in start_xmit without NAPI
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
[ Upstream commit 07e1a9408b6c2f9d0cfb757b67dabb52da7a32b2 ]
Virtio-net without NAPI frees completed skbs lazily on the next start_xmit. Senders waiting for in-flight zerocopy buffers can deadlock if they cannot transmit more packets, as then no completed packets will be freed.
When !use_napi, virtio-net already calls skb_orphan to avoid waiting up for transmitted skbs to be freed. For zerocopy packets that require deep copying on orphan (i.e. those that do not set SKBFL_DONT_ORPHAN, such as PACKET_TX_RING), call skb_orphan_frags before orphaning to release the buffers.
This fixes the tpacket_snd slot reuse bug on skb_orphan for virtio-net, and prevents PACKET_TX_RING from running out of slots.
This fix also touches vhost_net zerocopy packets, which also do not set SKBFL_DONT_ORPHAN. This is fine: vhost_net packets only encounter virtio-net in nested virtualization, and only if napi_tx is explicitly disabled (it has been default-enabled since Linux 4.12). In that rare case, copying the frags is desirable anyway to prevent holding guest descriptors pinned across unbounded intervals.
This is a prerequisite for the next patch, which converts PACKET_TX_RING to standard zerocopy completion. Without this patch first, a bounded ring sender can stall indefinitely behind a virtio-net virtqueue that cannot reclaim.
--- drivers/net/virtio_net.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/virtio_net.c +8 -0
@@ -1910,6 +1910,13 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) }while (use_napi && kick &&unlikely (!virtqueue_enable_cb_delayed (sq->vq))); +if (!use_napi && +unlikely (skb_orphan_frags (skb,GFP_ATOMIC ))) { + dev->stats.tx_dropped++; +dev_kfree_skb_any (skb); + goto kick_vq; + } +/* timestamp packet in software */ skb_tx_timestamp (skb);
@@ -1960,6 +1967,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) } } +kick_vq:if (kick ||netif_xmit_stopped (txq)) {if (virtqueue_kick_prepare (sq->vq) &&virtqueue_notify (sq->vq)) {u64_stats_update_begin (&sq->stats.syncp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 451/2857 packet: use ubuf_info completion for TX_RING packets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
[ Upstream commit 9518405613863d0bf0700927a21367f5942cf058 ]
tpacket_snd sends skbs with frags pointing into its ring slots. Slots are released when skb->destructor is called.
A call to skb_orphan calls skb->destructor before the skb is freed. This can cause the slot to be reused while still linked into the skb.
Switch to standard zerocopy completion (ubuf_info) so the slot is only released once all references to the payload are freed or copied. Restore skb->destructor to standard sock_wfree.
The ubuf_info completion callback can be called with a NULL skb, but only from net_zcopy_put and related API, used by zerocopy implementations that hold their own reference on the uarg, such as MSG_ZEROCOPY. This uarg is only ever completed from skb_zcopy_clear, so skb is always set.
To prevent userspace from aliasing in-flight state on shared ring slots, allocate tpacket_uarg per packet, rather than per slot. This adds a small allocation to the transmit path. Use standard kmalloc to allow backporting to stable kernels.
The uarg holds an sk_wmem_alloc reference, rather than an sk_refcnt reference. packet_free_tx_ring waits on sk_wmem_alloc before freeing the ring pages. Always allocate vec->deferred for tx_ring so page-backed rings also wait on sk_wmem_alloc when skb_copy_ubufs drops page refs before calling tpacket_ubuf_complete.
Drop the tx_ring.pg_vec test that tpacket_destruct_skb performed before accessing the slot. The sk_wmem_alloc reference now guarantees that the slot is valid. The test is also not sufficient by itself, as it reads pg_vec without pg_vec_lock, so it can race with packet_set_ring.
As a result a slot is released when its payload is copied, which can be before transmission (e.g., in skb_orphan_frags_rx). If copied before skb_tx_timestamp() is called, no slot timestamp is recorded, similar to when skb_orphan() was called early in the datapath before this patch.
Revert the now unused previous skb_zcopy_.._nouarg infra.
Depends on commit 992cc9f94ca9 ("net/packet: defer vmalloc TX_RING free until skbs finish").
--- include/linux/skbuff.h | 19 +------- net/packet/af_packet.c | 98 ++++++++++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 56 deletions(-)
include/linux/skbuff.h +1 -18
@@ -1736,22 +1736,6 @@ static inline void skb_zcopy_set(struct sk_buff *skb, struct ubuf_info *uarg, } } -static inline void skb_zcopy_set_nouarg (struct sk_buff *skb,void *val) -{ -skb_shinfo (skb)->destructor_arg = (void *)((uintptr_t ) val |0x1UL ); -skb_shinfo (skb)->flags |=SKBFL_ZEROCOPY_FRAG ; -} - -static inline bool skb_zcopy_is_nouarg (struct sk_buff *skb) -{ -return (uintptr_t )skb_shinfo (skb)->destructor_arg &0x1UL ; -} - -static inline void *skb_zcopy_get_nouarg (struct sk_buff *skb) -{ -return (void *)((uintptr_t )skb_shinfo (skb)->destructor_arg & ~0x1UL ); -} -static inline void net_zcopy_put (struct ubuf_info *uarg) {if (uarg)
@@ -1774,8 +1758,7 @@ static inline void skb_zcopy_clear(struct sk_buff *skb, bool zerocopy_success)struct ubuf_info *uarg =skb_zcopy (skb);if (uarg) { -if (!skb_zcopy_is_nouarg (skb)) - uarg->callback (skb, uarg, zerocopy_success); + uarg->callback (skb, uarg, zerocopy_success);skb_shinfo (skb)->flags &= ~SKBFL_ALL_ZEROCOPY ; }
net/packet/af_packet.c +60 -38
154 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 452/2857 tty: n_gsm: fix missing modem controls after DLCI open in convergence layer type 2
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Starke <[email protected]>
[ Upstream commit 11ea5a63d30ad6d305b1c22301cd99ff45a98c8d ]
The current implementation only updates the virtual V.24 control signals after DLCI open in basic option mode. In advanced option mode with convergence layer type 2 an empty data frame needs to be transmitted to inform the peer about the initial virtual V.24 control signals. Not doing so has two unwanted side effects:
1. hardware flow control status is unclear (initial CTS line is unknown)
2. DLCI user presence is not transmitted (initial DTR line is unknown)
Applications waiting on these lines can not start after a DLCI has been opened until the first data frame has been transmitted.
Fix this by using gsm_modem_update() thoroughly which handles basic and advanced option mode correctly. Add a flag in gsm_modem_update() and the delegated gsm_modem_upd_via_msc() to control whether waiting for the MSC command response is possible. Remove obsolete gsm_modem_send_initial_msc().
--- drivers/tty/n_gsm.c | 47 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-)
drivers/tty/n_gsm.c +14 -33
@@ -414,13 +414,12 @@ static const u8 gsm_fcs8[256] = {#define GOOD_FCS 0xCFstatic int gsmld_output (struct gsm_mux *gsm,u8 *data,int len); -static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk); +static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk,bool wait);static struct gsm_msg *gsm_data_alloc (struct gsm_mux *gsm,u8 addr,int len,u8 ctrl);static int gsm_send_packet (struct gsm_mux *gsm,struct gsm_msg *msg);static void gsmld_write_trigger (struct gsm_mux *gsm);static void gsmld_write_task (struct work_struct *work); -static int gsm_modem_send_initial_msc (struct gsm_dlci *dlci);/** * gsm_fcs_add - update FCS
@@ -1835,7 +1834,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci)pr_debug ("DLCI %d goes open.\n" , dlci->addr);/* Send current modem state */ if (dlci->addr) -gsm_modem_send_initial_msc (dlci); +gsm_modem_update (dlci,0 , false);gsm_dlci_data_kick (dlci);wake_up (&dlci->gsm->event); }
@@ -3466,9 +3465,10 @@ static void gsm_modem_upd_via_data(struct gsm_dlci *dlci, u8 brk)* gsm_modem_upd_via_msc - send modem bits via control frame * @dlci: channel * @brk: break signal +* @wait: wait for the MSC command */ -static int gsm_modem_upd_via_msc (struct gsm_dlci *dlci,u8 brk) +static int gsm_modem_upd_via_msc (struct gsm_dlci *dlci,u8 brk,bool wait) {u8 modembits[3 ];struct gsm_control *ctrl;
@@ -3485,41 +3485,22 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk) modembits[2 ] = (brk <<4 ) |2 |EA ;/* Length, Break, EA */ len++; } +if (!wait) +return gsm_control_command (dlci->gsm,CMD_MSC , modembits, len); ctrl =gsm_control_send (dlci->gsm,CMD_MSC , modembits, len);if (ctrl ==NULL )return -ENOMEM ;return gsm_control_wait (dlci->gsm, ctrl); } -/** -* gsm_modem_send_initial_msc - Send initial modem status message -* -* @dlci channel -* -* Send an initial MSC message after DLCI open to set the initial -* modem status lines. This is only done for basic mode. -* Does not wait for a response as we cannot block the input queue -* processing. -*/ -static int gsm_modem_send_initial_msc (struct gsm_dlci *dlci) -{ -u8 modembits[2 ]; - -if (dlci->adaption !=1 || dlci->gsm->encoding !=GSM_BASIC_OPT ) -return 0 ; - - modembits[0 ] = (dlci->addr <<2 ) |2 |EA ;/* DLCI, Valid, EA */ - modembits[1 ] = (gsm_encode_modem (dlci) <<1 ) |EA ; -return gsm_control_command (dlci->gsm,CMD_MSC , (const u8 *)&modembits,2 ); -} -/** * gsm_modem_update - send modem status line state * @dlci: channel * @brk: break signal +* @wait: wait for the MSC command */ -static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk) +static int gsm_modem_update (struct gsm_dlci *dlci,u8 brk,bool wait) {if (dlci->gsm->dead)return -EL2HLT ;
@@ -3529,7 +3510,7 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)return 0 ; }else if (dlci->gsm->encoding ==GSM_BASIC_OPT ) {/* Send as MSC control message. */ -return gsm_modem_upd_via_msc (dlci, brk); +return gsm_modem_upd_via_msc (dlci, brk, wait); }/* Modem status lines are not supported. */
@@ -3568,7 +3549,7 @@ static void gsm_dtr_rts(struct tty_port *port, int onoff) modem_tx &= ~(TIOCM_DTR |TIOCM_RTS );if (modem_tx != dlci->modem_tx) { dlci->modem_tx = modem_tx; -gsm_modem_update (dlci,0 ); +gsm_modem_update (dlci,0 , true); } }
@@ -3760,7 +3741,7 @@ static int gsmtty_tiocmset(struct tty_struct *tty,if (modem_tx != dlci->modem_tx) { dlci->modem_tx = modem_tx; -return gsm_modem_update (dlci,0 ); +return gsm_modem_update (dlci,0 , true); }return 0 ; }
@@ -3822,7 +3803,7 @@ static void gsmtty_throttle(struct tty_struct *tty) dlci->modem_tx &= ~TIOCM_RTS ; dlci->throttled = true;/* Send an MSC with RTS cleared */ -gsm_modem_update (dlci,0 ); +gsm_modem_update (dlci,0 , true); }static void gsmtty_unthrottle (struct tty_struct *tty)
@@ -3834,7 +3815,7 @@ static void gsmtty_unthrottle(struct tty_struct *tty) dlci->modem_tx |=TIOCM_RTS ; dlci->throttled = false;/* Send an MSC with RTS set */ -gsm_modem_update (dlci,0 ); +gsm_modem_update (dlci,0 , true); }static int gsmtty_break_ctl (struct tty_struct *tty,int state)
@@ -3852,7 +3833,7 @@ static int gsmtty_break_ctl(struct tty_struct *tty, int state)if (encode >0x0F ) encode =0x0F ;/* Best effort */ } -return gsm_modem_update (dlci, encode); +return gsm_modem_update (dlci, encode, true); }static void gsmtty_cleanup (struct tty_struct *tty)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/2857 serial: fix ioctl hangup race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 8ca59f7baee7c72cf7729950b4ab2e7f910c9549 ]
The tty ioctls can race with hangup and end up calling into a tty driver for a device that is already gone or powered down.
Add the missing checks to make sure the port has not been hung up before accessing the hardware to avoid issues like kernel panic due to unclocked accesses.
Note that TIOCGSERIAL, TIOCGICOUNT do not access hardware and are therefore not affected by the race.
Also note that the initialised check in uart_set_ldisc() added by commit 2f70e49ed860 ("serial_core: Check for port state when tty is in error state") should have been done under the port lock to avoid racing with uart_do_autoconfig().
--- drivers/tty/serial/serial_core.c | 52 +++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 14 deletions(-)
drivers/tty/serial/serial_core.c +38 -14
@@ -816,7 +816,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,upf_t old_flags, new_flags;int retval =0 ; -if (!uport) +if (!uport ||tty_io_error (tty))return -EIO ; new_port = new_info->port;
@@ -1120,7 +1120,7 @@ static int uart_break_ctl(struct tty_struct *tty, int break_state)mutex_lock (&port->mutex); uport =uart_port_check (state); -if (!uport) +if (!uport ||tty_io_error (tty)) goto out;if (uport->type !=PORT_UNKNOWN && uport->ops->break_ctl)
@@ -1149,7 +1149,7 @@ static int uart_do_autoconfig(struct tty_struct *tty, struct uart_state *state)return -ERESTARTSYS ; uport =uart_port_check (state); -if (!uport) { +if (!uport ||tty_io_error (tty)) { ret = -EIO ; goto out; }
@@ -1204,7 +1204,7 @@ static void uart_enable_ms(struct uart_port *uport)* FIXME: This wants extracting into a common all driver implementation * of TIOCMWAIT using tty_port. */ -static int uart_wait_modem_status (struct uart_state *state,unsigned long arg) +static int uart_wait_modem_status (struct tty_struct *tty,struct uart_state *state,unsigned long arg) {struct uart_port *uport;struct tty_port *port = &state->port;
@@ -1215,14 +1215,26 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg)/* * note the counters on entry */ +mutex_lock (&port->mutex); uport =uart_port_ref (state); -if (!uport) +if (!uport) { +mutex_unlock (&port->mutex);return -EIO ; + } + +if (tty_io_error (tty)) { +mutex_unlock (&port->mutex); + ret = -EIO ; + goto out_deref; + } +spin_lock_irq (&uport->lock);memcpy (&cprev, &uport->icount,sizeof (struct uart_icount ));uart_enable_ms (uport);spin_unlock_irq (&uport->lock); +mutex_unlock (&port->mutex); +add_wait_queue (&port->delta_msr_wait, &wait);for (;;) {set_current_state (TASK_INTERRUPTIBLE );
@@ -1251,6 +1263,7 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg) }__set_current_state (TASK_RUNNING );remove_wait_queue (&port->delta_msr_wait, &wait); +out_deref:uart_port_deref (uport);return ret;
@@ -1568,7 +1581,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)*/ switch (cmd) {case TIOCMIWAIT : - ret =uart_wait_modem_status (state, arg); + ret =uart_wait_modem_status (tty, state, arg);break ; }
@@ -1629,15 +1642,15 @@ static void uart_set_ldisc(struct tty_struct *tty) {struct uart_state *state = tty->driver_data;struct uart_port *uport; -struct tty_port *port = &state->port; - -if (!tty_port_initialized (port)) -return ;mutex_lock (&state->port.mutex); uport =uart_port_check (state); -if (uport && uport->ops->set_ldisc) +if (!uport ||tty_io_error (tty)) + goto out; + +if (uport->ops->set_ldisc) uport->ops->set_ldisc (uport, &tty->termios); +out:mutex_unlock (&state->port.mutex); }
@@ -1652,7 +1665,7 @@ static void uart_set_termios(struct tty_struct *tty,mutex_lock (&state->port.mutex); uport =uart_port_check (state); -if (!uport) +if (!uport ||tty_io_error (tty)) goto out;/*
@@ -1817,14 +1830,25 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)* 'timeout' / 'expire' give us the maximum amount of time * we wait. */ -while (!port->ops->tx_empty (port)) { +for (;;) { +bool done; + +uart_port_deref (port); +mutex_lock (&state->port.mutex); + port =uart_port_ref (state); + done = !port ||tty_io_error (tty) || port->ops->tx_empty (port); +mutex_unlock (&state->port.mutex); +if (done) +break ; +msleep_interruptible (jiffies_to_msecs (char_time));if (signal_pending (current))break ;if (timeout &&time_after (jiffies, expire))break ; } -uart_port_deref (port); +if (port) +uart_port_deref (port); }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 454/2857 serial: abort TIOCMIWAIT on hangup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit eb35b73e133686e5b999eb7130c4e3d22fe03089 ]
Add the missing hangup check to the TIOCMIWAIT wait loop to avoid going back to sleep (indefinitely) after being woken on hangup.
--- drivers/tty/serial/serial_core.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/tty/serial/serial_core.c +5 -0
@@ -1251,6 +1251,11 @@ static int uart_wait_modem_status(struct tty_struct *tty, struct uart_state *stabreak ; } +if (tty_io_error (tty)) { + ret = -EIO ; +break ; + } +schedule ();/* see if a signal did it */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/2857 serial: 8250_omap: fix wake irq cleared during suspend
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kendall Willis <[email protected]>
[ Upstream commit 73f3e6ca7a6a7c952977c7c94f1c6dddebcafa34 ]
The wake irq was cleared in shutdown(), which runs during the suspend sequence, making it impossible to wake the system via UART. Move wake irq setup to probe() and teardown to remove() so the irq remains armed during suspend when the UART is a wakeup source.
--- drivers/tty/serial/8250/8250_omap.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/tty/serial/8250/8250_omap.c +9 -8
@@ -685,12 +685,6 @@ static int omap_8250_startup(struct uart_port *port)struct omap8250_priv *priv = port->private_data;int ret; -if (priv->wakeirq) { - ret =dev_pm_set_dedicated_wake_irq (port->dev, priv->wakeirq); -if (ret) -return ret; - } -pm_runtime_get_sync (port->dev);serial_out (up,UART_FCR ,UART_FCR_CLEAR_RCVR |UART_FCR_CLEAR_XMIT );
@@ -740,7 +734,6 @@ static int omap_8250_startup(struct uart_port *port) err:pm_runtime_mark_last_busy (port->dev);pm_runtime_put_autosuspend (port->dev); -dev_pm_clear_wake_irq (port->dev);return ret; }
@@ -775,7 +768,6 @@ static void omap_8250_shutdown(struct uart_port *port)pm_runtime_mark_last_busy (port->dev);pm_runtime_put_autosuspend (port->dev);free_irq (port->irq, port); -dev_pm_clear_wake_irq (port->dev); }static void omap_8250_throttle (struct uart_port *port)
@@ -1468,6 +1460,13 @@ static int omap8250_probe(struct platform_device *pdev) } }#endif + +if (priv->wakeirq) { + ret =dev_pm_set_dedicated_wake_irq (&pdev->dev, priv->wakeirq); +if (ret) + goto err; + } + ret =serial8250_register_8250_port (&up);if (ret <0 ) {dev_err (&pdev->dev,"unable to register 8250 port\n" );
@@ -1478,6 +1477,7 @@ static int omap8250_probe(struct platform_device *pdev)pm_runtime_put_autosuspend (&pdev->dev);return 0 ; err: +dev_pm_clear_wake_irq (&pdev->dev);pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_put_sync (&pdev->dev);flush_work (&priv->qos_work);
@@ -1497,6 +1497,7 @@ static int omap8250_remove(struct platform_device *pdev)serial8250_unregister_port (priv->line); priv->line = -ENODEV ; +dev_pm_clear_wake_irq (&pdev->dev);pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_put_sync (&pdev->dev);flush_work (&priv->qos_work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 456/2857 HID: multitouch: stop the release timer from being rearmed on remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
[ Upstream commit 5acb2dace582f061aab5e14c399ac9480315f44b ]
mt_remove() quiesces the sticky-finger timer before stopping the hardware:
timer_delete_sync(&td->release_timer);
sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
hid_hw_stop(hdev);timer_delete_sync() waits for a running callback and dequeues the timer, but it does not stop the timer from being armed again. The transport is still delivering reports at that point, and the report path rearms it:
if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
if (td->mt_io_flags & MT_IO_SLOTS_MASK)
mod_timer(&td->release_timer,
jiffies + msecs_to_jiffies(100));A report that arrives after timer_delete_sync() has returned therefore leaves the timer queued. td is allocated with devm_kzalloc() against hdev->dev, so it is freed when the driver is unbound, after mt_remove() returns. When the timer fires afterwards, mt_expired_timeout() dereferences the freed td:
struct mt_device *td = timer_container_of(td, t, release_timer);
struct hid_device *hdev = td->hdev;
if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))Simply moving the teardown after hid_hw_stop() does not fix this on its own, because mt_expired_timeout() calls mt_release_contacts(), which walks hdev->inputs; the timer still has to be quiesced before hid_hw_stop() tears the input devices down.
Use timer_shutdown_sync() instead, which additionally makes any later mod_timer() a no-op, so neither ordering constraint has to be traded off against the other. This is the final-teardown pattern the function was introduced for, and hid-wiimote already uses it for the same reason.
--- drivers/hid/hid-multitouch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-multitouch.c +1 -1
@@ -1892,7 +1892,7 @@ static void mt_remove(struct hid_device *hdev) {struct mt_device *td =hid_get_drvdata (hdev); -del_timer_sync (&td->release_timer); +timer_shutdown_sync (&td->release_timer);sysfs_remove_group (&hdev->dev.kobj, &mt_attribute_group);hid_hw_stop (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/2857 x86/mce: Fix hardware debug register corruption on task migration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit b8d1d5b63a8ef532038eebd9d97d406860385668 ]
In exc_machine_check_user(), local_db_save() and local_db_restore() are invoked in the outer entry stubs (DEFINE_IDTENTRY_MCE_USER, DEFINE_FREDENTRY_MCE, and DEFINE_IDTENTRY_RAW), surrounding exc_machine_check_user().
However, exc_machine_check_user() calls irqentry_exit_to_user_mode(), which handles pending thread work and may schedule() if TIF_NEED_RESCHED is set. If the task migrates to another CPU during schedule(), local_db_restore() runs on the new CPU with the dr7 state saved from the old CPU. This corrupts the new CPU's DR7 hardware debug register and leaves the old CPU's DR7 disabled. In short, local_db_save() and local_db_restore() pair must be run on the same CPU.
To fix this, move local_db_save() and local_db_restore() inside exc_machine_check_user() and exc_machine_check_kernel(). In exc_machine_check_user(), DR7 is saved and restored strictly around do_machine_check() to avoid schedule() during migration. In exc_machine_check_kernel(), local_db_save() is called at the entry point to prevent early memory accesses from triggering nested #DB exceptions, and restored on all exits.
--- arch/x86/kernel/cpu/mce/core.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/mce/core.c +10 -13
@@ -2117,6 +2117,9 @@ bool filter_mce(struct mce *m) static __always_inline void exc_machine_check_kernel(struct pt_regs *regs) {irqentry_state_t irq_state; +unsigned long dr7; + + dr7 =local_db_save ();WARN_ON_ONCE (user_mode (regs));
@@ -2125,20 +2128,26 @@ static __always_inline void exc_machine_check_kernel(struct pt_regs *regs)* mce_check_crashing_cpu() for details. */ if (mca_cfg.initialized &&mce_check_crashing_cpu ()) -return ; + goto out; irq_state =irqentry_nmi_enter (regs);do_machine_check (regs);irqentry_nmi_exit (regs, irq_state); +out: +local_db_restore (dr7); } static __always_inline void exc_machine_check_user(struct pt_regs *regs) { +unsigned long dr7; +irqentry_enter_from_user_mode (regs); + dr7 =local_db_save ();do_machine_check (regs); +local_db_restore (dr7);irqentry_exit_to_user_mode (regs); }
@@ -2147,34 +2156,22 @@ static __always_inline void exc_machine_check_user(struct pt_regs *regs)/* MCE hit kernel mode */ DEFINE_IDTENTRY_MCE (exc_machine_check) { -unsigned long dr7; - - dr7 =local_db_save ();exc_machine_check_kernel (regs); -local_db_restore (dr7); }/* The user mode variant. */ DEFINE_IDTENTRY_MCE_USER (exc_machine_check) { -unsigned long dr7; - - dr7 =local_db_save ();exc_machine_check_user (regs); -local_db_restore (dr7); }#else /* 32bit unified entry point */ DEFINE_IDTENTRY_RAW (exc_machine_check) { -unsigned long dr7; - - dr7 =local_db_save ();if (user_mode (regs))exc_machine_check_user (regs);else exc_machine_check_kernel (regs); -local_db_restore (dr7); }#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/2857 drm/amd/display: Whitespace cleanup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 3335a13535312c9fad4d8d1307a621e6617d6ed8 ]
Commit 075e2099c32c ("drm/amd/display: Fix race condition in DPIA AUX transfer") was backported to stable, which I noticed because of git saying
linux-6.1/.git/rebase-apply/patch:37154: space before tab in indent.
while applying patch-6.1.21. While fixing the code location that issued that warning, improve in few more places.
Stable-dep-of: c5fd4eaad50d ("drm/amd/display: Fix dc stream excess put in dm_update_crtc_state()")
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +13 -13
@@ -2336,9 +2336,9 @@ static int dm_late_init(void *handle)*/ params.min_abm_backlight =0x28F ;/* In the case where abm is implemented on dmcub, -* dmcu object will be null. -* ABM 2.4 and up are implemented on dmcub. -*/ +* dmcu object will be null. +* ABM 2.4 and up are implemented on dmcub. +*/ if (dmcu) {if (!dmcu_load_iram (dmcu, params))return -EINVAL ;
@@ -7087,13 +7087,13 @@ static uint add_fs_modes(struct amdgpu_dm_connector *aconnector)/* Standard FPS values * * 23.976 - TV/NTSC -* 24 - Cinema -* 25 - TV/PAL +* 24 - Cinema +* 25 - TV/PAL * 29.97 - TV/NTSC -* 30 - TV/NTSC -* 48 - Cinema HFR -* 50 - TV/PAL -* 60 - Commonly used +* 30 - TV/NTSC +* 48 - Cinema HFR +* 50 - TV/PAL +* 60 - Commonly used * 48,72,96,120 - Multiples of 24 */ static const u32 common_rates[] = {
@@ -7719,7 +7719,7 @@ static void update_freesync_state_on_stream(return ;spin_lock_irqsave (&adev_to_drm (adev)->event_lock, flags); - vrr_params = acrtc->dm_irq_params.vrr_params; + vrr_params = acrtc->dm_irq_params.vrr_params;if (surface) { mod_freesync_handle_preflip(
@@ -8274,7 +8274,7 @@ static void amdgpu_dm_commit_audio(struct drm_device *dev,if (!drm_atomic_crtc_needs_modeset (new_crtc_state))continue ; - notify: +notify:if (connector->connector_type ==DRM_MODE_CONNECTOR_WRITEBACK )continue ;
@@ -9303,7 +9303,7 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm, skip_modeset:/* Release extra reference */ if (new_stream) -dc_stream_release (new_stream); +dc_stream_release (new_stream); new_stream =NULL ;/*
@@ -10699,7 +10699,7 @@ int amdgpu_dm_process_dmub_aux_transfer_sync(if (!dc_process_dmub_aux_transfer_async (ctx->dc, link_index, payload)) { *operation_result =AUX_RET_ERROR_ENGINE_ACQUIRE ; goto out; - } + }if (!wait_for_completion_timeout (&adev->dm.dmub_aux_transfer_done,10 *HZ )) {DRM_ERROR ("wait_for_completion_timeout timeout!" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/2857 drm/amd/display: Fix dc stream excess put in dm_update_crtc_state()
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 c5fd4eaad50d620c7e09ac2082b2fb55ee54170e ]
In dm_update_crtc_state(), when a modeset is required the newly created stream is stored in dm_new_crtc_state->stream and an extra reference is taken with dc_stream_retain(). The reference returned by create_validate_stream_for_sink() is released as an extra reference at the skip_modeset label, leaving the stream owned by the new CRTC state.
If amdgpu_dm_check_crtc_color_mgmt() fails afterwards, the code jumps to the fail label which releases new_stream again. Since the extra reference was already released at skip_modeset, this drops the reference owned by dm_new_crtc_state->stream and the stream is released while the atomic state still points to it, leading to a premature free of the dc stream.
Set new_stream to NULL after releasing the extra reference at the skip_modeset label so that a later goto fail cannot release the reference owned by the new CRTC state.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -1
@@ -9302,8 +9302,10 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm, skip_modeset:/* Release extra reference */ -if (new_stream) +if (new_stream) {dc_stream_release (new_stream); + new_stream =NULL ; + } new_stream =NULL ;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/2857 drm/amd/display: Bump frame warning limit for clang builds of dml
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Lipski <[email protected]>
[ Upstream commit 18779dd84515db093fedb4ebaf0998c9b165a5fb ]
[Why&How]
When building the DML files with clang without any sanitizer or LTO, the following -Wframe-larger-than errors break the build under CONFIG_WERROR:
display_mode_vba_30.c: error: stack frame size (2512) exceeds limit
(2048) in 'dml30_ModeSupportAndSystemConfigurationFull'
display_mode_vba_31.c: error: stack frame size (2416) exceeds limit
(2048) in 'dml31_ModeSupportAndSystemConfigurationFull'
display_mode_vba_314.c: error: stack frame size (2392) exceeds limit
(2048) in 'dml314_ModeSupportAndSystemConfigurationFull'
Clang consistently spills more than gcc, pushing the frame past the 2048 byte limit.
Apply an existing approach of increasing the warn stack size to the non-sanitizer path so plain clang builds use a 3072 byte limit.
--- drivers/gpu/drm/amd/display/dc/dml/Makefile | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/dc/dml/Makefile +4 -0
@@ -55,9 +55,13 @@ ifneq ($(CONFIG_FRAME_WARN),0) ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y) frame_warn_flag := -Wframe-larger-than=3072 else +ifeq ($(CONFIG_CC_IS_CLANG),y) +frame_warn_flag := -Wframe-larger-than=3072 +else frame_warn_flag := -Wframe-larger-than=2048 endif endif +endif CFLAGS_$(AMDDALPATH)/dc/dml/display_mode_lib.o := $(dml_ccflags)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/2857 net: mctp: avoid confusion over local/peer dest/source addresses
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeremy Kerr <[email protected]>
[ Upstream commit ee076b73e576b0a052d5686d873346b285ae50ea ]
We have a double-swap of local and peer addresses in mctp_alloc_local_tag; the arguments in both call sites are swapped, but there is also a swap in the implementation of alloc_local_tag. This is opaque because we're using source/dest address references, which don't match the local/peer semantics.
Avoid this confusion by naming the arguments as 'local' and 'peer', and remove the double swap. The calling order now matches mctp_key_alloc.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- include/net/mctp.h | 4 ++-- net/mctp/af_mctp.c | 2 +- net/mctp/route.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-)
include/net/mctp.h +2 -2
@@ -90,7 +90,7 @@ struct mctp_sock { };/* Key for matching incoming packets to sockets or reassembly contexts. -* Packets are matched on (src,dest,tag). +* Packets are matched on (peer EID, local EID, tag). * * Lifetime / locking requirements: *
@@ -258,7 +258,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,void mctp_key_unref (struct mctp_sk_key *key);struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, -mctp_eid_t daddr,mctp_eid_t saddr, +mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp);/* routing <--> device interface */
net/mctp/af_mctp.c +1 -1
@@ -366,7 +366,7 @@ static int mctp_ioctl_alloctag(struct mctp_sock *msk, unsigned long arg)if (ctl.flags)return -EINVAL ; - key =mctp_alloc_local_tag (msk, ctl.peer_addr,MCTP_ADDR_ANY , + key =mctp_alloc_local_tag (msk,MCTP_ADDR_ANY , ctl.peer_addr, true, &tag);if (IS_ERR (key))return PTR_ERR (key);
net/mctp/route.c +8 -8
@@ -634,11 +634,11 @@ static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,refcount_inc (&key->refs); } -/* Allocate a locally-owned tag value for (saddr, daddr), and reserve +/* Allocate a locally-owned tag value for (local, peer), and reserve * it for the socket msk */ struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, -mctp_eid_t daddr,mctp_eid_t saddr, +mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp) {struct net *net =sock_net (&msk->sk);
@@ -648,11 +648,11 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,u8 tagbits;/* for NULL destination EIDs, we may get a response from any peer */ -if (daddr ==MCTP_ADDR_NULL ) - daddr =MCTP_ADDR_ANY ; +if (peer ==MCTP_ADDR_NULL ) + peer =MCTP_ADDR_ANY ;/* be optimistic, alloc now */ - key =mctp_key_alloc (msk, saddr, daddr,0 ,GFP_KERNEL ); + key =mctp_key_alloc (msk, local, peer,0 ,GFP_KERNEL );if (!key)return ERR_PTR (-ENOMEM );
@@ -673,8 +673,8 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,if (tmp->tag &MCTP_HDR_FLAG_TO )continue ; -if (!(mctp_address_matches (tmp->peer_addr, daddr) && -mctp_address_matches (tmp->local_addr, saddr))) +if (!(mctp_address_matches (tmp->peer_addr, peer) && +mctp_address_matches (tmp->local_addr, local)))continue ;spin_lock (&tmp->lock);
@@ -966,7 +966,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt, key =mctp_lookup_prealloc_tag (msk, daddr, req_tag, &tag); else - key =mctp_alloc_local_tag (msk, daddr, saddr, + key =mctp_alloc_local_tag (msk, saddr, daddr, false, &tag);if (IS_ERR (key)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 462/2857 net: mctp: Add some detail on the key allocation implementation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeremy Kerr <[email protected]>
[ Upstream commit aee6479a458e2c5027e558cfe26c60c37f8efc80 ]
We could do with a little more comment on where MCTP_ADDR_ANY will match in the key allocations.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- net/mctp/route.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
net/mctp/route.c +37 -0
@@ -73,6 +73,40 @@ static struct mctp_sock *mctp_lookup_bind(struct net *net, struct sk_buff *skb)return NULL ; } +/* A note on the key allocations. +* +* struct net->mctp.keys contains our set of currently-allocated keys for +* MCTP tag management. The lookup tuple for these is the peer EID, +* local EID and MCTP tag. +* +* In some cases, the peer EID may be MCTP_EID_ANY: for example, when a +* broadcast message is sent, we may receive responses from any peer EID. +* Because the broadcast dest address is equivalent to ANY, we create +* a key with (local = local-eid, peer = ANY). This allows a match on the +* incoming broadcast responses from any peer. +* +* We perform lookups when packets are received, and when tags are allocated +* in two scenarios: +* +* - when a packet is sent, with a locally-owned tag: we need to find an +* unused tag value for the (local, peer) EID pair. +* +* - when a tag is manually allocated: we need to find an unused tag value +* for the peer EID, but don't have a specific local EID at that stage. +* +* in the latter case, on successful allocation, we end up with a tag with +* (local = ANY, peer = peer-eid). +* +* So, the key set allows both a local EID of ANY, as well as a peer EID of +* ANY in the lookup tuple. Both may be ANY if we prealloc for a broadcast. +* The matching (in mctp_key_match()) during lookup allows the match value to +* be ANY in either the dest or source addresses. +* +* When allocating (+ inserting) a tag, we need to check for conflicts amongst +* the existing tag set. This requires macthing either exactly on the local +* and peer addresses, or either being ANY. +*/ +static bool mctp_key_match (struct mctp_sk_key *key,mctp_eid_t local,mctp_eid_t peer,u8 tag) {
@@ -386,6 +420,9 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)* key lookup to find the socket, but don't use this * key for reassembly - we'll create a more specific * one for future packets if required (ie, !EOM). +* +* this lookup requires key->peer to be MCTP_ADDR_ANY, +* it doesn't match just any key->peer. */ any_key =mctp_lookup_key (net, skb,MCTP_ADDR_ANY , &f);if (any_key) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 463/2857 net: mctp: separate key correlation across nets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeremy Kerr <[email protected]>
[ Upstream commit 43e6795574f5d75284a3cb21f5b76a5ffb98e8e6 ]
Currently, we lookup sk_keys from the entire struct net_namespace, which may contain multiple MCTP net IDs. In those cases we want to distinguish between endpoints with the same EID but different net ID.
Add the net ID data to the struct mctp_sk_key, populate on add and filter on this during route lookup.
For the ioctl interface, we use a default net of MCTP_INITIAL_DEFAULT_NET (ie., what will be in use for single-net configurations), but we'll extend the ioctl interface to provide net-specific tag allocation in an upcoming change.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- include/net/mctp.h | 2 ++ net/mctp/af_mctp.c | 4 ++-- net/mctp/route.c | 43 +++++++++++++++++++++++++++----------- net/mctp/test/route-test.c | 7 +++++-- 4 files changed, 40 insertions(+), 16 deletions(-)
include/net/mctp.h +2 -0
@@ -136,6 +136,7 @@ struct mctp_sock {* - through an expiry timeout, on a per-socket timer */ struct mctp_sk_key { +unsigned int net;mctp_eid_t peer_addr;mctp_eid_t local_addr;/* MCTP_ADDR_ANY for local owned tags */ __u8 tag;/* incoming tag match; invert TO for local */
@@ -258,6 +259,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,void mctp_key_unref (struct mctp_sk_key *key);struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, +unsigned int netid,mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp);
net/mctp/af_mctp.c +2 -2
@@ -366,8 +366,8 @@ static int mctp_ioctl_alloctag(struct mctp_sock *msk, unsigned long arg)if (ctl.flags)return -EINVAL ; - key =mctp_alloc_local_tag (msk,MCTP_ADDR_ANY , ctl.peer_addr, - true, &tag); + key =mctp_alloc_local_tag (msk,MCTP_INITIAL_DEFAULT_NET , +MCTP_ADDR_ANY , ctl.peer_addr, true, &tag);if (IS_ERR (key))return PTR_ERR (key);
net/mctp/route.c +31 -12
160 lines not on this page · raw message
net/mctp/test/route-test.c +5 -2
@@ -544,6 +544,7 @@ static void mctp_test_route_input_sk_keys(struct kunit *test)struct mctp_sock *msk;struct socket *sock;unsigned long flags; +unsigned int net;int rc;u8 c;
@@ -551,6 +552,7 @@ static void mctp_test_route_input_sk_keys(struct kunit *test) dev =mctp_test_create_dev ();KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + net =READ_ONCE (dev->mdev->net); rt =mctp_test_create_route (&init_net, dev->mdev,8 ,68 );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt);
@@ -562,8 +564,9 @@ static void mctp_test_route_input_sk_keys(struct kunit *test) mns = &sock_net (sock->sk)->mctp;/* set the incoming tag according to test params */ - key =mctp_key_alloc (msk, params->key_local_addr, params->key_peer_addr, - params->key_tag,GFP_KERNEL ); + key =mctp_key_alloc (msk, net, params->key_local_addr, + params->key_peer_addr, params->key_tag, +GFP_KERNEL );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, key);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 464/2857 mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit 26cc0e69cce062cd3aa6fae33074684669c35a71 ]
When a socket transmits a packet with MCTP_TAG_PREALLOC set, mctp_lookup_prealloc_tag() iterates over the per-netns &mns->keys list and matches netid, req_tag, peer_addr, and manual_alloc, without checking whether tmp->sk == &msk->sk. This allows any MCTP socket in the same network namespace to use and consume another socket's preallocated tag.
Iterate the socket's own tag list (&msk->keys via sklist) instead of the namespace-wide &mns->keys list in mctp_lookup_prealloc_tag(), ensuring that only tags allocated by msk are matched.
Tested in QEMU against Linux 7.3.0-rc3 by allocating a manual tag (0x18) on socket A via SIOCMCTPALLOCTAG for peer EID 9 and sending a 4-byte message with MCTP_TAG_PREALLOC from socket B in the same network namespace. On the unfixed kernel, sendto(sock_b) using socket A's preallocated tag succeeds (ret = 4); with this patch applied, sendto(sock_b) fails with -ENOENT (errno = 2) while sendto(sock_a) succeeds (ret = 4).
--- net/mctp/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mctp/route.c +1 -1
@@ -773,7 +773,7 @@ static struct mctp_sk_key *mctp_lookup_prealloc_tag(struct mctp_sock *msk,spin_lock_irqsave (&mns->keys_lock, flags); -hlist_for_each_entry (tmp, &mns->keys, hlist) { +hlist_for_each_entry (tmp, &msk->keys, sklist) {if (tmp->net != netid)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 465/2857 KVM: SVM: Preserve TLB control (i.e. pending TLB flush) on failed VMRUN
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 60d93c27859fb3ec5b5a689e24de303f166477d0 ]
Don't reset the VMCB's TLB control back to "do nothing" on a failed VMRUN, as empirical testing shows that the CPU performs the requested TLB flush if and only if VMRUN is successful, i.e. clearing TLB control on a failed VMRUN effectively drops a TLB flush.
Explicitly track the need to flush all ASIDs on a per-CPU basis, as the ASID reuse condition is tied to the pCPU, not to the vCPU. As a bonus, this also obviates the need to avoid clobbering FLUSH_ALL_ASID with TLB_CONTROL_FLUSH_ASID, e.g. in svm_flush_tlb_asid().
Deliberately don't bother saving/restoring the "old" tlb_ctl on failure, in quotes because it's not exactly the old tlb_ctl, it's the tlb_ctl from after pre_svm_run(), but before updating tlb_ctl for flush_all_asids. If VMRUN fails and TLB_CONTROL_FLUSH_ALL_ASID is forced, then the next successful run of the VMCB *may* unnecessarily flush all ASIDs, which strictly speaking could result in noisy neighbor issues. However, the fact that new_asid() is already guest-triggerable, because of KVM's flawed behavior of clearing the ASID on emulated INIT, means that a guest can already trigger a flush of all ASIDs at roughly the same rate. And once KVM stops clobbering the ASID on emulated INIT, *or* assigns a static ASID to each vCPU, this flaw goes away.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/svm.c | 14 +++++++++++--- arch/x86/kvm/svm/svm.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-)
arch/x86/kvm/svm/svm.c +11 -3
@@ -1911,8 +1911,7 @@ static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd)if (sd->next_asid > sd->max_asid) { ++sd->asid_generation; sd->next_asid = sd->min_asid; - svm->vmcb->control.tlb_ctl =TLB_CONTROL_FLUSH_ALL_ASID ; -vmcb_mark_dirty (svm->vmcb,VMCB_ASID ); + sd->flush_all_asids = true; } svm->current_vmcb->asid_generation = sd->asid_generation;
@@ -4059,6 +4058,11 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags) svm->vmcb->control.asid = svm->asid;vmcb_mark_dirty (svm->vmcb,VMCB_ASID ); } +if (this_cpu_ptr (&svm_data)->flush_all_asids) { + svm->vmcb->control.tlb_ctl =TLB_CONTROL_FLUSH_ALL_ASID ; +vmcb_mark_dirty (svm->vmcb,VMCB_ASID ); + } + svm->vmcb->save.cr2 = vcpu->arch.cr2;svm_hv_update_vp_id (svm->vmcb, vcpu);
@@ -4128,7 +4132,11 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags) svm->nested.nested_run_pending =0 ; } - svm->vmcb->control.tlb_ctl =TLB_CONTROL_DO_NOTHING ; +if (svm->vmcb->control.exit_code !=SVM_EXIT_ERR ) { +this_cpu_ptr (&svm_data)->flush_all_asids = false; + svm->vmcb->control.tlb_ctl =TLB_CONTROL_DO_NOTHING ; + } +vmcb_mark_all_clean (svm->vmcb);/* if exit due to PF check for async PF */
arch/x86/kvm/svm/svm.h +1 -0
@@ -293,6 +293,7 @@ struct svm_cpu_data {u32 min_asid;struct kvm_ldttss_desc *tss_desc; +bool flush_all_asids;struct page *save_area;unsigned long save_area_pa;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 466/2857 KVM: SVM: Update control fields on #VMEXIT if and only if VMRUN succeeded
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 e27fc915c8f575ab5630e27d97465c2077d4b9d1 ]
Leave control.erap_ctl and control.clean as-is in the VMCS if VMRUN fails, because as per AMD:
there's no explicit architectural guarantee about the behavior in the presence of VMRUN failures. So the best thing to do would be to assume that if VMRUN fails, the actions requested in the control fields may not have been performed.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/svm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +2 -2
@@ -4135,9 +4135,9 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)if (svm->vmcb->control.exit_code !=SVM_EXIT_ERR ) {this_cpu_ptr (&svm_data)->flush_all_asids = false; svm->vmcb->control.tlb_ctl =TLB_CONTROL_DO_NOTHING ; - } -vmcb_mark_all_clean (svm->vmcb); +vmcb_mark_all_clean (svm->vmcb); + }/* if exit due to PF check for async PF */ if (svm->vmcb->control.exit_code ==SVM_EXIT_EXCP_BASE +PF_VECTOR )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 467/2857 KVM: nVMX: Force MSR bitmap refresh if runtime eVMCS controls are modified
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 2abb25273c82061dd4670690c81c319c03740bf6 ]
Force a refresh of the vmcs02 MSR bitmap during nested VM-Enter if the runtime eVMCS controls (pin, primary, secondary, etc.) are being updated. If L1 isn't intercepting TPR writes, runs L2 with TPR virtualization, and then runs the same L2 with TPR virtualization disabled, KVM will fail to refresh msr_bitmap02 and leave TPR in passthrough mode even though TPR virtualization is disabled. I.e. failure to refresh the bitmap lets L2 (or L1 by proxy) read and write L0's TPR.
--- arch/x86/kvm/vmx/nested.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/kvm/vmx/nested.c +6 -0
@@ -1569,6 +1569,9 @@ static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx)static void copy_enlightened_to_vmcs12 (struct vcpu_vmx *vmx,u32 hv_clean_fields) { +const u64 runtime_controls =HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1 | +HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 | +HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC ;struct vmcs12 *vmcs12 = vmx->nested.cached_vmcs12;struct hv_enlightened_vmcs *evmcs = vmx->nested.hv_evmcs;
@@ -1576,6 +1579,9 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields vmcs12->tpr_threshold = evmcs->tpr_threshold; vmcs12->guest_rip = evmcs->guest_rip; +if ((hv_clean_fields & runtime_controls) != runtime_controls) + vmx->nested.force_msr_bitmap_recalc = true; +if (unlikely (!(hv_clean_fields &HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC ))) { vmcs12->guest_rsp = evmcs->guest_rsp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 468/2857 ALSA: hda/realtek: Fix silent speaker on Higole F9B
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu-Hsiang Tseng <[email protected]>
[ Upstream commit 2a8ee6897302ca12ff39e8eb180503956797c60c ]
The Higole F9B is an Alder Lake-N mini PC with a 7" touchscreen and an ALC269VC codec (subsystem ID 0x10ec111e). Its DMI strings are all "Default string", so the SSID is the only way to identify it.
The internal speaker is silent out of the box. The generic parser assigns DAC 0x03 to the speaker pin 0x14 and DAC 0x02 to the headphone pin 0x15, but the speaker only reproduces what DAC 0x02 plays, whatever its connection selection says. Checked one path at a time, only the gain of DAC 0x02 and the mute of pin 0x14 change what comes out of the speaker. User space only knows the path it was told the speaker uses, so selecting the speaker turns the path that actually reaches it all the way down.
Route both 0x14 and 0x15 through mixer 0x0c (DAC 0x02), which is what ALC290_FIXUP_MONO_SPEAKERS already does. Tested on the device: the speaker plays.
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -10247,6 +10247,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x10cf ,0x1757 ,"Lifebook E752" ,ALC269_FIXUP_LIFEBOOK_HP_PIN ),SND_PCI_QUIRK (0x10cf ,0x1845 ,"Lifebook U904" ,ALC269_FIXUP_LIFEBOOK_EXTMIC ),SND_PCI_QUIRK (0x10ec ,0x10f2 ,"Intel Reference board" ,ALC700_FIXUP_INTEL_REFERENCE ), +SND_PCI_QUIRK (0x10ec ,0x111e ,"Higole F9B" ,ALC290_FIXUP_MONO_SPEAKERS ),SND_PCI_QUIRK (0x10ec ,0x118c ,"Medion EE4254 MD62100" ,ALC256_FIXUP_MEDION_HEADSET_NO_PRESENCE ),SND_PCI_QUIRK (0x10ec ,0x119e ,"Positivo SU C1400" ,ALC269_FIXUP_ASPIRE_HEADSET_MIC ), SND_PCI_QUIRK(0x10ec, 0x11bc, "VAIO VJFE-IL", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 469/2857 Bluetooth: Serialize SMP remote OOB data access
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit 81a2345f1984f0b36d3226571bc196316a01b648 ]
build_pairing_cmd() looks up remote OOB data and copies its contents without holding hdev->lock, which serializes the list's writers. After SMP finds an entry, a concurrent management Remove Remote OOB Data command can unlink and free it before SMP reads its present flag or copies its random and confirmation values. Removal can also invalidate an entry while the lookup is still traversing the list.
KASAN reported:
BUG: KASAN: slab-use-after-free in build_pairing_cmd+0x948/0x9b0 Call Trace: build_pairing_cmd+0x948/0x9b0 smp_recv_cb+0x459f/0x8110 l2cap_recv_frame+0xf14/0x9190 l2cap_recv_acldata+0xa64/0xd40 hci_rx_work+0x4ca/0x730 Allocated by task 87: hci_add_remote_oob_data+0x11d/0x530 add_remote_oob_data+0x282/0x400 hci_sock_sendmsg+0x1033/0x1ea0 Freed by task 93: hci_remote_oob_data_clear+0x108/0x1c0 remove_remote_oob_data+0x198/0x220 hci_sock_sendmsg+0x1033/0x1ea0
Taking hdev->lock in build_pairing_cmd() would recurse for callers that already hold it and invert the device-to-L2CAP lock order on the receive path. Add a per-device remote_oob_lock instead, held across the SMP lookup and copies and by the add, remove and clear helpers. Cover initialization and in-place updates as well, so SMP cannot read partially initialized or updated OOB values. Release the mutex on allocation failure, preserving the existing error return.
The new critical sections acquire no device, connection or channel locks. Writers retain their existing hdev->lock protection, which continues to serialize the other readers without changing their locking or behavior.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 12 +++++++++++- net/bluetooth/smp.c | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -553,6 +553,7 @@ struct hci_dev {struct list_head link_keys;struct list_head long_term_keys;struct list_head identity_resolving_keys; +struct mutex remote_oob_lock;struct list_head remote_oob_data;struct list_head le_accept_list;struct list_head le_resolv_list;
net/bluetooth/hci_core.c +11 -1
@@ -1521,8 +1521,10 @@ int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,BT_DBG ("%s removing %pMR (%u)" , hdev->name, bdaddr, bdaddr_type); +mutex_lock (&hdev->remote_oob_lock);list_del (&data->list);kfree (data); +mutex_unlock (&hdev->remote_oob_lock);return 0 ; }
@@ -1531,10 +1533,12 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev) {struct oob_data *data, *n; +mutex_lock (&hdev->remote_oob_lock);list_for_each_entry_safe (data, n, &hdev->remote_oob_data, list) {list_del (&data->list);kfree (data); } +mutex_unlock (&hdev->remote_oob_lock); } int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
@@ -1543,11 +1547,14 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, {struct oob_data *data; +mutex_lock (&hdev->remote_oob_lock); data =hci_find_remote_oob_data (hdev, bdaddr, bdaddr_type);if (!data) { data =kmalloc (sizeof (*data),GFP_KERNEL ); -if (!data) +if (!data) { +mutex_unlock (&hdev->remote_oob_lock);return -ENOMEM ; + }bacpy (&data->bdaddr, bdaddr); data->bdaddr_type = bdaddr_type;
@@ -1580,6 +1587,8 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,BT_DBG ("%s for %pMR" , hdev->name, bdaddr); +mutex_unlock (&hdev->remote_oob_lock); +return 0 ; }
@@ -2523,6 +2532,7 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)mutex_init (&hdev->lock);mutex_init (&hdev->req_lock);mutex_init (&hdev->mgmt_pending_lock); +mutex_init (&hdev->remote_oob_lock);ida_init (&hdev->unset_handle_ida);
net/bluetooth/smp.c +2 -0
@@ -682,6 +682,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn,else bdaddr_type =BDADDR_LE_RANDOM ; +mutex_lock (&hdev->remote_oob_lock); oob_data =hci_find_remote_oob_data (hdev, &hcon->dst, bdaddr_type);if (oob_data && oob_data->present) {
@@ -692,6 +693,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn,SMP_DBG ("OOB Remote Confirmation: %16phN" , smp->pcnf);SMP_DBG ("OOB Remote Random: %16phN" , smp->rr); } +mutex_unlock (&hdev->remote_oob_lock); }else { authreq &= ~SMP_AUTH_SC ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 470/2857 Bluetooth: hci_core: Serialize SCO and ISO scheduling with teardown
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit 848a7a91c7f03675d3bd8db6f7721cbf9cb50e21 ]
hci_low_sent() selects a connection under RCU but drops the read lock before calculating its quota and returning it to the scheduler. The connection is then used without lifetime protection by hci_sched_iso() and hci_sched_sco().
After the TX worker drops the RCU read lock, hci_abort_conn_sync() on hdev->req_workqueue can remove the connection from the hash, complete synchronize_rcu(), purge its queues and release it. The TX worker on hdev->workqueue can then access the freed connection in hci_quote_sent() or while dequeuing packets and updating conn->sent.
KASAN reported:
BUG: KASAN: slab-use-after-free in hci_low_sent+0x730/0x840 Workqueue: hci0 hci_tx_work Call Trace: hci_low_sent+0x730/0x840 hci_sched_iso+0x25e/0x4d0 hci_tx_work+0x239/0xcb0 Allocated by task 93: __hci_conn_add+0x16f/0x1b40 hci_bind_bis+0x782/0x17b0 hci_connect_bis+0xa0/0x510 iso_sock_connect+0x589/0x1050 Freed by task 88: kfree+0x131/0x3c0 device_release+0xc8/0x240 kobject_put+0x14d/0x280 hci_conn_del+0x55a/0xe80 hci_disconnect_sync+0x156/0x180 hci_abort_conn_sync+0x3e7/0x940 hci_cmd_sync_work+0x13c/0x290
Hold hci_dev_lock() across connection selection and transmission in both SCO and ISO scheduling, serializing them with connection teardown. This also prevents queuing completion timestamps after the connection queues have been purged. Extending RCU across transmission would be unsafe because the transmit path can sleep. Keep the ISO timeout check outside the mutex since hci_link_tx_to() takes it itself.
The preceding channel fix already holds this mutex in the ACL and LE schedulers, which call the SCO scheduler between packets. Move the SCO body to __hci_sched_sco(), assert that its caller holds the mutex, and use it directly from these locked paths. Keep a locking hci_sched_sco() wrapper for the direct calls from hci_tx_work(). This avoids recursively acquiring the device mutex while preserving the scheduling order.
Remove the obsolete claim that connection removal disables TX.
--- net/bluetooth/hci_core.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
net/bluetooth/hci_core.c +19 -8
@@ -3400,9 +3400,6 @@ static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,struct hci_conn *conn =NULL , *c;unsigned int num =0 , min = ~0 ; -/* We don't have to lock device here. Connections are always -* added and removed with TX task disabled. */ -rcu_read_lock ();list_for_each_entry_rcu (c, &h->list, list) {
@@ -3589,13 +3586,15 @@ static void __check_timeout(struct hci_dev *hdev, unsigned int cnt, u8 type) }/* Schedule SCO */ -static void hci_sched_sco (struct hci_dev *hdev,__u8 type) +static void __hci_sched_sco (struct hci_dev *hdev,__u8 type) {struct hci_conn *conn;struct sk_buff *skb;int quote, *cnt;unsigned int pkts = hdev->sco_pkts; +lockdep_assert_held (&hdev->lock); +bt_dev_dbg (hdev,"type %u" , type);if (!hci_conn_num (hdev, type) || !pkts)
@@ -3630,6 +3629,13 @@ static void hci_sched_sco(struct hci_dev *hdev, __u8 type)queue_work (hdev->workqueue, &hdev->tx_work); } +static void hci_sched_sco (struct hci_dev *hdev,__u8 type) +{ +hci_dev_lock (hdev); +__hci_sched_sco (hdev, type); +hci_dev_unlock (hdev); +} +static void hci_sched_acl_pkt (struct hci_dev *hdev) {unsigned int cnt = hdev->acl_cnt;
@@ -3665,8 +3671,8 @@ static void hci_sched_acl_pkt(struct hci_dev *hdev) chan->conn->sent++;/* Send pending SCO packets right away */ -hci_sched_sco (hdev,SCO_LINK ); -hci_sched_sco (hdev,ESCO_LINK ); +__hci_sched_sco (hdev,SCO_LINK ); +__hci_sched_sco (hdev,ESCO_LINK ); } }
@@ -3725,8 +3731,8 @@ static void hci_sched_le(struct hci_dev *hdev) chan->conn->sent++;/* Send pending SCO packets right away */ -hci_sched_sco (hdev,SCO_LINK ); -hci_sched_sco (hdev,ESCO_LINK ); +__hci_sched_sco (hdev,SCO_LINK ); +__hci_sched_sco (hdev,ESCO_LINK ); } }
@@ -3750,6 +3756,9 @@ static void hci_sched_iso(struct hci_dev *hdev) cnt = hdev->iso_pkts ? &hdev->iso_cnt : hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; + +hci_dev_lock (hdev); +while (*cnt && (conn =hci_low_sent (hdev,ISO_LINK , "e))) {while (quote-- && (skb =skb_dequeue (&conn->data_q))) {BT_DBG ("skb %p len %d" , skb, skb->len);
@@ -3761,6 +3770,8 @@ static void hci_sched_iso(struct hci_dev *hdev) (*cnt)--; } } + +hci_dev_unlock (hdev); }static void hci_tx_work (struct work_struct *work)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 471/2857 net: extend IPv6 exthdr detection of tunneled packets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
[ Upstream commit 5f0764cb1c81a9712bce605d38efe6d844a70b29 ]
Commit c4336a07eb6b ("net: correctly handle tunneled traffic on IPV6_CSUM GSO fallback") split skb_gso_has_extension_hdr() into mutually exclusive branches on skb->encapsulation. This did not yet address all paths:
1. With skb->encapsulation set, the outer header is not checked. IPv6 tunnels such as ip6_gre and ip6_tunnel add an outer Destination Options header by default (encap_limit). Their GSO packets skip software GSO, then skb_csum_hwoffload_help() sees the outer extension header and calls skb_checksum_help() on the GSO skb, which warns and drops it.
2. Tunnels over IPv6 without an outer transport header, such as ip6_tunnel, leave skb->transport_header at the inner transport header. skb_network_header_len() then spans the outer IPv6, tunnel and inner IP headers, a false positive.
3. UDP tunnels without an inner network header, such as SCTP-in-UDP or PSP, have no inner IPv6 header to check. Decide on the outer header alone.
4. Directly dereferencing inner_ip_hdr(skb)->version without skb_header_pointer() is unsafe.
Instead, check ipv6_ext_hdr(nexthdr) on the outer IPv6 header and, if set, on the inner IPv6 header. Read the headers with skb_header_pointer(). Keep the skb_network_header_len() check when !skb->encapsulation to also catch encapsulated packets without skb->encapsulation (e.g., virtio).
Use the same helper in skb_csum_hwoffload_help(). Its open coded test has the false positive of (2) and ignores the inner header.
Background: checksum offload of tunneled packets invariants:
Non-GSO skb:
- If the inner packet is CHECKSUM_PARTIAL, Local Checksum Offload computes the outer checksum in software and the device offloads only the inner L4 checksum.
- If the inner packet is CHECKSUM_NONE (e.g., SCTP-in-UDP, ESP-in-UDP, Remote Checksum Offload), the device offloads the outer UDP or GRE checksum instead.
GSO skb:
- A device with NETIF_F_GSO_UDP_TUNNEL_CSUM or NETIF_F_GSO_GRE_CSUM computes both inner and outer checksums per segment. The outer checksum is seeded with only the pseudo-header checksum.
A NETIF_F_IPV6_CSUM device must parse through the outer headers to reach the inner ones.
--- net/core/dev.c | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-)
net/core/dev.c +32 -17
@@ -3592,20 +3592,36 @@ static netdev_features_t dflt_features_check(struct sk_buff *skb,return vlan_features_check (skb, features); } -static bool skb_gso_has_extension_hdr (const struct sk_buff *skb) -{ -if (!skb->encapsulation) -return ((skb_shinfo (skb)->gso_type &SKB_GSO_TCPV6 || - (skb_shinfo (skb)->gso_type &SKB_GSO_UDP_L4 && -vlan_get_protocol (skb) ==htons (ETH_P_IPV6 ))) && -skb_transport_header_was_set (skb) && -skb_network_header_len (skb) !=sizeof (struct ipv6hdr )); -else -return (!skb_inner_network_header_was_set (skb) || - ((skb_shinfo (skb)->gso_type &SKB_GSO_TCPV6 || - (skb_shinfo (skb)->gso_type &SKB_GSO_UDP_L4 && -inner_ip_hdr (skb)->version ==6 )) && -skb_inner_network_header_len (skb) !=sizeof (struct ipv6hdr ))); +static bool __skb_has_ipv6_ext_hdr (const struct sk_buff *skb,int nhoff) +{ +const struct ipv6hdr *ip6h; +struct ipv6hdr _ip6h; + + ip6h =skb_header_pointer (skb, nhoff,sizeof (_ip6h), &_ip6h); +return ip6h && ip6h->version ==6 &&ipv6_ext_hdr (ip6h->nexthdr); +} + +static bool skb_has_ipv6_extension_hdr (const struct sk_buff *skb) +{ +if (vlan_get_protocol (skb) ==htons (ETH_P_IPV6 )) { +if (__skb_has_ipv6_ext_hdr (skb,skb_network_offset (skb))) +return true; + +/* Catch tunnels without skb->encapsulation (e.g., virtio). */ +if (!skb->encapsulation && +skb_transport_header_was_set (skb) && +skb_network_header_len (skb) !=sizeof (struct ipv6hdr )) +return true; + } + +/* Tunnels without an inner network header, such as SCTP-in-UDP or +* PSP, have no inner IP header and thus no inner extension header. +*/ +if (skb->encapsulation &&skb_inner_network_header_was_set (skb) && +__skb_has_ipv6_ext_hdr (skb,skb_inner_network_offset (skb))) +return true; + +return false; } static netdev_features_t gso_features_check(const struct sk_buff *skb,
@@ -3654,7 +3670,7 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb,* so neither does TSO that depends on it. */ if (features &NETIF_F_IPV6_CSUM && -skb_gso_has_extension_hdr (skb) && +skb_has_ipv6_extension_hdr (skb) && !ipv6_has_hopopt_jumbo (skb)) features &= ~(NETIF_F_IPV6_CSUM |NETIF_F_TSO6 |NETIF_F_GSO_UDP_L4 );
@@ -3757,8 +3773,7 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,return 0 ;if (features & (NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM )) { -if (vlan_get_protocol (skb) ==htons (ETH_P_IPV6 ) && -skb_network_header_len (skb) !=sizeof (struct ipv6hdr ) && +if (skb_has_ipv6_extension_hdr (skb) && !ipv6_has_hopopt_jumbo (skb)) goto sw_checksum;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 472/2857 smb: client: discard post-EOF pagecache when extending a file via clone range
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 4721587f96cb8de8164f3fd203093a0875560999 ]
cifs_remap_file_range() discarded the pagecache only for the folios overlapping the destination region, so when a clone extends the file the folio straddling the old EOF - which may hold data dirtied past EOF through an mmap - was never dropped and became visible as file content once the file was extended.
Start the discard at the smaller of fstart and the old EOF. i_size is still old here, so nothing past the old EOF is flushed to the server.
--- fs/smb/client/cifsfs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/smb/client/cifsfs.c +8 -2
@@ -1366,9 +1366,15 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,if (rc) goto unlock; -/* Discard all the folios that overlap the destination region. */ +/* +* Discard all the folios that overlap the destination region. Start at +* the old EOF when extending so the folio straddling it, which may hold +* data written past EOF through an mmap, is dropped too. +*/ cifs_dbg (FYI ,"about to discard pages %llx-%llx\n" , fstart, fend); -truncate_inode_pages_range (&target_inode->i_data, fstart, fend); +truncate_inode_pages_range (&target_inode->i_data, + min_t(unsigned long long, fstart, +i_size_read (target_inode)), fend);fscache_invalidate (cifs_inode_cookie (target_inode),NULL ,i_size_read (target_inode),0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 473/2857 smb: client: flush and commit data before querying allocated ranges
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit aa994489bd835547c191827acc460192e147032d ]
The mode 0 / FALLOC_FL_KEEP_SIZE fallocate emulation for small interior ranges in smb3_simple_fallocate_range() issues FSCTL_QUERY_ALLOCATED_RANGES and zero-fills any sub-range the server reports as an unallocated hole, to force block allocation without changing file contents.
This is unsafe against Windows servers. Per the Win32 documentation, FSCTL_QUERY_ALLOCATED_RANGES only reports ranges that *may* contain nonzero data and is explicitly not coherent with recently written data:
"a call to FSCTL_QUERY_ALLOCATED_RANGES [after writing to a network
file] would not necessarily return a correct list of allocated regions. To ensure coherency [...] flush the data to the file"
fsx (generic/363) reproduces the resulting corruption against Windows Server 2022: a range is written, an uncached read returns the data, yet the next FSCTL_QUERY_ALLOCATED_RANGES on that range reports it as a whole hole, so the emulation overwrites live data with zeroes. A network trace confirmed the WRITE, the READ returning data and the query returning an empty range list within microseconds. Samba does not exhibit this; its query is coherent with the written data.
Write back the dirty pages, drain any outstanding I/O and issue an SMB2 FLUSH to force the server to commit the data before querying the allocated ranges, so the query reflects the data actually present.
With this, generic/363 passes against both Windows Server 2022 and Samba over 100000 fsx operations.
--- fs/smb/client/smb2ops.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
fs/smb/client/smb2ops.c +27 -8
@@ -3683,9 +3683,27 @@ static int smb3_simple_fallocate_range(unsigned int xid,u32 out_data_len;char *buf =NULL ;u64 range_start, range_len, range_end; +struct inode *inode =d_inode (cfile->dentry);loff_t l;int rc; +filemap_invalidate_lock (inode->i_mapping); + +/* +* Flush and commit the data to the server, otherwise +* FSCTL_QUERY_ALLOCATED_RANGES might report recently written data as +* unallocated holes on Windows Servers, and the loop below would +* then zero-fill them and corrupt the file. +*/ + rc =filemap_write_and_wait_range (inode->i_mapping, off, + off + len -1 ); +if (rc) + goto out_unlock; + rc =SMB2_flush (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid); +if (rc) + goto out_unlock; + in_data.file_offset =cpu_to_le64 (off); in_data.length =cpu_to_le64 (len); rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
@@ -3695,12 +3713,12 @@ static int smb3_simple_fallocate_range(unsigned int xid,1024 *sizeof (struct file_allocated_range_buffer ), (char **)&out_data, &out_data_len);if (rc) - goto out; + goto out_unlock; buf =kzalloc (1024 *1024 ,GFP_KERNEL );if (buf ==NULL ) { rc = -ENOMEM ; - goto out; + goto out_unlock; } tmp_data = out_data;
@@ -3711,12 +3729,12 @@ static int smb3_simple_fallocate_range(unsigned int xid,if (out_data_len ==0 ) { rc =smb3_simple_fallocate_write_range (xid, tcon, cfile, off, len, buf); - goto out; + goto out_unlock; }if (out_data_len <sizeof (struct file_allocated_range_buffer )) { rc = -EINVAL ; - goto out; + goto out_unlock; } range_start =le64_to_cpu (tmp_data->file_offset);
@@ -3724,7 +3742,7 @@ static int smb3_simple_fallocate_range(unsigned int xid,if (check_add_overflow (range_start, range_len, &range_end) || range_end >S64_MAX ) { rc = -EINVAL ; - goto out; + goto out_unlock; }if (off < range_start) {
@@ -3739,11 +3757,11 @@ static int smb3_simple_fallocate_range(unsigned int xid, rc =smb3_simple_fallocate_write_range (xid, tcon, cfile, off, l, buf);if (rc) - goto out; + goto out_unlock; off = off + l; len = len - l;if (len ==0 ) - goto out; + goto out_unlock; }/* * We are at a section of allocated data, just skip forward
@@ -3762,7 +3780,8 @@ static int smb3_simple_fallocate_range(unsigned int xid, out_data_len -=sizeof (struct file_allocated_range_buffer ); } - out: + out_unlock: +filemap_invalidate_unlock (inode->i_mapping);kfree (out_data);kfree (buf);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 474/2857 smb: client: flush dirty data before zeroing a range
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 8f8d32c1044f70e46e87550e039a15ff20a4b21c ]
smb3_zero_range() emulates FALLOC_FL_ZERO_RANGE by invalidating the page cache over the target range with truncate_pagecache_range() and then issuing FSCTL_SET_ZERO_DATA to the server.
Dirty data was only flushed conditionally, when the range reached or extended EOF. For a purely interior zero range that does not reach EOF, no flush happened, so a dirty folio overlapping the range could be written back to the server after the FSCTL and refill the range that was just zeroed with stale data.
Fix this by unconditionally flushing and waiting for dirty data in the range before invalidating the page cache and issuing FSCTL_SET_ZERO_DATA, exactly as was done for smb3_punch_hole() in commit d7d2adcd022b ("smb/client: flush dirty data before punching a hole"); the two paths are structurally identical here.
This is observed as generic/363 randomly reading stale data where a zeroed range is expected against Windows Server.
--- fs/smb/client/smb2ops.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
fs/smb/client/smb2ops.c +5 -9
@@ -3515,8 +3515,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,struct inode *inode =file_inode (file);struct cifsInodeInfo *cifsi =CIFS_I (inode);struct cifsFileInfo *cfile = file->private_data; -struct netfs_inode *ictx =netfs_inode (inode); -unsigned long long i_size, new_size, remote_size; +unsigned long long i_size, new_size;long rc;unsigned int xid;__le64 eof;
@@ -3530,14 +3529,11 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,filemap_invalidate_lock (inode->i_mapping); i_size =i_size_read (inode); - remote_size = ictx->remote_i_size; -if (offset + len >= remote_size && offset < i_size) { -unsigned long long top =umin (offset + len, i_size); - rc =filemap_write_and_wait_range (inode->i_mapping, offset, top -1 ); -if (rc <0 ) - goto zero_range_exit; - } + rc =filemap_write_and_wait_range (inode->i_mapping, offset, + offset + len -1 ); +if (rc <0 ) + goto zero_range_exit;/* * We zero the range through ioctl, so we need remove the page caches
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 475/2857 smb: client: drain and invalidate before server-side copy/clone
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit c9b1194e8ec99d95db25db45edd2fbf690f043ab ]
cifs_file_copychunk_range() and the clone (FICLONE) path of cifs_remap_file_range() do not serialise the destination page cache against the server-side copy the way the other server-side range operations (smb3_zero_range(), smb3_punch_hole(), smb3_collapse_range() and smb3_insert_range()) do.
cifs_file_copychunk_range() invalidates the destination range with filemap_invalidate_inode(), which takes and drops the mapping's invalidate_lock internally, so the lock is no longer held when the copychunk ioctl is issued. It also never drains in-flight netfs I/O on the target. The clone path never takes the invalidate_lock at all (only i_rwsem), uses a bare truncate_inode_pages_range() and likewise does not drain outstanding I/O.
As a result an asynchronous destination writeback can complete after the server-side copy/clone has run and reinstate stale data over the region just written by the server, corrupting the file. This is the same class of corruption as commit d7d2adcd022b ("smb/client: flush dirty data before punching a hole") and has been seen randomly in generic/363 against Windows Server.
Fix both paths to follow the established ordering: hold the target mapping's invalidate_lock across the flush and invalidation of the destination and the server ioctl, and call netfs_wait_for_outstanding_io() on the target to drain in-flight writes before the ioctl is issued. Only the target inode's invalidate_lock is required, as the source is merely flushed and not invalidated; i_rwsem (already held via lock_two_nondirectories()) is acquired before the invalidate_lock, matching the VFS lock ordering. Since filemap_invalidate_inode() takes that same lock internally, replace it with its own unmap/flush/invalidate steps instead of calling it, and return early on a zero-length copy to avoid a range underflow.
--- fs/smb/client/cifsfs.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/cifsfs.c +7 -0
@@ -1317,6 +1317,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,* server could even support copy of range where source = target */ lock_two_nondirectories (target_inode, src_inode); +filemap_invalidate_lock (target_inode->i_mapping);if (len ==0 ) {loff_t src_size =i_size_read (src_inode);
@@ -1409,6 +1410,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,that target is updated on the server */ CIFS_I (target_inode)->time =0 ; unlock: +filemap_invalidate_unlock (target_inode->i_mapping);/* although unlocking in the reverse order from locking is not strictly necessary here it is a little cleaner to be consistent */ unlock_two_nondirectories (src_inode, target_inode);
@@ -1432,6 +1434,9 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,unsigned long long destend, fstart, fend;ssize_t rc; +if (len ==0 ) +return 0 ; +cifs_dbg (FYI ,"copychunk range\n" );if (!src_file->private_data || !dst_file->private_data) {
@@ -1461,6 +1466,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,* server could even support copy of range where source = target */ lock_two_nondirectories (target_inode, src_inode); +filemap_invalidate_lock (target_inode->i_mapping);cifs_dbg (FYI ,"about to flush pages\n" );
@@ -1513,6 +1519,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,CIFS_I (target_inode)->time =0 ; unlock: +filemap_invalidate_unlock (target_inode->i_mapping);/* although unlocking in the reverse order from locking is not * strictly necessary here it is a little cleaner to be consistent */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 476/2857 smb: client: only require read lease for size-extending zero range
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit fafc68cccf8a00ed0a1f47c1413a3f16ce4dcdfa ]
smb3_zero_range() refuses any FALLOC_FL_ZERO_RANGE that clears FALLOC_FL_KEEP_SIZE with -EOPNOTSUPP whenever the inode is not read caching:
/* if file not oplocked can't be sure whether asking to extend size */ rc = -EOPNOTSUPP; if (keep_size == false && !CIFS_CACHE_READ(cifsi)) goto zero_range_exit;
The read lease is only needed to trust the cached i_size when deciding whether the range extends the file. When it is not held, the size can instead be fetched from the server, which is authoritative, rather than refusing the request outright: query the server's end of file and take the larger of it and the cached size for the interior-vs-extend decision. The larger of the two is used because the server's end of file reflects another client's growth while the cached size reflects this client's own writes that may not have reached the server yet; using the server size alone would wrongly shrink the file when the range flush above left an extending write unwritten.
The query isn't lease-protected either, so its result is only trusted to confirm the range is interior, never to justify extending: if it still shows the range going past EOF, refuse with -EOPNOTSUPP instead of calling SMB2_set_eof(), which could otherwise shrink the file if another client extended it further between the query and the call. For the same reason, take the larger of the already-computed i_size and a fresh i_size_read(inode) right before that call, instead of relying on either
alone: the local variable carries the query's result, which is never written back to the inode, while a concurrent write on this client can still extend the cached i_size during the flush, the query, or the zero-data round trip that happen in between.
Rejecting interior ranges is observed as generic/363 randomly failing against Windows Server with
do_zero_range: fallocate: Operation not supported
fsx issues an interior, non-KEEP_SIZE zero range while the inode is transiently not read caching: the server had just downgraded the file's lease from RWH to RH after breaking the write caching, and the ensuing handle reopen/revalidation left CIFS_CACHE_READ momentarily clear. The range sat well within the server's end of file, so no extend was needed, yet the range was refused and fsx aborted. This keeps the emulation correct even when a genuine lease break from another client leaves the inode without read caching -- the case the -EOPNOTSUPP guard turned into a hard failure. The extra round trip only happens on the no-lease path; the common cached case is unchanged.
--- fs/smb/client/smb2ops.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
fs/smb/client/smb2ops.c +28 -7
@@ -3507,6 +3507,21 @@ static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon, 0, NULL, NULL); } +static long query_server_eof (const unsigned int xid, +struct cifs_tcon *tcon, +struct cifsFileInfo *cfile, +unsigned long long *eof) +{ +struct smb2_file_all_info file_inf = {}; +long rc; + + rc =SMB2_query_info (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, &file_inf); +if (!rc) + *eof =le64_to_cpu (file_inf.EndOfFile); +return rc; +} +static long smb3_zero_range (struct file *file,struct cifs_tcon *tcon,unsigned long long offset,unsigned long long len,bool keep_size)
@@ -3515,7 +3530,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,struct inode *inode =file_inode (file);struct cifsInodeInfo *cifsi =CIFS_I (inode);struct cifsFileInfo *cfile = file->private_data; -unsigned long long i_size, new_size; +unsigned long long i_size, remote_i_size, new_size;long rc;unsigned int xid;__le64 eof;
@@ -3544,10 +3559,17 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,*/ truncate_pagecache_range (inode,min (offset, i_size), offset + len -1 ); -/* if file not oplocked can't be sure whether asking to extend size */ - rc = -EOPNOTSUPP ; -if (keep_size == false && !CIFS_CACHE_READ (cifsi)) - goto zero_range_exit; + new_size = offset + len; +if (!keep_size && !CIFS_CACHE_READ (cifsi)) { + rc =query_server_eof (xid, tcon, cfile, &remote_i_size); +if (rc) + goto zero_range_exit; + i_size =max (i_size, remote_i_size); +if (i_size < new_size) { + rc = -EOPNOTSUPP ; + goto zero_range_exit; + } + } rc =smb3_zero_data (file, tcon, offset, len, xid);if (rc <0 )
@@ -3556,8 +3578,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,/* * do we also need to change the size of the file? */ - new_size = offset + len; -if (keep_size == false && (unsigned long long )i_size_read (inode) < new_size) { +if (!keep_size &&umax (i_size,i_size_read (inode)) < new_size) { eof =cpu_to_le64 (new_size); rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, &eof);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 477/2857 dm-integrity: validate the superblock on resume
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit fc79aeb86a2c244c1f1894e2d8f2966fe2b60fa2 ]
dm_integrity_resume() re-reads the superblock from the device so that it picks up the flags and the recalculate position. It performs no validation on the result, while the constructor validates the superblock it reads and sizes all the in-memory structures according to it. The user may modify the superblock on the underlying device while the dm-integrity device is suspended, so that the two no longer agree.
In particular, access_journal_data() shifts the journal entry index by ic->sb->log2_sectors_per_block, while ic->journal_section_sectors and the journal page list were computed with the value that was present at constructor time. Increasing log2_sectors_per_block makes the index run past the end of the journal, and dm-integrity then writes 512 bytes through lowmem_page_address(NULL).
Snapshot the validated superblock in the constructor and refuse to resume if any of the fields that describe the on-disk geometry changed.
--- drivers/md/dm-integrity.c | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/md/dm-integrity.c +49 -0
@@ -171,6 +171,7 @@ struct dm_integrity_c {struct dm_bufio_client *bufio;struct workqueue_struct *metadata_wq;struct superblock *sb; +struct superblock *sb_copy;unsigned int journal_pages;unsigned int n_bitmap_blocks;
@@ -3238,6 +3239,34 @@ static void dm_integrity_postsuspend(struct dm_target *ti) ic->journal_uptodate = true; } +/* +* The superblock is re-read from the device on every resume, so that we pick +* up the flags and the recalculate position. The geometry described by the +* superblock must not change though - the in-memory structures (and the +* journal in particular) were sized according to the superblock that was +* validated in the constructor. Reject a superblock that was modified behind +* our back. +* +* Only the fields that the driver never rewrites may be tested here. In +* particular, "version" is recalculated by sb_set_version on every superblock +* write and it depends on SB_FLAG_RECALCULATING and SB_FLAG_DIRTY_BITMAP, and +* SB_FLAG_DISCARD_KEYED may be set by dm_integrity_resume itself. +*/ +static bool superblock_changed (struct dm_integrity_c *ic) +{ +const __le32 immutable_flags =cpu_to_le32 (SB_FLAG_HAVE_JOURNAL_MAC | +SB_FLAG_FIXED_PADDING | +SB_FLAG_FIXED_HMAC ); + +return memcmp (ic->sb->magic, ic->sb_copy->magic,sizeof (ic->sb->magic)) !=0 || + ic->sb->log2_interleave_sectors != ic->sb_copy->log2_interleave_sectors || + ic->sb->integrity_tag_size != ic->sb_copy->integrity_tag_size || + ic->sb->journal_sections != ic->sb_copy->journal_sections || + ic->sb->log2_sectors_per_block != ic->sb_copy->log2_sectors_per_block || + ((ic->sb->flags ^ ic->sb_copy->flags) & immutable_flags) !=0 || +memcmp (ic->sb->salt, ic->sb_copy->salt,SALT_SIZE ) !=0 ; +} +static void dm_integrity_resume (struct dm_target *ti) {struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private;
@@ -3254,6 +3283,18 @@ static void dm_integrity_resume(struct dm_target *ti)if (r)dm_integrity_io_error (ic,"reading superblock" , r); +if (unlikely (superblock_changed (ic))) { +/* +* Restore the superblock that we validated in the constructor, +* so that the rest of the driver doesn't operate on values +* that don't match the in-memory structures. +*/ +memcpy (ic->sb, ic->sb_copy,sizeof (struct superblock )); +DMERR ("The superblock was changed while the device was suspended" ); +dm_integrity_io_error (ic,"superblock check" , -EINVAL ); + goto skip_writes; + } +if (ic->mode =='R' ) goto skip_writes;
@@ -4667,6 +4708,13 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned int argc, char **argv ic->just_formatted = true; } + ic->sb_copy =kmemdup (ic->sb,sizeof (struct superblock ),GFP_KERNEL ); +if (!ic->sb_copy) { + ti->error ="Cannot allocate superblock copy" ; + r = -ENOMEM ; + goto bad; + } +if (!ic->meta_dev) { r =dm_set_target_max_io_len (ti,1U << ic->sb->log2_interleave_sectors);if (r)
@@ -4763,6 +4811,7 @@ static void dm_integrity_dtr(struct dm_target *ti)kvfree (ic->journal_tree);if (ic->sb)free_pages_exact (ic->sb,SB_SECTORS <<SECTOR_SHIFT ); +kfree (ic->sb_copy);if (ic->internal_hash)crypto_free_shash (ic->internal_hash);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 478/2857 perf: Replace perf_event_header__init_id with full header init
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit b9d1fdc6f4ac1b6e49f9deafaf137da1407d9af1 ]
perf_iterate_sb() invokes its callback for each matching perf_event on the CPU and task context, passing a shared caller-allocated event structure.
perf_event_header__init_id() mutated header->size in place by adding event->id_header_size, requiring sideband output callbacks to save and restore header fields across iterations. Three sideband callbacks failed to save and restore header.size around perf_event_header__init_id():
- perf_event_ksymbol_output()
- perf_event_bpf_output()
- perf_event_text_poke_output()
When multiple events with attr.ksymbol, attr.bpf_event, or attr.text_poke and sample_id_all are active on the same CPU, each subsequent event receives a record whose header.size is inflated by all preceding events' id_header_size values while only a single id_sample is written, leaving uninitialized ring-buffer bytes at the end of the record and causing userspace perf to fail with -EFAULT ("Bad address") when parsing the sample_id trailer.
Similarly, perf_event_mmap_output() set PERF_RECORD_MISC_MMAP_BUILD_ID in mmap_event->event_id.header.misc when event->attr.build_id was enabled, but only saved and restored header.size and header.type. If an event with attr.build_id was followed by an event with attr.mmap2 and !attr.build_id, the second event received PERF_RECORD_MISC_MMAP_BUILD_ID in header.misc while its payload contained maj/min/ino/ino_generation instead of a build ID.
Rather than splitting header initialization between callers and output callbacks and saving/restoring mutated header fields, replace perf_event_header__init_id() with perf_event_header__init(), which initializes header->type, header->misc, and header->size alongside the sample_id fields on each invocation.
--- arch/powerpc/perf/imc-pmu.c | 23 +-- include/linux/perf_event.h | 7 +- kernel/events/core.c | 288 +++++++++++++++--------------------- kernel/events/ring_buffer.c | 7 +- 4 files changed, 140 insertions(+), 185 deletions(-)
arch/powerpc/perf/imc-pmu.c +12 -11
@@ -1279,6 +1279,8 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem,struct perf_event_header *header, struct perf_event *event) { + u16 misc = 0; +/* Sanity checks for a valid record */ if (be64_to_cpu (READ_ONCE (mem->tb1)) > *prev_tb) *prev_tb =be64_to_cpu (READ_ONCE (mem->tb1));
@@ -1293,23 +1295,19 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem, data->ip =be64_to_cpu (READ_ONCE (mem->ip)); data->period = event->hw.last_period; - header->type =PERF_RECORD_SAMPLE ; - header->size =sizeof (*header) + event->header_size; - header->misc =0 ; -if (cpu_has_feature (CPU_FTR_ARCH_31 )) {switch (IMC_TRACE_RECORD_VAL_HVPR (be64_to_cpu (READ_ONCE (mem->val)))) {case 0 :/* when MSR HV and PR not set in the trace-record */ - header->misc |=PERF_RECORD_MISC_GUEST_KERNEL ; + misc |=PERF_RECORD_MISC_GUEST_KERNEL ;break ;case 1 :/* MSR HV is 0 and PR is 1 */ - header->misc |=PERF_RECORD_MISC_GUEST_USER ; + misc |=PERF_RECORD_MISC_GUEST_USER ;break ;case 2 :/* MSR HV is 1 and PR is 0 */ - header->misc |=PERF_RECORD_MISC_KERNEL ; + misc |=PERF_RECORD_MISC_KERNEL ;break ;case 3 :/* MSR HV is 1 and PR is 1 */ - header->misc |=PERF_RECORD_MISC_USER ; + misc |=PERF_RECORD_MISC_USER ;break ;default :pr_info ("IMC: Unable to set the flag based on MSR bits\n" );
@@ -1317,11 +1315,14 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem, } }else {if (is_kernel_addr (data->ip)) - header->misc |=PERF_RECORD_MISC_KERNEL ; + misc |=PERF_RECORD_MISC_KERNEL ;else - header->misc |=PERF_RECORD_MISC_USER ; + misc |=PERF_RECORD_MISC_USER ; } -perf_event_header__init_id (header, data, event); +perf_event_header__init (header, data, +PERF_RECORD_SAMPLE , misc, +sizeof (*header) + event->header_size, + event);return 0 ; }
include/linux/perf_event.h +4 -3
@@ -1172,9 +1172,10 @@ static inline bool uses_default_overflow_handler(struct perf_event *event)#endif extern void -perf_event_header__init_id (struct perf_event_header *header, -struct perf_sample_data *data, -struct perf_event *event); +perf_event_header__init (struct perf_event_header *header, +struct perf_sample_data *data, +u32 type,u16 misc,u16 size, +struct perf_event *event); extern void perf_event__output_id_sample(struct perf_event *event, struct perf_output_handle *handle,
kernel/events/core.c +121 -167
608 lines not on this page · raw message
kernel/events/ring_buffer.c +3 -4
@@ -241,14 +241,13 @@ __perf_output_begin(struct perf_output_handle *handle, handle->size = (1UL << page_shift) - offset;if (unlikely (have_lost)) { - lost_event.header.size =sizeof (lost_event); - lost_event.header.type =PERF_RECORD_LOST ; - lost_event.header.misc =0 ; lost_event.id = event->id; lost_event.lost =local_xchg (&rb->lost,0 );/* XXX mostly redundant; @data is already fully initializes */ -perf_event_header__init_id (&lost_event.header, data, event); +perf_event_header__init (&lost_event.header, data, +PERF_RECORD_LOST ,/* misc= */ 0 , +sizeof (lost_event), event);perf_output_put (handle, lost_event);perf_event__output_id_sample (event, handle, data); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 479/2857 namespace: check a recursive bind mount for mount namespace loops
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit c640a01a78e42302879006ed7b7d5a9a943ba815 ]
do_loopback() refuses to bind mount the file of a mount namespace that is as old as the caller's or older because a mount namespace that holds a mount of its own file, or of an ancestor's, would cause a cycle. But it only checks the dentry the bind mount starts from. With MS_REC everything below it is copied and do_loopback() passes CL_COPY_MNT_NS_FILE so mount namespace files below the source are copied.
That's fine for a source in the caller's own mount namespace. Every mount namespace file in there passed the same check when it was bind-mounted. It isn't fine for a source in another mount namespace. may_copy_tree() accepts a bind mount of any nsfs or pidfs file no matter what mount namespace it lives in so that /proc/<pid>/ns/<ns> and pidfds can be bind mounted. If we create a bind-mount stack of mount namespaces file descriptors the kernel will copy them irrespective of their ancestoral relationship to the mount namespace in question:
151 146 0:7 net:[4026531833] /tmp/nrc/y rw - nsfs nsfs rw 152 151 0:7 mnt:[4026532293] /tmp/nrc/y rw - nsfs nsfs rw
Mount 152 is a mount of the mount namespace file of mount namespace 4026532293 inside mount namespace 4026532293. That namespace and every mount in it are leaked... All it takes is a process in an older mount namespace that stacks the file and repeating it leaks without limit:
after control: Shmem: 380 kB
child: mount(/proc/self/fd/6, MS_BIND|MS_REC): ok
after cycle: Shmem: 65916 kB
do_move_mount() runs check_for_nsfs_mounts() over a detached tree for exactly that reason. Do the same for the copy before it is grafted.
--- fs/namespace.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-)
fs/namespace.c +27 -23
@@ -2468,6 +2468,28 @@ static struct mount *__do_loopback(struct path *old_path, int recurse)return mnt; } +/* +* Check that there aren't references to earlier/same mount namespaces in the +* specified subtree. Such references can act as pins for mount namespaces +* that aren't checked by the mount-cycle checking code, thereby allowing +* cycles to be made. +*/ +static bool check_for_nsfs_mounts (struct mount *subtree) +{ +struct mount *p; +bool ret = false; + +lock_mount_hash (); +for (p = subtree; p; p =next_mnt (p, subtree)) +if (mnt_ns_loop (p->mnt.mnt_root)) + goto out; + + ret = true; +out: +unlock_mount_hash (); +return ret; +} +/* * do loopback mount. */
@@ -2504,7 +2526,11 @@ static int do_loopback(struct path *path, const char *old_name, goto out2; } - err =graft_tree (mnt, parent, mp); +/* the copy may carry mount namespace files from below the source */ +if (recurse && !check_for_nsfs_mounts (mnt)) + err = -EINVAL ; +else + err =graft_tree (mnt, parent, mp);if (err) {lock_mount_hash ();umount_tree (mnt,UMOUNT_SYNC );
@@ -2790,28 +2816,6 @@ static inline int tree_contains_unbindable(struct mount *mnt)return 0 ; } -/* -* Check that there aren't references to earlier/same mount namespaces in the -* specified subtree. Such references can act as pins for mount namespaces -* that aren't checked by the mount-cycle checking code, thereby allowing -* cycles to be made. -*/ -static bool check_for_nsfs_mounts (struct mount *subtree) -{ -struct mount *p; -bool ret = false; - -lock_mount_hash (); -for (p = subtree; p; p =next_mnt (p, subtree)) -if (mnt_ns_loop (p->mnt.mnt_root)) - goto out; - - ret = true; -out: -unlock_mount_hash (); -return ret; -} -static int do_set_group (struct path *from_path,struct path *to_path) {struct mount *from, *to;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 480/2857 drm/amdgpu: skip the noirq suspend reset for a switcheroo-parked GPU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Theo Andersen Carton <[email protected]>
[ Upstream commit eadb85cca111152bd334b861fb53747ab851d13a ]
amdgpu_pmops_suspend_noirq() resets the ASIC unconditionally. When the GPU has been parked by vga_switcheroo it has neither power nor a PCIe link, so the reset cannot reach it: pci_set_power_state() reports the device as inaccessible and amdgpu_asic_reset() returns -EINVAL. A failure there aborts the entire noirq suspend phase, and with it the system suspend, so the machine cannot sleep at all while the GPU is switched off.
amdgpu_device_prepare(), amdgpu_device_suspend() and amdgpu_device_resume() all bail out early on DRM_SWITCH_POWER_OFF. This callback was added later, for an unrelated reason, and did not inherit the check. nouveau guards every one of its PM callbacks the same way.
Bail out the same way here. On a single-GPU system switch_power_state is never DRM_SWITCH_POWER_OFF, so this is a no-op there.
Found on a MacBookPro11,5, where the Radeon is powered down through apple-gmux so that the internal panel can be driven by the iGPU instead. Every suspend failed in amdgpu_pmops_suspend_noirq() while the card was off; with this check a full S3 cycle completes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +8 -0
@@ -2441,6 +2441,14 @@ static int amdgpu_pmops_suspend_noirq(struct device *dev)struct drm_device *drm_dev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (drm_dev); +/* +* A GPU parked by vga_switcheroo has no power and no PCIe link, so the +* ASIC reset below would fail and abort the whole noirq suspend phase. +* Bail out like amdgpu_device_prepare/suspend/resume() already do. +*/ +if (drm_dev->switch_power_state ==DRM_SWITCH_POWER_OFF ) +return 0 ; + adev->suspend_complete = true;if (amdgpu_acpi_should_gpu_reset (adev))return amdgpu_asic_reset (adev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 481/2857 drm/amd/display: guard dc_sink dereferences in MST mode validation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hari Mishal <[email protected]>
[ Upstream commit 217f64f348c90cba62164e7ff38e0ccf78a5ca09 ]
dm_dp_mst_is_port_support_mode() reads aconnector->dc_sink->dsc_caps... for the DSC branch-throughput check, and get_conv_frl_bw()'s HDMI-PCON FRL-bandwidth path reads aconnector->dc_sink->edid_caps.max_frl_rate, both without a NULL check. dc_sink is cleared asynchronously on MST unplug, and both functions run from paths that the driver's own comments document as racing that teardown: the connector probe worker's ->mode_valid callback and a compositor's atomic check, neither of which holds the MST manager lock that the teardown path uses. The former does have an existing dsc_aux NULL check, but dsc_aux isn't reliably cleared in every path that clears dc_sink, so it doesn't cover this.
Fail the port-support check and skip the FRL conversion path when the sink is already gone.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +3 -0
@@ -1671,6 +1671,9 @@ enum dc_status dm_dp_mst_is_port_support_mode( }#endif +if (!aconnector->dc_sink) +return DC_FAIL_BANDWIDTH_VALIDATE ; +/* check is mst dsc output bandwidth branch_overall_throughput_0_mps */ switch (stream->timing.pixel_encoding) {case PIXEL_ENCODING_RGB :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 482/2857 namespace: never expire a locked mount
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit f78ddcc872248c7aa1d7e904928441a0be4c6d5d ]
Locked mounts are special. They protect the underlying files and directories from being revealed. do_umount() refuses to unmount locked mounts but shrink_submounts() doesn't.
A shrinkable mount can become locked once the owner of a user namespace puts it beneath a locked mount with MOVE_MOUNT_BENEATH. The locked property now moves to the mount at the bottom making it possible to unmount the top mount.
So umount() of an unlocked ancestor now expires the bottom mount first and the covered directory is revealed:
move_mount(c -> x/hidden, MOVE_MOUNT_BENEATH) = 0
the cover after the lock moved: umount2(x/hidden) = 0 the holder of the lock: umount2(x/hidden) = EINVAL the root of the copy, busy: umount2(x) = EBUSY
reads x/hidden/secret: "covered-by-root"
So leave a locked mount alone as it dies together with its parent. A plain umount() of an unlocked mount with a locked one below it is EBUSY from now on. It's the same for any other locked child. A lazy umount still takes the whole tree.
mark_mounts_for_expiry() never sees a locked mount. lock_mnt_tree() leaves a mount on an expiry list alone and nothing else puts a locked one on such a list. Add an assert for this.
--- fs/namespace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/namespace.c +4 -1
@@ -3221,6 +3221,8 @@ void mark_mounts_for_expiry(struct list_head *mounts)* cleared by mntput()) */ list_for_each_entry_safe (mnt, next, mounts, mnt_expire) { +/* lock_mnt_tree() leaves expirable mounts alone */ +WARN_ON_ONCE (IS_MNT_LOCKED (mnt));if (!xchg (&mnt->mnt_expiry_mark,1 ) ||propagate_mount_busy (mnt,1 ))continue ;
@@ -3249,7 +3251,8 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);*/ static bool shrink_submount (struct mount *mnt) { -if (propagate_mount_busy (mnt,1 )) +/* not the kernel's to remove either */ +if (IS_MNT_LOCKED (mnt) ||propagate_mount_busy (mnt,1 ))return false;touch_mnt_namespace (mnt->mnt_ns);umount_tree (mnt,UMOUNT_PROPAGATE |UMOUNT_SYNC );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 483/2857 regulator: of: fill in supply names in of_regulator_bulk_get_all()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
[ Upstream commit e2151c29cec73f6cc70abf1c7cbc7b9b202489f5 ]
of_regulator_bulk_get_all() returns an array it allocated itself, and fills in only the consumer of each entry. Every other way of getting a bulk array has the supply name set, because the caller provides it, and the core expects it to be there: regulator_bulk_enable() prints it when a supply fails to enable, so a caller that hands such an array to it dereferences uninitialised memory on that path.
Copy each name into the array's own allocation, right behind the entries, so that it shares the array's lifetime and callers still have nothing extra to free. That also retires the fixed 64 byte stack buffer the names were assembled in, which is_supply_name() never bounded the copy against.
--- drivers/regulator/of_regulator.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/regulator/of_regulator.c +18 -9
@@ -755,16 +755,16 @@ static int is_supply_name(const char *name)int of_regulator_bulk_get_all (struct device *dev,struct device_node *np,struct regulator_bulk_data **consumers) { -int num_consumers =0 ; +int num_consumers =0 , names_len =0 ;struct regulator *tmp;struct property *prop; +char *names;int i, n =0 , ret; -char name[64 ]; *consumers =NULL ;/* -* first pass: get numbers of xxx-supply +* first pass: get numbers of xxx-supply and the room their names take * second pass: fill consumers */ restart:
@@ -774,16 +774,19 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,continue ;if (!*consumers) { num_consumers++; + names_len += i +1 ;continue ; }else { -memcpy (name, prop->name, i); - name[i] ='\0' ; - tmp =regulator_get (dev, name); +memcpy (names, prop->name, i); + names[i] ='\0' ; + tmp =regulator_get (dev, names);if (IS_ERR (tmp)) { ret =PTR_ERR (tmp); goto error; } + (*consumers)[n].supply = names; (*consumers)[n].consumer = tmp; + names += i +1 ; n++;continue ; }
@@ -792,11 +795,17 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,return num_consumers;if (num_consumers ==0 )return 0 ; - *consumers =kmalloc_array (num_consumers, -sizeof (struct regulator_bulk_data ), -GFP_KERNEL ); +/* +* The supply names are kept in the same allocation as the array, so +* that they share its lifetime and the caller has nothing extra to +* free. +*/ + *consumers =kzalloc (size_add (size_mul (num_consumers, +sizeof (struct regulator_bulk_data )), + names_len),GFP_KERNEL );if (!*consumers)return -ENOMEM ; + names = (char *)(*consumers + num_consumers); goto restart; error:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 484/2857 net: team: free skb when broadcast has no txable port
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 489114c9ecae44e523361a4b3e610ee5ebd9189c ]
bc_transmit() sends the original skb through the last txable port. When no port is txable, it returns false without consuming the skb, but team_xmit() still returns NETDEV_TX_OK. AF_PACKET sends then retain the skb and its socket write-memory charge.
A TX-enabled, link-down port keeps the broadcast transmit op installed. Carrier can stay up through a second link-up, TX-disabled port or be forced on by userspace. Free the original skb on the no-port path while leaving the existing drop accounting intact.
Discovered by Sashiko during review of previous commit.
--- drivers/net/team/team_mode_broadcast.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/team/team_mode_broadcast.c +2 -0
@@ -38,6 +38,8 @@ static bool bc_transmit(struct team *team, struct sk_buff *skb) ret = !team_dev_queue_xmit (team, last, skb);if (!sum_ret) sum_ret = ret; + }else { +dev_kfree_skb_any (skb); }return sum_ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 485/2857 drm/amd/display: Fix direct scanout alpha on some DRM_FORMATs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Li <[email protected]>
[ Upstream commit 7744262f5d63f9faa4d59dec127ae1c8b2d56495 ]
[Why]
DM was declaring it's own list of has_alpha DRM formats to check against for enabling alpha blending, when the format->has_alpha already does that for us.
The self-declared list missed some has_alpha formats, causing direct-scanout planes with such formats to appear opaque.
[How]
Drop the self-declared list, instead use the format->has_alpha field directly.
--- .../drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +1 -14
@@ -101,20 +101,7 @@ void fill_blending_from_plane_state(const struct drm_plane_state *plane_state,if (plane_state->pixel_blend_mode ==DRM_MODE_BLEND_PREMULTI || plane_state->pixel_blend_mode ==DRM_MODE_BLEND_COVERAGE ) { -static const uint32_t alpha_formats[] = { -DRM_FORMAT_ARGB8888 , -DRM_FORMAT_RGBA8888 , -DRM_FORMAT_ABGR8888 , - }; -uint32_t format = plane_state->fb->format->format; -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (alpha_formats); ++i) { -if (format == alpha_formats[i]) { - *per_pixel_alpha = true; -break ; - } - } + *per_pixel_alpha = plane_state->fb->format->has_alpha;if (*per_pixel_alpha && plane_state->pixel_blend_mode ==DRM_MODE_BLEND_COVERAGE ) *pre_multiplied_alpha = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 486/2857 drm/amdgpu: serialize vblank counter reads against GPU reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vitaly Prosyak <[email protected]>
[ Upstream commit 1a6023edfbb5673f55fab6348f135fb3b1428ea5 ]
The vblank counter callback reads display registers and scanout position without holding reset_domain->sem. During GPU recovery, display commit work can call the callback while reset owns the semaphore for writing. The hardware access then triggers the lockdep_assert_held() in amdgpu_device_skip_hw_access() and sets TAINT_WARN when lockdep is enabled.
Try to acquire the reset semaphore for reading before accessing the hardware, and hold it across the counter and scanout-position reads. If reset is already in progress, return DRM's cached software vblank count instead. This avoids blocking behind reset and avoids accessing display hardware while it is being reset.
The cached count is less accurate than the hardware count, but is used only when reset prevents a safe hardware read. This addresses the reset-time warning from this vblank path; it does not suppress or fix unrelated lockdep warnings.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
@@ -29,6 +29,7 @@#include "amdgpu.h" #include <drm/amdgpu_drm.h> #include <drm/drm_drv.h> +#include <drm/drm_vblank.h> #include "amdgpu_uvd.h" #include "amdgpu_vce.h" #include "atom.h"
@@ -42,6 +43,7 @@#include "amdgpu_gem.h" #include "amdgpu_display.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" void amdgpu_unregister_gpu_instance (struct amdgpu_device *adev) {
@@ -1315,6 +1317,9 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)DRM_ERROR ("Invalid crtc %u\n" , pipe);return -EINVAL ; } +if (!down_read_trylock (&adev->reset_domain->sem)) +return drm_crtc_vblank_count (crtc); +/* The hw increments its frame counter at start of vsync, not at start * of vblank, as is required by DRM core vblank counter handling.
@@ -1360,6 +1365,7 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)DRM_DEBUG_VBL ("NULL mode info! Returned count may be wrong.\n" ); } +up_read (&adev->reset_domain->sem);return count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 487/2857 Input: xpad - add support for Corsair Novablade Pro
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Furman <[email protected]>
[ Upstream commit f9282b8aa85a8c97c50d656db75feb6d76fc7cbe ]
Add device IDs for the Corsair Novablade Pro leverless fight controller in both wired (0x2b1f) and 2.4 GHz receiver (0x2b2b) modes, and add Corsair's vendor ID to the Xbox 360 vendor match list.
Outside of its PS4/PS5 modes the controller uses the Xbox 360 protocol (vendor-specific class, subclass 93, protocol 1) on interface 0, which xpad does not currently bind, so no gamepad device is created. The PS4/PS5 modes present a standard HID gamepad and already work with hid-generic.
Tested on 7.2.5 with the 2.4 GHz receiver and wired.
--- drivers/input/joystick/xpad.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/input/joystick/xpad.c +3 -0
@@ -307,6 +307,8 @@ static const struct xpad_device { { 0x16d0, 0x13ea, "Azeron Keyzen", 0, XTYPE_XBOX360 }, { 0x17ef, 0x6182, "Lenovo Legion Controller for Windows", 0, XTYPE_XBOX360 }, { 0x1949, 0x041a, "Amazon Game Controller", 0, XTYPE_XBOX360 }, + { 0x1b1c, 0x2b1f, "Corsair Novablade Pro (Wired)", 0, XTYPE_XBOX360 }, + { 0x1b1c, 0x2b2b, "Corsair Novablade Pro (2.4 GHz Receiver)", 0, XTYPE_XBOX360 }, { 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 }, { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, { 0x1bad, 0x0130, "Ion Drum Rocker", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
@@ -506,6 +508,7 @@ static const struct usb_device_id xpad_table[] = {XPAD_XBOX360_VENDOR (0x16d0 ),/* Azeron controllers */ XPAD_XBOX360_VENDOR (0x17ef ),/* Lenovo */ XPAD_XBOX360_VENDOR (0x1949 ),/* Amazon controllers */ +XPAD_XBOX360_VENDOR (0x1b1c ),/* Corsair controllers */ XPAD_XBOX360_VENDOR (0x1bad ),/* Harminix Rock Band Guitar and Drums */ XPAD_XBOX360_VENDOR (0x20d6 ),/* PowerA Controllers */ XPAD_XBOXONE_VENDOR(0x20d6), /* PowerA Controllers */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 488/2857 x86/kvm: Use separate percpu variable to track the enabling of asyncpf
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiaoyao Li <[email protected]>
[ Upstream commit ccb2280ec2f9e805d70f57a3a1c5deff0d532cb3 ]
Refer to commit fd10cde9294f ("KVM paravirt: Add async PF initialization to PV guest") and commit 344d9588a9df ("KVM: Add PV MSR to enable asynchronous page faults delivery"). It turns out that at the time when asyncpf was introduced, the purpose was defining the shared PV data 'struct kvm_vcpu_pv_apf_data' with the size of 64 bytes. However, it made a mistake and defined the size to 68 bytes, which failed to make fit in a cache line and made the code inconsistent with the documentation.
Below justification quoted from Sean[*]
KVM (the host side) has *never* read kvm_vcpu_pv_apf_data.enabled, and the documentation clearly states that enabling is based solely on the bit in the synthetic MSR.
So rather than update the documentation, fix the goof by removing the enabled filed and use the separate percpu variable instread. KVM-as-a-host obviously doesn't enforce anything or consume the size, and changing the header will only affect guests that are rebuilt against the new header, so there's no chance of ABI breakage between KVM and its guests. The only possible breakage is if some other hypervisor is emulating KVM's async #PF (LOL) and relies on the guest to set kvm_vcpu_pv_apf_data.enabled. But (a) I highly doubt such a hypervisor exists, (b) that would arguably be a violation of KVM's "spec", and
(c) the worst case scenario is that the guest would simply lose async #PF functionality.
[*] https://lore.kernel.org/all/[email protected]/T/#u
Stable-dep-of: 81d99abe2bd8 ("x86/kvm: Don't consume async #PF flags on a kernel #PF in NMI context")
--- Documentation/virt/kvm/x86/msr.rst | 1 - arch/x86/include/uapi/asm/kvm_para.h | 1 - arch/x86/kernel/kvm.c | 11 ++++++----- 3 files changed, 6 insertions(+), 7 deletions(-)
Documentation/virt/kvm/x86/msr.rst +0 -1
@@ -204,7 +204,6 @@ data: __u32 token; __u8 pad[56]; - __u32 enabled; }; Bits 5-4 of the MSR are reserved and should be zero. Bit 0 is set to 1
arch/x86/include/uapi/asm/kvm_para.h +0 -1
@@ -142,7 +142,6 @@ struct kvm_vcpu_pv_apf_data {__u32 token;__u8 pad[56 ]; -__u32 enabled; };#define KVM_PV_EOI_BIT 0
arch/x86/kernel/kvm.c +6 -5
@@ -65,6 +65,7 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc); +static DEFINE_PER_CPU_READ_MOSTLY(bool, async_pf_enabled); static DEFINE_PER_CPU_DECRYPTED(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64); DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64) __visible; static int has_steal_clock = 0;
@@ -244,7 +245,7 @@ noinstr u32 kvm_read_and_reset_apf_flags(void) {u32 flags =0 ; -if (__this_cpu_read (apf_reason.enabled)) { +if (__this_cpu_read (async_pf_enabled)) { flags =__this_cpu_read (apf_reason.flags);__this_cpu_write (apf_reason.flags,0 ); }
@@ -295,7 +296,7 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_kvm_asyncpf_interrupt)inc_irq_stat (irq_hv_callback_count); -if (__this_cpu_read (apf_reason.enabled)) { +if (__this_cpu_read (async_pf_enabled)) { token =__this_cpu_read (apf_reason.token);kvm_async_pf_task_wake (token);__this_cpu_write (apf_reason.token,0 );
@@ -362,7 +363,7 @@ static void kvm_guest_cpu_init(void)wrmsrl (MSR_KVM_ASYNC_PF_INT ,HYPERVISOR_CALLBACK_VECTOR );wrmsrl (MSR_KVM_ASYNC_PF_EN , pa); -__this_cpu_write (apf_reason.enabled,1 ); +__this_cpu_write (async_pf_enabled, true);pr_debug ("setup async PF for cpu %d\n" ,smp_processor_id ()); }
@@ -383,11 +384,11 @@ static void kvm_guest_cpu_init(void)static void kvm_pv_disable_apf (void ) { -if (!__this_cpu_read (apf_reason.enabled)) +if (!__this_cpu_read (async_pf_enabled))return ;wrmsrl (MSR_KVM_ASYNC_PF_EN ,0 ); -__this_cpu_write (apf_reason.enabled,0 ); +__this_cpu_write (async_pf_enabled, false);pr_debug ("disable async PF for cpu %d\n" ,smp_processor_id ()); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 489/2857 x86/kvm: Dont consume async #PF flags on a kernel #PF in NMI context
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: EJ Campbell <[email protected]>
[ Upstream commit 81d99abe2bd81379abfb595e403bbbee6fbfc624 ]
An async #PF "page not present" event arrives through the #PF vector, and its reason sits in the per-CPU apf_reason.flags until __kvm_handle_async_pf() reads and clears it. If an NMI arrives after the event is injected and before the #PF handler reads the flags, and the NMI handler itself takes a #PF, that fault reads and clears the flags belonging to the #PF it interrupted. It then finds interrupts disabled in the NMI context it interrupted, and panics:
Kernel panic - not syncing: Host injected async #PF in interrupt disabled region Call Trace: <NMI> panic+0x52/0x60 __kvm_handle_async_pf+0xb0/0xb0 exc_page_fault+0x71/0xb0 asm_exc_page_fault+0x27/0x30 RIP: 0010:__get_user_nocheck_8+0x6/0x20 perf_callchain_user+0x147/0x1a0 get_perf_callchain+0x12d/0x1c0 ... perf_event_nmi_handler+0x26/0x50 exc_nmi+0xe8/0x110 RIP: 0010:asm_exc_page_fault+0x0/0x30 </NMI>
The last RIP line shows the NMI landing on the first instruction of the #PF entry. perf with user call chains takes such a fault: the sampling NMI walks the user stack with __get_user(), which faults when a saved frame pointer is not a valid user address or the walk runs off the top of the stack. The same window exists when KVM, running as an L1 hypervisor with DELIVERY_AS_PF_VMEXIT, reads the flags itself after a #PF VM-exit.
The NMI entry code saves and restores CR2 for this nesting, but not the async #PF reason. Andy Lutomirski described the race, with perf as the example, when async #PF delivery was reworked in 2020 [1]. Saving and clearing the flags across the NMI, next to CR2, was discussed there but not merged.
Since that rework, Linux has stopped setting KVM_ASYNC_PF_SEND_ALWAYS, so the host delivers "page not present" only for user mode faults and a kernel-mode fault in NMI context (including kernel-mode #MC and #DB) cannot be an async page fault. In that case, return without touching the flags so that the interrupted handler finds them intact.
Tested on v7.3-rc5 in a 4-vCPU, 2 GiB guest restored from a snapshot whose memory is served on demand through userfaultfd, so that reading it back takes async #PFs, while every thread samples hardware cycles with user call chains and points its frame pointer at an unmapped page. Without this patch the guest panicked as above in 3 of 3 runs. With it, the guest survived 3 of 3 runs of 60 seconds, and the host counted 148,441 to 153,334 kvm_async_pf_not_present events in the first 20 seconds of each. On 6.18.50 the results were the same: the guest panicked without the patch and survived with it.
--- arch/x86/kernel/kvm.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)
arch/x86/kernel/kvm.c +29 -3
@@ -254,11 +254,39 @@ noinstr u32 kvm_read_and_reset_apf_flags(void) }EXPORT_SYMBOL_GPL (kvm_read_and_reset_apf_flags); +static __always_inline bool kvm_apf_reason_pending(void) +{ +return __this_cpu_read (async_pf_enabled) && +__this_cpu_read (apf_reason.flags); +} + noinstr bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token) { -u32 flags =kvm_read_and_reset_apf_flags ();irqentry_state_t state; +u32 flags; + +if (!kvm_apf_reason_pending ()) +return false; + +/* +* The guest does not enable KVM_ASYNC_PF_SEND_ALWAYS, so the host +* delivers async #PF only to user mode (or as a #PF VM-exit, which KVM +* reads itself). A #PF from kernel mode can still arrive between that +* delivery and the read of the reason flags, inside an NMI that +* interrupted it, for instance perf reading user memory for a call +* chain. Such a fault is not async, so leave the async PF flags +* untouched for the outer handler. Outside NMI context, on the other +* hand, async PF flags on a kernel-mode fault mean the host is broken. +*/ +if (!user_mode (regs)) { +if (likely (in_nmi ())) +return false; + state =irqentry_enter (regs); +instrumentation_begin (); +panic ("Host injected async #PF in kernel mode\n" ); + } + flags =kvm_read_and_reset_apf_flags ();if (!flags)return false;
@@ -274,8 +302,6 @@ noinstr bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token)panic ("Host injected async #PF in interrupt disabled region\n" );if (flags &KVM_PV_REASON_PAGE_NOT_PRESENT ) { -if (unlikely (!(user_mode (regs)))) -panic ("Host injected async #PF in kernel mode\n" );/* Page is swapped out by the host. */ kvm_async_pf_task_wait_schedule (token); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 490/2857 drm/i915/dmc: Add sanity check for DMC load address
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dibin Moolakadan Subrahmanian <[email protected]>
[ Upstream commit 7dedc5bb11f95e96fe80757c924d8d9aa7327759 ]
For DMC firmware header version 3, the firmware load address is stored in dmc_info->start_mmioaddr and later used by dmc_load_program().
Unlike the MMIO address table, the firmware load address is not validated. Add a sanity check to ensure it is within the valid range.
BSpec: 69671, 68378
--- drivers/gpu/drm/i915/display/intel_dmc.c | 55 +++++++++++++++++++ drivers/gpu/drm/i915/display/intel_dmc_regs.h | 12 ++++ 2 files changed, 67 insertions(+)
drivers/gpu/drm/i915/display/intel_dmc.c +55 -0
@@ -543,6 +543,55 @@ static void dmc_set_fw_offset(struct intel_dmc *dmc, } } +/* +* Check if the load address is within the valid range for the given DMC ID. +*/ +static bool dmc_load_addr_sanity_check (struct intel_dmc *dmc, +u32 start_addr,u32 payload_size, +int header_ver,u8 dmc_id) +{ +u32 start_range, end_range, end_addr; + +if (header_ver !=3 ) +return true; + +switch (dmc_id) { +case DMC_FW_MAIN : + start_range =DMC_MAIN_PROGRAM_BASE_START ; + end_range =DMC_MAIN_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPEA : + start_range =DMC_PIPEA_PROGRAM_BASE_START ; + end_range =DMC_PIPEA_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPEB : + start_range =DMC_PIPEB_PROGRAM_BASE_START ; + end_range =DMC_PIPEB_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPEC : + start_range =DMC_PIPEC_PROGRAM_BASE_START ; + end_range =DMC_PIPEC_PROGRAM_BASE_END ; +break ; +case DMC_FW_PIPED : + start_range =DMC_PIPED_PROGRAM_BASE_START ; + end_range =DMC_PIPED_PROGRAM_BASE_END ; +break ; +default : +MISSING_CASE (dmc_id); +return false; + } + +if (payload_size ==0 ) + end_addr = start_addr; +else if (check_add_overflow (start_addr, payload_size -1 , &end_addr)) +return false; + +if (start_addr < start_range || end_addr > end_range) +return false; + +return true; +} +static bool dmc_mmio_addr_sanity_check (struct intel_dmc *dmc,const u32 *mmioaddr,u32 mmio_count,int header_ver,u8 dmc_id)
@@ -683,6 +732,12 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc,return 0 ; } +if (!dmc_load_addr_sanity_check (dmc, start_mmioaddr, payload_size, + dmc_header->header_ver, dmc_id)) { +drm_err (&i915->drm,"DMC %d: firmware has wrong load address\n" , dmc_id); +return 0 ; + } + dmc_info->payload =kmalloc (payload_size,GFP_KERNEL );if (!dmc_info->payload)return 0 ;
drivers/gpu/drm/i915/display/intel_dmc_regs.h +12 -0
@@ -76,6 +76,18 @@#define TGL_PIPE_MMIO_END (dmc_id) _PICK_EVEN(((dmc_id) - 1), _TGL_PIPEA_MMIO_END,\ _TGL_PIPEB_MMIO_END) +/* For DMC header version v3*/ +#define DMC_MAIN_PROGRAM_BASE_START 0x80000 +#define DMC_MAIN_PROGRAM_BASE_END 0x86fff +#define DMC_PIPEA_PROGRAM_BASE_START 0x90000 +#define DMC_PIPEA_PROGRAM_BASE_END 0x96fff +#define DMC_PIPEB_PROGRAM_BASE_START 0x98000 +#define DMC_PIPEB_PROGRAM_BASE_END 0x9efff +#define DMC_PIPEC_PROGRAM_BASE_START 0x52000 +#define DMC_PIPEC_PROGRAM_BASE_END 0x53fff +#define DMC_PIPED_PROGRAM_BASE_START 0x59000 +#define DMC_PIPED_PROGRAM_BASE_END 0x5afff +#define SKL_DMC_DC3_DC5_COUNT _MMIO(0x80030)#define SKL_DMC_DC5_DC6_COUNT _MMIO(0x8002C)#define BXT_DMC_DC3_DC5_COUNT _MMIO(0x80038)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 491/2857 ipc: create_ipc_ns: drop mqueue mount on sysctl setup failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Kulikov <[email protected]>
[ Upstream commit 7229d74e5e8c1f140529d405c88d4493e37ce4e3 ]
If setup_mq_sysctls(ns) fails after mq_init_ns(ns) succeeds, the error path skipped releasing the internal kernel mqueue mount kept in ns->mq_mnt. That leaves the vfsmount/superblock referenced until final namespace teardown, i.e. a resource leak on this rare failure edge.
Unwind it by calling mntput(ns->mq_mnt) before dropping user_ns and freeing the IPC namespace. This mirrors the normal ordering used in free_ipc_ns().
Stable-dep-of: f0e48172a59e ("ipc: drop the mqueue mount with kern_unmount() on setup failure")
--- ipc/namespace.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
ipc/namespace.c +5 -4
@@ -61,10 +61,10 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, err = -ENOMEM ;if (!setup_mq_sysctls (ns)) - goto fail_put; + goto fail_mq_mount;if (!setup_ipc_sysctls (ns)) - goto fail_mq; + goto fail_mq_sysctls; err =msg_init_ns (ns);if (err)
@@ -77,9 +77,10 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, fail_ipc:retire_ipc_sysctls (ns); -fail_mq: +fail_mq_sysctls:retire_mq_sysctls (ns); - +fail_mq_mount: +mntput (ns->mq_mnt); fail_put:put_user_ns (ns->user_ns);ns_free_inum (&ns->ns);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 492/2857 ipc: drop the mqueue mount with kern_unmount() on setup failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit f0e48172a59e517e613b73f73cc35f24fd123aeb ]
mq_init_ns() creates the mqueue mount with fc_mount_longterm(), so its ->mnt_ns is MNT_NS_INTERNAL. When setting up the mqueue or ipc sysctls or msg_init_ns() fails afterwards, create_ipc_ns() drops it with a plain mntput(). With ->mnt_ns set that takes the fast path of mntput_no_expire(). The count drops to zero and nothing ever kills the mount, so the mount and the mqueue superblock are leaked.
Commit dc55e35f9e81 ("ipc: Store mqueue sysctls in the ipc namespace") added the first failure path after mq_init_ns() and never dropped the mount. Commit 7229d74e5e8c ("ipc: create_ipc_ns: drop mqueue mount on sysctl setup failure") tried to fix that with a mntput() but that doesn't help for a long-term mount.
Use kern_unmount(). free_ipc() open-codes the same thing for a namespace that made it.
--- ipc/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ipc/namespace.c +1 -1
@@ -80,7 +80,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, fail_mq_sysctls:retire_mq_sysctls (ns); fail_mq_mount: -mntput (ns->mq_mnt); +kern_unmount (ns->mq_mnt); fail_put:put_user_ns (ns->user_ns);ns_free_inum (&ns->ns);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 493/2857 tracing: Fix fully-qualified variable reference printing in histograms
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Zanussi <[email protected]>
[ Upstream commit 9236eebd138aa2753f7b30fc6cee7b7202841247 ]
The syntax for fully-qualified variable references in histograms is subsys.event.$var, which is parsed correctly, but not displayed correctly when printing a histogram spec. The current code puts the $ reference at the beginning of the fully-qualified variable name i.e. $subsys.event.var, which is incorrect.
Before:
trigger info: hist:keys=next_comm:vals=hitcount:wakeup_lat=common_timestamp.usecs-$sched.sched_wakeup.ts0: ...
After:
trigger info: hist:keys=next_comm:vals=hitcount:wakeup_lat=common_timestamp.usecs-sched.sched_wakeup.$ts0: ...
Stable-dep-of: a0777b9e5315 ("tracing: Fix NULL dereference when copying keys for a field variable")
--- kernel/trace/trace_events_hist.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
kernel/trace/trace_events_hist.c +10 -5
@@ -1339,9 +1339,12 @@ static const char *hist_field_name(struct hist_field *field, field->flags & HIST_FIELD_FL_VAR_REF) {if (field->system) {static char full_name[MAX_FILTER_STR_VAL ]; +static char *fmt;int len; - len =snprintf (full_name,sizeof (full_name),"%s.%s.%s" , + fmt = field->flags &HIST_FIELD_FL_VAR_REF ?"%s.%s.$%s" :"%s.%s.%s" ; + + len =snprintf (full_name,sizeof (full_name), fmt, field->system, field->event_name, field->name);if (len <sizeof (full_name))
@@ -1709,9 +1712,10 @@ static const char *get_hist_field_flags(struct hist_field *hist_field)static void expr_field_str (struct hist_field *field,char *expr) { -if (field->flags &HIST_FIELD_FL_VAR_REF ) -strcat (expr,"$" ); -else if (field->flags &HIST_FIELD_FL_CONST ) { +if (field->flags &HIST_FIELD_FL_VAR_REF ) { +if (!field->system) +strcat (expr,"$" ); + }else if (field->flags &HIST_FIELD_FL_CONST ) {char str[HIST_CONST_DIGITS_MAX ];snprintf (str,HIST_CONST_DIGITS_MAX ,"%llu" , field->constant);
@@ -5845,7 +5849,8 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)else if (field_name) {if (hist_field->flags &HIST_FIELD_FL_VAR_REF || hist_field->flags &HIST_FIELD_FL_ALIAS ) -seq_putc (m,'$' ); +if (!hist_field->system) +seq_putc (m,'$' );seq_printf (m,"%s" , field_name); }else if (hist_field->flags &HIST_FIELD_FL_TIMESTAMP )seq_puts (m,"common_timestamp" );
Signature · 1 line
2.53.0