6.1.188-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 631/1191 gpu: host1x: Avoid stack over-read in debug output helpers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikko Perttunen <[email protected]>
[ Upstream commit bc17ac285fb708f22a8fa2c0ed32eceb1d37e6d6 ]
host1x_debug_output() and host1x_debug_cont() used vsnprintf(), which returns the length the formatted string would have reached with an unbounded buffer. That return value was passed straight to o->fn as the number of bytes to emit.
This could cause a read past end of the output buffer if a call to host1x_debug_* produced a string longer than 256 bytes. This only affected the debugfs files as the printk debug sink ignores the number of bytes. In practice, this is very unlikely to occur.
Fix by switching to vscnprintf(), which returns the number of bytes actually written.
--- drivers/gpu/host1x/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/host1x/debug.c +2 -2
@@ -31,7 +31,7 @@ void host1x_debug_output(struct output *o, const char *fmt, ...)int len;va_start (args, fmt); - len =vsnprintf (o->buf,sizeof (o->buf), fmt, args); + len =vscnprintf (o->buf,sizeof (o->buf), fmt, args);va_end (args); o->fn (o->ctx, o->buf, len, false);
@@ -43,7 +43,7 @@ void host1x_debug_cont(struct output *o, const char *fmt, ...)int len;va_start (args, fmt); - len =vsnprintf (o->buf,sizeof (o->buf), fmt, args); + len =vscnprintf (o->buf,sizeof (o->buf), fmt, args);va_end (args); o->fn (o->ctx, o->buf, len, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 632/1191 bpf: Sync tail_call_reachable with callee state on entry
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pu Lehui <[email protected]>
[ Upstream commit 3513ea9dab6c1a3d2dc8e6160c41f690206948b6 ]
Currently in check_max_stack_depth_subprog, when the verifier enters a new callee branch, the local tail_call_reachable is not properly synchronized with the callee's state.
Consider a main prog branching into multiple subprogs:
subprog0 -> tailcall
main <
subprog1 -> subprog2When the verifier finishes checking subprog0 and backtracks to main prog, the local tail_call_reachable state is left as true. As it proceeds to subprog1, this uncleared state leaks into the new branch, falsely marking subprog1 and subprog2 as tailcall reachable.
Fix this by explicitly syncing tail_call_reachable with the callee's has_tail_call state on entry. The caller's state is safely preserved and restored via the existing backtracking logic.
--- kernel/bpf/verifier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +2 -2
@@ -4503,8 +4503,8 @@ static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx) i = next_insn; idx = sidx; -if (subprog[idx].has_tail_call) - tail_call_reachable = true; +/* sync tail_call_reachable with callee state on entry */ + tail_call_reachable = subprog[idx].has_tail_call; frame++;if (frame >=MAX_CALL_FRAMES ) {
Signature · 1 line
2.53.0
Re: [PATCH 6.1 0632/1191] bpf: Sync tail_call_reachable with callee state on entry
Please hold this patch unless 6.1 backports of upstream commits 01793ed86b5d ("bpf, verifier: Correct tail_call_reachable for bpf prog") and 54c27ea6dadb ("bpf: Fix tail_call_reachable leak") can also be included.
This patch resets tail_call_reachable on callee entry, but 6.1 lacks both the direct-tail-call initialization and the parent-state restoration it relies on. This can leave the root program falsely unmarked and make the x86 JIT omit required tail-call counter handling.
I reproduced this on 6.1.188-rc1 in QEMU: Linux permits 33 successful tail calls, so the test must stop after 34 program entries including the initial invocation. The unmodified rc1 reached 35, bypassing the limit.
With tested 6.1 adaptations of both commits applied, the same test stopped at the expected 34 entries.
Thanks,
Karl
Greg Kroah-Hartman
maintainerPATCH 633/1191 crypto: sl3516 - drop invalid sg_dma_len checks before DMA mapping
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 3ae59a2eba64b3648f069aa52eeaaeefdfe4bb2f ]
sg_dma_len() is only valid after mapping the scatterlist with dma_map_sg(). However, sl3516_ce_need_fallback() checks it before the source and destination scatterlists are mapped. Thus, a stale DMA length that is not a multiple of 16 could incorrectly force a software fallback when CONFIG_NEED_SG_DMA_LENGTH=y.
Remove the invalid checks; the existing scatterlist length checks are sufficient.
--- drivers/crypto/gemini/sl3516-ce-cipher.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/crypto/gemini/sl3516-ce-cipher.c +0 -8
@@ -52,10 +52,6 @@ static bool sl3516_ce_need_fallback(struct skcipher_request *areq) ce->fallback_mod16++;return true; } -if ((sg_dma_len (sg) %16 ) !=0 ) { - ce->fallback_mod16++; -return true; - }if (!IS_ALIGNED (sg->offset,16 )) { ce->fallback_align16++;return true;
@@ -68,10 +64,6 @@ static bool sl3516_ce_need_fallback(struct skcipher_request *areq) ce->fallback_mod16++;return true; } -if ((sg_dma_len (sg) %16 ) !=0 ) { - ce->fallback_mod16++; -return true; - }if (!IS_ALIGNED (sg->offset,16 )) { ce->fallback_align16++;return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 634/1191 ACPI: processor: idle: Expand _LPI package sanity checks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit d5c13047a132162d2649be876906ead691d12948 ]
The _LPI package sanity checks in acpi_processor_evaluate_lpi() miss a couple of things, so expand them by adding a buffer size check before retrieving a struct acpi_power_register from it (and skip the given state if the buffer is not large enough to hold a register structure) and making the function avoid copying the state description from the ACPI table if there are too few elements in the package supposed to hold it.
While at it, relocate and rephrase a comment about skipping _LPI state package elements [7-8].
--- drivers/acpi/processor_idle.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/acpi/processor_idle.c +21 -7
@@ -952,6 +952,13 @@ static int acpi_processor_evaluate_lpi(acpi_handle handle,if (obj->type ==ACPI_TYPE_BUFFER ) {struct acpi_power_register *reg; +if (obj->buffer.length <sizeof (*reg)) { +acpi_handle_debug (handle, +"Invalid register data for _LPI state %d\n" , + state_idx); +continue ; + } + reg = (struct acpi_power_register *)obj->buffer.pointer;if (reg->space_id !=ACPI_ADR_SPACE_SYSTEM_IO && reg->space_id !=ACPI_ADR_SPACE_FIXED_HARDWARE )
@@ -968,13 +975,6 @@ static int acpi_processor_evaluate_lpi(acpi_handle handle,continue ; } -/* elements[7,8] skipped for now i.e. Residency/Usage counter*/ - - obj = pkg_elem +9 ; -if (obj->type ==ACPI_TYPE_STRING ) -strscpy (lpi_state->desc, obj->string.pointer, -ACPI_CX_DESC_LEN ); - lpi_state->index = state_idx;if (obj_get_integer (pkg_elem +0 , &lpi_state->min_residency)) {pr_debug ("No min. residency found, assuming 10 us\n" );
@@ -997,6 +997,20 @@ static int acpi_processor_evaluate_lpi(acpi_handle handle,if (obj_get_integer (pkg_elem +5 , &lpi_state->enable_parent_state)) lpi_state->enable_parent_state =0 ; + +/* Skip elements [7-8] i.e. Residency/Usage counters. */ + +/* +* Avoid out-of-bounds access if the size of the package is less +* than expected. +*/ +if (element->package.count <10 ) +continue ; + + obj = pkg_elem +9 ; +if (obj->type ==ACPI_TYPE_STRING ) +strscpy (lpi_state->desc, obj->string.pointer, +ACPI_CX_DESC_LEN ); }acpi_handle_debug (handle,"Found %d power states\n" , state_idx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 635/1191 usb: gadget: f_uac1_legacy: remove broken string configfs attributes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Yang <[email protected]>
[ Upstream commit 590d74ec8f488e06b9f1c0f8f0941f45531f3a55 ]
The UAC1_STR_ATTRIBUTE macro defines configfs show/store handlers for the fn_play, fn_cap, and fn_cntl string options. The store function contains an inverted null check on the kstrndup() return value.
This means every write attempt returns -ENOMEM on success and dereferences a NULL pointer on allocation failure. The attributes have been broken and unused for many years.
Remove the UAC1_STR_ATTRIBUTE macro and the three attributes it generated. The internal defaults (FILE_PCM_PLAYBACK, FILE_PCM_CAPTURE, FILE_CONTROL) set in f_audio_alloc_inst() are unaffected.
--- .../testing/configfs-usb-gadget-uac1_legacy | 3 - Documentation/usb/gadget-testing.rst | 3 - drivers/usb/gadget/function/f_uac1_legacy.c | 56 ------------------- drivers/usb/gadget/function/u_uac1_legacy.h | 3 - 4 files changed, 65 deletions(-)
Documentation/ABI/testing/configfs-usb-gadget-uac1_legacy +0 -3
@@ -5,8 +5,5 @@ Description: The attributes: audio_buf_size - audio buffer size - fn_cap - capture pcm device file name - fn_cntl - control device file name - fn_play - playback pcm device file name req_buf_size - ISO OUT endpoint request buffer size req_count - ISO OUT endpoint request count
Documentation/usb/gadget-testing.rst +0 -3
@@ -701,9 +701,6 @@ The uac1 function provides these attributes in its function directory: =============== ==================================== audio_buf_size audio buffer size - fn_cap capture pcm device file name - fn_cntl control device file name - fn_play playback pcm device file name req_buf_size ISO OUT endpoint request buffer size req_count ISO OUT endpoint request count =============== ====================================
drivers/usb/gadget/function/f_uac1_legacy.c +0 -56
72 lines not on this page · raw message
drivers/usb/gadget/function/u_uac1_legacy.h +0 -3
@@ -62,9 +62,6 @@ struct f_uac1_legacy_opts {char *fn_cap;char *fn_cntl; unsigned bound:1; - unsigned fn_play_alloc:1; - unsigned fn_cap_alloc:1; - unsigned fn_cntl_alloc:1;struct mutex lock;int refcnt; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 636/1191 tty: hvc: restrict HVC_DCC to ARMv6+ and ARM64
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 782f4dbd1794b4f30dc116a7ca42c5962c409be8 ]
hvc_dcc drives the JTAG DCC via the ARMv6/v7 CP14 debug registers (mrc/mcr p14, 0, rX, c0, c1/c5, 0 in asm/dcc.h). That encoding is undefined on older ARM cores, and also on ARMv7-M, but HVC_DCC only depends on ARM, so it can be enabled on e.g. ARM926 (ARCH_MULTI_V5), where hvc_dcc_console_init() runs __dcc_putchar() at boot and takes an undefined-instruction trap before the console is up:
Internal error: Oops - undefined instruction: 0 [#1] ARM PC is at hvc_dcc_check+0x50/0x8c hvc_dcc_check from hvc_dcc_console_init+0x18/0x48 hvc_dcc_console_init from console_init+0x58/0x170 Kernel panic - not syncing: Fatal exception
Restrict HVC_DCC to the CPUs where that encoding is valid: the CPU_V6 || CPU_V6K || CPU_V7 set that arch/arm/include/debug/icedcc.S guards it with, plus ARM64.
--- drivers/tty/hvc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/hvc/Kconfig +1 -1
@@ -79,7 +79,7 @@ config HVC_UDBG config HVC_DCC bool "ARM JTAG DCC console" - depends on ARM || ARM64 + depends on (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || ARM64 select HVC_DRIVER select SERIAL_CORE_CONSOLE help
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 637/1191 UDF symlink pathComponent header OOB read
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lee <[email protected]>
[ Upstream commit d23eb7380d1594cda31a5dc8487dd2a5c8def8c7 ]
udf_symlink_filler() can enter udf_pc_to_char() with a partial pathComponent header.
Validate that enough input remains for a complete pathComponent header before accessing it. Reject malformed symlink data that would otherwise make udf_pc_to_char() perform an out-of-bounds read.
--- fs/udf/symlink.c | 2 ++ 1 file changed, 2 insertions(+)
fs/udf/symlink.c +2 -0
@@ -40,6 +40,8 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from,/* Reserve one byte for terminating \0 */ tolen--;while (elen < fromlen) { +if (fromlen - elen <sizeof (struct pathComponent )) +return -EIO ; pc = (struct pathComponent *)(from + elen); elen +=sizeof (struct pathComponent );switch (pc->componentType) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 638/1191 uio: Fix stale info pointer in failed registration path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 67b6fc084b034a91c3ec7907a3fed89a2450f30b ]
After device_add(), the UIO device is visible to userspace and /dev/uioX can be opened. If a later setup step fails, __uio_register_device() unwinds the device but leaves idev->info pointing at the caller-owned struct uio_info.
That is unsafe when an opener races with the failed registration path. The open file keeps a reference to the uio_device, while the caller sees registration failure and may free its struct uio_info. Later file operations can then follow idev->info and dereference freed memory.
Handle post-device_add() failures like unregister: remove UIO attributes while the info pointer is still valid, then clear idev->info under info_lock and wake existing waiters/async users before removing the device and minor. This makes already-open file descriptors observe the same "device gone" state as normal uio_unregister_device().
--- drivers/uio/uio.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/uio/uio.c +5 -0
@@ -990,6 +990,11 @@ int __uio_register_device(struct module *owner, err_request_irq:uio_dev_del_attributes (idev); err_uio_dev_add_attributes: +mutex_lock (&idev->info_lock); + idev->info =NULL ; +mutex_unlock (&idev->info_lock); +wake_up_interruptible (&idev->wait); +kill_fasync (&idev->async_queue,SIGIO ,POLL_HUP );device_del (&idev->dev); err_device_create:uio_free_minor (idev->minor);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 639/1191 accessibility: speakup: Fix incorrect string length computation in report_char_chartab_status()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit bce0e640623372520d9d90c42f33ddbfb576ce69 ]
snprintf() returns the "number of characters which *would* be generated for the given input", not the size *really* generated.
In order to avoid too large values for 'len' (and potential negative values for "sizeof(buf) - (len - 1)") use scnprintf() instead of snprintf().
--- drivers/accessibility/speakup/kobjects.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/accessibility/speakup/kobjects.c +3 -3
@@ -92,9 +92,9 @@ static void report_char_chartab_status(int reset, int received, int used,if (reset) {pr_info ("%s reset to defaults\n" , object_type[do_characters]); }else if (received) { - len =snprintf (buf,sizeof (buf), -" updated %d of %d %s\n" , - used, received, object_type[do_characters]); + len =scnprintf (buf,sizeof (buf), +" updated %d of %d %s\n" , + used, received, object_type[do_characters]);if (rejected) snprintf(buf + (len - 1), sizeof(buf) - (len - 1), " with %d reject%s\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 640/1191 speakup: keyhelp: guard letter_offsets possible out-of-range indexing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavel Zhigulin <[email protected]>
[ Upstream commit 6a19ad4d68c95185308cd9e5d169b10a2cf236c8 ]
help_init() builds letter_offsets[] by using the first byte of each function name as an index via (start & 31) - 1. If function_names are overridden from sysfs (root) with a name starting outside [a–z], the index underflows or exceeds the array, leading to OOB write.
Function names can be overridden with the following commands as root:
modprobe speakup_soft
echo "0 _bad" > /sys/accessibility/speakup/i18n/function_names # then press Insert+2 on /dev/tty
This fix checks the first letter in help_init(), and if it is not in the [a–z] range the function returns an error to the caller. Eventually this error is propagated to drivers/accessibility/speakup/main.c:2217, which causes a bleep sound.
--- drivers/accessibility/speakup/keyhelp.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/accessibility/speakup/keyhelp.c +12 -5
@@ -8,6 +8,7 @@*/ #include <linux/keyboard.h> +#include <linux/ctype.h> #include "spk_priv.h" #include "speakup.h"
@@ -111,7 +112,7 @@ static void say_key(int key) spk_msg_get(MSG_KEYNAMES_START + (key - 1))); } -static int help_init (void ) +static void help_init (void ) {char start =SPACE ;int i;
@@ -120,13 +121,19 @@ static int help_init(void) state_tbl = spk_our_keys[0 ] +SHIFT_TBL_SIZE +2 ;for (i =0 ; i < num_funcs; i++) {char *cur_funcname =spk_msg_get (MSG_FUNCNAMES_START + i); +char first_letter; -if (start == *cur_funcname) + first_letter =tolower (*cur_funcname); + +/* Accept only 'a'..'z' to index letter_offsets[] safely */ +if (first_letter <'a' || first_letter >'z' ) +continue ; + +if (start == first_letter)continue ; - start = *cur_funcname; + start = first_letter; letter_offsets[(start &31 ) -1 ] = i; } -return 0 ; }int spk_handle_help (struct vc_data *vc,u_char type,u_char ch,u_short key)
@@ -144,7 +151,7 @@ int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)synth_printf ("%s\n" ,spk_msg_get (MSG_LEAVING_HELP ));return 1 ; } - ch |=32 ;/* lower case */ + ch =tolower (ch);if (ch <'a' || ch >'z' )return -1 ;if (letter_offsets[ch -'a' ] ==-1 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 641/1191 misc: bcm-vk: Use acquire/release for msgq_inited
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gui-Dong Han <[email protected]>
[ Upstream commit 61b101c6a150057b6d512421ed108aed16e822ea ]
bcm_vk_sync_msgq() fills the message queue information and then sets msgq_inited. Readers call bcm_vk_drv_access_ok() before accessing the message queues and their cached queue information.
atomic_set()/atomic_read() do not order those accesses. A reader can see msgq_inited set while still seeing stale queue information. Use release when publishing the initialized queues and acquire when checking the gate.
Keep the clear in bcm_vk_blk_drv_access() as atomic_set(). It closes the gate and does not publish queue state to readers.
--- drivers/misc/bcm-vk/bcm_vk_msg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/misc/bcm-vk/bcm_vk_msg.c +4 -2
@@ -108,7 +108,8 @@ u32 msgq_avail_space(const struct bcm_vk_msgq __iomem *msgq,bool bcm_vk_drv_access_ok (struct bcm_vk *vk) { -return (!!atomic_read (&vk->msgq_inited)); +/* Pair with the release store after message queue initialization. */ +return !!atomic_read_acquire (&vk->msgq_inited); }void bcm_vk_set_host_alert (struct bcm_vk *vk,u32 bit_mask)
@@ -501,7 +502,8 @@ int bcm_vk_sync_msgq(struct bcm_vk *vk, bool force_sync) msgq++; } } -atomic_set (&vk->msgq_inited,1 ); +/* Publish message queue info before allowing driver access. */ +atomic_set_release (&vk->msgq_inited,1 );return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 642/1191 misc: rtsx: add missing write register handling
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gleb Markov <[email protected]>
[ Upstream commit 655faba1ccf195e22a7a83146ef6015e3271233c ]
If an error occurs at the stage of working with registers in conjunction with MCU_Block, it will not be processed.
The occurrence of errors at this stage may signal an impact on writes to the device's PCI registers and is a more global problem than a driver-level security problem, but adding a handler would be a good practice.
Add a missing error handling.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/misc/cardreader/rtsx_pcr.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/misc/cardreader/rtsx_pcr.c +2 -0
@@ -1230,6 +1230,8 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)/* Gating real mcu clock */ err =rtsx_pci_write_register (pcr,RTS5261_FW_CFG1 ,RTS5261_MCU_CLOCK_GATING ,0 ); +if (err <0 ) +return err; err =rtsx_pci_write_register (pcr,RTS5261_REG_FPDCTL ,SSC_POWER_DOWN ,0 ); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 643/1191 misc: ad525x_dpot: use driver core groups for sysfs files
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit e3a8557e88eb26278eda60bf64f2ef33ce7de8bf ]
ad_dpot_probe() creates per-RDAC sysfs files manually and then optionally creates the command sysfs group. This leaves probe responsible for rolling back partial sysfs state and makes remove responsible for matching every file that probe created.
Move the device attributes into driver core dev_groups for the I2C and SPI drivers and use an is_visible() callback to expose only the attributes supported by the probed device. With this shape, the driver core creates the sysfs files only after probe succeeds and removes them before the remove callback frees the driver data.
--- drivers/misc/ad525x_dpot-i2c.c | 1 + drivers/misc/ad525x_dpot-spi.c | 1 + drivers/misc/ad525x_dpot.c | 177 ++++++++++++++++++++------------- drivers/misc/ad525x_dpot.h | 3 + 4 files changed, 112 insertions(+), 70 deletions(-)
drivers/misc/ad525x_dpot-i2c.c +1 -0
@@ -105,6 +105,7 @@ MODULE_DEVICE_TABLE(i2c, ad_dpot_id);static struct i2c_driver ad_dpot_i2c_driver = { .driver = { .name ="ad_dpot" , + .dev_groups = ad_dpot_groups, }, .probe = ad_dpot_i2c_probe, .remove = ad_dpot_i2c_remove,
drivers/misc/ad525x_dpot-spi.c +1 -0
@@ -131,6 +131,7 @@ MODULE_DEVICE_TABLE(spi, ad_dpot_spi_id);static struct spi_driver ad_dpot_spi_driver = { .driver = { .name ="ad_dpot" , + .dev_groups = ad_dpot_groups, }, .probe = ad_dpot_spi_probe, .remove = ad_dpot_spi_remove,
drivers/misc/ad525x_dpot.c +107 -70
224 lines not on this page · raw message
drivers/misc/ad525x_dpot.h +3 -0
@@ -10,6 +10,8 @@#include <linux/types.h> +struct attribute_group ; +#define DPOT_CONF (features, wipers, max_pos, uid) \ (((features) << 18) | (((wipers) & 0xFF) << 10) | \ ((max_pos & 0xF) << 6) | (uid & 0x3F))
@@ -210,5 +212,6 @@ struct ad_dpot_bus_data {int ad_dpot_probe (struct device *dev,struct ad_dpot_bus_data *bdata,unsigned long devid,const char *name);void ad_dpot_remove (struct device *dev); +extern const struct attribute_group *ad_dpot_groups[];#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 644/1191 ppdev: prevent overflow when setting port timeout
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
[ Upstream commit 3c0cf801ea2fa40daa5e7d1e6d32adca5ff75ad9 ]
PPSETTIME64 supplies the timeval fields as s64 values, but pp_set_timeout() narrows tv_usec to int and calculates tv_sec * HZ in a signed long. Large positive values can therefore be truncated or overflow and install an unintended timeout.
Keep both fields as s64, reject a non-canonical microsecond value, and use timespec64_to_jiffies() to cap excessively large timeouts at MAX_JIFFY_OFFSET. This is a behavior change because both PPSETTIME ioctls could previously accept values with tv_usec >= USEC_PER_SEC. The validation follows the precedent set by sock_set_timeout().
--- drivers/char/ppdev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/char/ppdev.c +6 -4
@@ -340,15 +340,17 @@ static enum ieee1284_phase init_phase(int mode)return IEEE1284_PH_FWD_IDLE ; } -static int pp_set_timeout (struct pardevice *pdev,long tv_sec,int tv_usec) +static int pp_set_timeout (struct pardevice *pdev,s64 tv_sec,s64 tv_usec) { +struct timespec64 ts;long to_jiffies; -if ((tv_sec <0 ) || (tv_usec <0 )) +if (tv_sec <0 || tv_usec <0 || tv_usec >=USEC_PER_SEC )return -EINVAL ; - to_jiffies =usecs_to_jiffies (tv_usec); - to_jiffies += tv_sec *HZ ; + ts.tv_sec = tv_sec; + ts.tv_nsec = tv_usec *NSEC_PER_USEC ; + to_jiffies =timespec64_to_jiffies (&ts);if (to_jiffies <=0 )return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 645/1191 s390/con3215: Fix white space errors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Richter <[email protected]>
[ Upstream commit 55af33fdec50a9a88f0dc0f8b898db7399e32645 ]
Adjust white space according to coding guidelines.
Stable-dep-of: b6b5d64cb161 ("ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove")
--- drivers/s390/char/con3215.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/s390/char/con3215.c +9 -10
@@ -159,7 +159,7 @@ static void raw3215_mk_read_req(struct raw3215_info *raw) ccw->cmd_code =0x0A ;/* read inquiry */ ccw->flags =0x20 ;/* ignore incorrect length */ ccw->count =160 ; - ccw->cda = (__u32 )__pa (raw->inbuf); + ccw->cda = (__u32 )__pa (raw->inbuf); }/*
@@ -218,8 +218,7 @@ static void raw3215_mk_write_req(struct raw3215_info *raw) ccw[-1 ].flags |=0x40 ;/* use command chaining */ ccw->cmd_code =0x01 ;/* write, auto carrier return */ ccw->flags =0x20 ;/* ignore incorrect length ind. */ - ccw->cda = - (__u32 )__pa (raw->buffer + ix); + ccw->cda = (__u32 )__pa (raw->buffer + ix); count = len;if (ix + count >RAW3215_BUFFER_SIZE ) count =RAW3215_BUFFER_SIZE - ix;
@@ -642,7 +641,7 @@ static void raw3215_free_info(struct raw3215_info *raw)kfree (raw); } -static int raw3215_probe (struct ccw_device *cdev) +static int raw3215_probe (struct ccw_device *cdev) {struct raw3215_info *raw;int line;
@@ -675,7 +674,7 @@ static int raw3215_probe (struct ccw_device *cdev)return 0 ; } -static void raw3215_remove (struct ccw_device *cdev) +static void raw3215_remove (struct ccw_device *cdev) {struct raw3215_info *raw;unsigned int line;
@@ -694,7 +693,7 @@ static void raw3215_remove (struct ccw_device *cdev) } } -static int raw3215_set_online (struct ccw_device *cdev) +static int raw3215_set_online (struct ccw_device *cdev) {struct raw3215_info *raw;
@@ -705,7 +704,7 @@ static int raw3215_set_online (struct ccw_device *cdev)return raw3215_startup (raw); } -static int raw3215_set_offline (struct ccw_device *cdev) +static int raw3215_set_offline (struct ccw_device *cdev) {struct raw3215_info *raw;
@@ -940,7 +939,7 @@ static unsigned int tty3215_write_room(struct tty_struct *tty)/* * String write routine for 3215 ttys */ -static int tty3215_write (struct tty_struct * tty, +static int tty3215_write (struct tty_struct *tty,const unsigned char *buf,int count) {struct raw3215_info *raw = tty->driver_data;
@@ -1000,7 +999,7 @@ static void tty3215_flush_buffer(struct tty_struct *tty)/* * Disable reading from a 3215 tty */ -static void tty3215_throttle (struct tty_struct * tty) +static void tty3215_throttle (struct tty_struct *tty) {struct raw3215_info *raw = tty->driver_data;
@@ -1010,7 +1009,7 @@ static void tty3215_throttle(struct tty_struct * tty)/* * Enable reading from a 3215 tty */ -static void tty3215_unthrottle (struct tty_struct * tty) +static void tty3215_unthrottle (struct tty_struct *tty) {struct raw3215_info *raw = tty->driver_data;unsigned long flags;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 646/1191 s390/tty3270: add tty3270_create_view()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Schnelle <[email protected]>
[ Upstream commit a21e962e129db40ae08af9fc80ea7babf3632d77 ]
Will be used later for the console driver.
Stable-dep-of: b6b5d64cb161 ("ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove")
--- drivers/s390/char/tty3270.c | 57 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 24 deletions(-)
drivers/s390/char/tty3270.c +33 -24
@@ -953,27 +953,14 @@ static struct raw3270_fn tty3270_fn = { .resize = tty3270_resize }; -/* -* This routine is called whenever a 3270 tty is opened first time. -*/ -static int tty3270_install (struct tty_driver *driver,struct tty_struct *tty) +static int +tty3270_create_view (int index,struct tty3270 **newtp) { -struct raw3270_view *view;struct tty3270 *tp;int i, rc; -/* Check if the tty3270 is already there. */ - view =raw3270_find_view (&tty3270_fn, tty->index +RAW3270_FIRSTMINOR ); -if (!IS_ERR (view)) { - tp = container_of(view, struct tty3270, view); - tty->driver_data = tp; - tty->winsize.ws_row = tp->view.rows -2 ; - tty->winsize.ws_col = tp->view.cols; - tp->inattr =TF_INPUT ; - goto port_install; - } -if (tty3270_max_index < tty->index +1 ) - tty3270_max_index = tty->index +1 ; +if (tty3270_max_index < index +1 ) + tty3270_max_index = index +1 ;/* Allocate tty3270 structure on first open. */ tp =tty3270_alloc_view ();
@@ -981,7 +968,7 @@ static int tty3270_install(struct tty_driver *driver, struct tty_struct *tty)return PTR_ERR (tp); rc =raw3270_add_view (&tp->view, &tty3270_fn, - tty->index +RAW3270_FIRSTMINOR , + index +RAW3270_FIRSTMINOR ,RAW3270_VIEW_LOCK_BH );if (rc) {tty3270_free_view (tp);
@@ -997,9 +984,6 @@ static int tty3270_install(struct tty_driver *driver, struct tty_struct *tty)return rc; } - tty->winsize.ws_row = tp->view.rows -2 ; - tty->winsize.ws_col = tp->view.cols; -tty3270_create_prompt (tp);tty3270_create_status (tp);tty3270_update_status (tp);
@@ -1016,16 +1000,41 @@ static int tty3270_install(struct tty_driver *driver, struct tty_struct *tty)kbd_ascebc (tp->kbd, tp->view.ascebc);raw3270_activate_view (&tp->view); +raw3270_put_view (&tp->view); + *newtp = tp; +return 0 ; +} + +/* +* This routine is called whenever a 3270 tty is opened first time. +*/ +static int +tty3270_install (struct tty_driver *driver,struct tty_struct *tty) +{ +struct raw3270_view *view; +struct tty3270 *tp; +int rc; -port_install: +/* Check if the tty3270 is already there. */ + view =raw3270_find_view (&tty3270_fn, tty->index +RAW3270_FIRSTMINOR ); +if (IS_ERR (view)) { + rc =tty3270_create_view (tty->index, &tp); +if (rc) +return rc; + }else { + tp = container_of(view, struct tty3270, view); + tty->driver_data = tp; + tp->inattr =TF_INPUT ; + } + + tty->winsize.ws_row = tp->view.rows -2 ; + tty->winsize.ws_col = tp->view.cols; rc =tty_port_install (&tp->port, driver, tty);if (rc) {raw3270_put_view (&tp->view);return rc; } - tty->driver_data = tp; -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 647/1191 s390/3270: unify con3270 + tty3270
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Schnelle <[email protected]>
[ Upstream commit c17fe081ac1f397feaed6c8a279ebb3f647f359a ]
There were two flavours of 3270 drivers: con3270, which provides a console driver, and tty3270 providing a tty driver. A user could switch with PF3 between the two views. While this sounds nice, it's a bit
annoying: If the user enters a command which triggers a kernel message, he always has to switch back and forth to see the message. Unify both views to have kernel messages and tty in one screen, like it is on almost all other platforms. This also has the nice side effect of removing a lot of duplicate code.
Stable-dep-of: b6b5d64cb161 ("ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove")
--- drivers/s390/char/Makefile | 1 - drivers/s390/char/con3270.c | 651 ------------------------------------ drivers/s390/char/tty3270.c | 181 ++++++++-- drivers/s390/char/tty3270.h | 15 - 4 files changed, 158 insertions(+), 690 deletions(-) delete mode 100644 drivers/s390/char/con3270.c delete mode 100644 drivers/s390/char/tty3270.h
drivers/s390/char/Makefile +0 -1
@@ -22,7 +22,6 @@ obj-y += ctrlchar.o keyboard.o defkeymap.o sclp.o sclp_rw.o sclp_quiesce.o \ sclp_early.o sclp_early_core.o sclp_sd.o obj-$(CONFIG_TN3270) += raw3270.o -obj-$(CONFIG_TN3270_CONSOLE) += con3270.o obj-$(CONFIG_TN3270_TTY) += tty3270.o obj-$(CONFIG_TN3270_FS) += fs3270.o
drivers/s390/char/con3270.c deleted +0 -651
651 lines not on this page · raw message
drivers/s390/char/tty3270.c +158 -23
323 lines not on this page · raw message
drivers/s390/char/tty3270.h deleted +0 -15
@@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Copyright IBM Corp. 2007 -* -*/ - -#ifndef __DRIVERS_S390_CHAR_TTY3270_H -#define __DRIVERS_S390_CHAR_TTY3270_H - -#include <linux/tty.h> -#include <linux/tty_driver.h> - -extern struct tty_driver *tty3270_driver; - -#endif /* __DRIVERS_S390_CHAR_TTY3270_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 648/1191 s390/con3270: fix formatting issues
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Schnelle <[email protected]>
[ Upstream commit e6d98bb823af51ad8b89ee705111dbb1ed8a4aff ]
fix function prototypes split over two lines like:
static void
foobar(void)
and fix superfluous spaces in declarations like
foo * bar
Stable-dep-of: b6b5d64cb161 ("ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove")
--- drivers/s390/char/tty3270.c | 172 ++++++++++++------------------------ 1 file changed, 58 insertions(+), 114 deletions(-)
drivers/s390/char/tty3270.c +58 -114
@@ -134,8 +134,7 @@ static void tty3270_set_timer(struct tty3270 *tp, int expires)/* * The input line are the two last lines of the screen. */ -static void -tty3270_update_prompt (struct tty3270 *tp,char *input,int count) +static void tty3270_update_prompt (struct tty3270 *tp,char *input,int count) {struct string *line;unsigned int off;
@@ -161,8 +160,7 @@ tty3270_update_prompt(struct tty3270 *tp, char *input, int count) tp->update_flags |=TTY_UPDATE_INPUT ; } -static void -tty3270_create_prompt (struct tty3270 *tp) +static void tty3270_create_prompt (struct tty3270 *tp) {static const unsigned char blueprint[] = {TO_SBA ,0 ,0 ,0x6e ,TO_SF ,TF_INPUT ,
@@ -192,8 +190,7 @@ tty3270_create_prompt(struct tty3270 *tp)* The status line is the last line of the screen. It shows the string * "Running"/"Holding" in the lower right corner of the screen. */ -static void -tty3270_update_status (struct tty3270 * tp) +static void tty3270_update_status (struct tty3270 *tp) {char *str;
@@ -203,8 +200,7 @@ tty3270_update_status(struct tty3270 * tp) tp->update_flags |=TTY_UPDATE_STATUS ; } -static void -tty3270_create_status (struct tty3270 * tp) +static void tty3270_create_status (struct tty3270 *tp) {static const unsigned char blueprint[] = {TO_SBA ,0 ,0 ,TO_SF ,TF_LOG ,TO_SA ,TAT_COLOR ,TAC_GREEN ,
@@ -226,8 +222,7 @@ tty3270_create_status(struct tty3270 * tp)* Set output offsets to 3270 datastream fragment of a tty string. * (TO_SBA offset at the start and TO_RA offset at the end of the string) */ -static void -tty3270_update_string (struct tty3270 *tp,struct string *line,int nr) +static void tty3270_update_string (struct tty3270 *tp,struct string *line,int nr) {unsigned char *cp;
@@ -242,8 +237,7 @@ tty3270_update_string(struct tty3270 *tp, struct string *line, int nr)/* * Rebuild update list to print all lines. */ -static void -tty3270_rebuild_update (struct tty3270 *tp) +static void tty3270_rebuild_update (struct tty3270 *tp) {struct string *s, *n;int line, nr_up;
@@ -273,8 +267,7 @@ tty3270_rebuild_update(struct tty3270 *tp)* Alloc string for size bytes. If there is not enough room in * freemem, free strings until there is room. */ -static struct string * -tty3270_alloc_string (struct tty3270 *tp,size_t size) +static struct string *tty3270_alloc_string (struct tty3270 *tp,size_t size) {struct string *s, *n;
@@ -304,8 +297,7 @@ tty3270_alloc_string(struct tty3270 *tp, size_t size)/* * Add an empty line to the list. */ -static void -tty3270_blank_line (struct tty3270 *tp) +static void tty3270_blank_line (struct tty3270 *tp) {static const unsigned char blueprint[] = {TO_SBA ,0 ,0 ,TO_SA ,TAT_EXTHI ,TAX_RESET ,
@@ -324,8 +316,7 @@ tty3270_blank_line(struct tty3270 *tp)/* * Create a blank screen and remove all lines from the history. */ -static void -tty3270_blank_screen (struct tty3270 *tp) +static void tty3270_blank_screen (struct tty3270 *tp) {struct string *s, *n;int i;
@@ -345,8 +336,7 @@ tty3270_blank_screen(struct tty3270 *tp)/* * Write request completion callback. */ -static void -tty3270_write_callback (struct raw3270_request *rq,void *data) +static void tty3270_write_callback (struct raw3270_request *rq,void *data) { struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
@@ -362,8 +352,7 @@ tty3270_write_callback(struct raw3270_request *rq, void *data)/* * Update 3270 display. */ -static void -tty3270_update (struct timer_list *t) +static void tty3270_update (struct timer_list *t) {struct tty3270 *tp =from_timer (tp, t, timer);static char invalid_sba[2 ] = {0xff ,0xff };
@@ -456,8 +445,7 @@ tty3270_update(struct timer_list *t)/* * Command recalling. */ -static void -tty3270_rcl_add (struct tty3270 *tp,char *input,int len) +static void tty3270_rcl_add (struct tty3270 *tp,char *input,int len) {struct string *s;
@@ -476,8 +464,7 @@ tty3270_rcl_add(struct tty3270 *tp, char *input, int len) tp->rcl_nr++; } -static void -tty3270_rcl_backward (struct kbd_data *kbd) +static void tty3270_rcl_backward (struct kbd_data *kbd) { struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);struct string *s;
@@ -503,8 +490,7 @@ tty3270_rcl_backward(struct kbd_data *kbd)/* * Deactivate tty view. */ -static void -tty3270_exit_tty (struct kbd_data *kbd) +static void tty3270_exit_tty (struct kbd_data *kbd) { struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
@@ -514,8 +500,7 @@ tty3270_exit_tty(struct kbd_data *kbd)/* * Scroll forward in history. */ -static void -tty3270_scroll_forward (struct kbd_data *kbd) +static void tty3270_scroll_forward (struct kbd_data *kbd) { struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);int nr_up;
@@ -536,8 +521,7 @@ tty3270_scroll_forward(struct kbd_data *kbd)/* * Scroll backward in history. */ -static void -tty3270_scroll_backward (struct kbd_data *kbd) +static void tty3270_scroll_backward (struct kbd_data *kbd) { struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);int nr_up;
@@ -558,8 +542,7 @@ tty3270_scroll_backward(struct kbd_data *kbd)/* * Pass input line to tty. */ -static void -tty3270_read_tasklet (unsigned long data) +static void tty3270_read_tasklet (unsigned long data) {struct raw3270_request *rrq = (struct raw3270_request *)data;static char kreset_data =TW_KR ;
@@ -615,8 +598,7 @@ tty3270_read_tasklet(unsigned long data)/* * Read request completion callback. */ -static void -tty3270_read_callback (struct raw3270_request *rq,void *data) +static void tty3270_read_callback (struct raw3270_request *rq,void *data) { struct tty3270 *tp = container_of(rq->view, struct tty3270, view);raw3270_get_view (rq->view);
@@ -627,8 +609,7 @@ tty3270_read_callback(struct raw3270_request *rq, void *data)/* * Issue a read request. Call with device lock. */ -static void -tty3270_issue_read (struct tty3270 *tp,int lock) +static void tty3270_issue_read (struct tty3270 *tp,int lock) {struct raw3270_request *rrq;int rc;
@@ -655,8 +636,7 @@ tty3270_issue_read(struct tty3270 *tp, int lock)/* * Hang up the tty */ -static void -tty3270_hangup_tasklet (unsigned long data) +static void tty3270_hangup_tasklet (unsigned long data) {struct tty3270 *tp = (struct tty3270 *)data;tty_port_tty_hangup (&tp->port, true);
@@ -666,8 +646,7 @@ tty3270_hangup_tasklet(unsigned long data)/* * Switch to the tty view. */ -static int -tty3270_activate (struct raw3270_view *view) +static int tty3270_activate (struct raw3270_view *view) { struct tty3270 *tp = container_of(view, struct tty3270, view);
@@ -676,16 +655,14 @@ tty3270_activate(struct raw3270_view *view)return 0 ; } -static void -tty3270_deactivate (struct raw3270_view *view) +static void tty3270_deactivate (struct raw3270_view *view) { struct tty3270 *tp = container_of(view, struct tty3270, view);del_timer (&tp->timer); } -static void -tty3270_irq (struct tty3270 *tp,struct raw3270_request *rq,struct irb *irb) +static void tty3270_irq (struct tty3270 *tp,struct raw3270_request *rq,struct irb *irb) {/* Handle ATTN. Schedule tasklet to read aid. */ if (irb->scsw.cmd.dstat &DEV_STAT_ATTENTION ) {
@@ -714,8 +691,7 @@ tty3270_irq(struct tty3270 *tp, struct raw3270_request *rq, struct irb *irb)/* * Allocate tty3270 structure. */ -static struct tty3270 * -tty3270_alloc_view (void ) +static struct tty3270 *tty3270_alloc_view (void ) {struct tty3270 *tp;int pages;
@@ -785,8 +761,7 @@ tty3270_alloc_view(void)/* * Free tty3270 structure. */ -static void -tty3270_free_view (struct tty3270 *tp) +static void tty3270_free_view (struct tty3270 *tp) {int pages;
@@ -804,8 +779,7 @@ tty3270_free_view(struct tty3270 *tp)/* * Allocate tty3270 screen. */ -static struct tty3270_line * -tty3270_alloc_screen (unsigned int rows,unsigned int cols) +static struct tty3270_line *tty3270_alloc_screen (unsigned int rows,unsigned int cols) {struct tty3270_line *screen;unsigned long size;
@@ -833,8 +807,7 @@ tty3270_alloc_screen(unsigned int rows, unsigned int cols)/* * Free tty3270 screen. */ -static void -tty3270_free_screen (struct tty3270_line *screen,unsigned int rows) +static void tty3270_free_screen (struct tty3270_line *screen,unsigned int rows) {int lines;
@@ -886,8 +859,7 @@ static void tty3270_resize_work(struct work_struct *work)tty_kref_put (tty); } -static void -tty3270_resize (struct raw3270_view *view,int model,int rows,int cols) +static void tty3270_resize (struct raw3270_view *view,int model,int rows,int cols) { struct tty3270 *tp = container_of(view, struct tty3270, view);
@@ -902,8 +874,7 @@ tty3270_resize(struct raw3270_view *view, int model, int rows, int cols)/* * Unlink tty3270 data structure from tty. */ -static void -tty3270_release (struct raw3270_view *view) +static void tty3270_release (struct raw3270_view *view) { struct tty3270 *tp = container_of(view, struct tty3270, view);struct tty_struct *tty =tty_port_tty_get (&tp->port);
@@ -920,8 +891,7 @@ tty3270_release(struct raw3270_view *view)/* * Free tty3270 data structure */ -static void -tty3270_free (struct raw3270_view *view) +static void tty3270_free (struct raw3270_view *view) { struct tty3270 *tp = container_of(view, struct tty3270, view);
@@ -933,8 +903,7 @@ tty3270_free(struct raw3270_view *view)/* * Delayed freeing of tty3270 views. */ -static void -tty3270_del_views (void ) +static void tty3270_del_views (void ) {int i;
@@ -1042,8 +1011,7 @@ tty3270_install(struct tty_driver *driver, struct tty_struct *tty)/* * This routine is called whenever a 3270 tty is opened. */ -static int -tty3270_open (struct tty_struct *tty,struct file *filp) +static int tty3270_open (struct tty_struct *tty,struct file *filp) {struct tty3270 *tp = tty->driver_data;struct tty_port *port = &tp->port;
@@ -1057,8 +1025,7 @@ tty3270_open(struct tty_struct *tty, struct file *filp)* This routine is called when the 3270 tty is closed. We wait * for the remaining request to be completed. Then we clean up. */ -static void -tty3270_close (struct tty_struct *tty,struct file * filp) +static void tty3270_close (struct tty_struct *tty,struct file *filp) {struct tty3270 *tp = tty->driver_data;
@@ -1081,8 +1048,7 @@ static void tty3270_cleanup(struct tty_struct *tty)/* * We always have room. */ -static unsigned int -tty3270_write_room (struct tty_struct *tty) +static unsigned int tty3270_write_room (struct tty_struct *tty) {return INT_MAX ; }
@@ -1116,8 +1082,7 @@ static void tty3270_put_character(struct tty3270 *tp, char ch)/* * Convert a tty3270_line to a 3270 data fragment usable for output. */ -static void -tty3270_convert_line (struct tty3270 *tp,int line_nr) +static void tty3270_convert_line (struct tty3270 *tp,int line_nr) {struct tty3270_line *line;struct tty3270_cell *cell;
@@ -1223,8 +1188,7 @@ tty3270_convert_line(struct tty3270 *tp, int line_nr)/* * Do carriage return. */ -static void -tty3270_cr (struct tty3270 *tp) +static void tty3270_cr (struct tty3270 *tp) { tp->cx =0 ; }
@@ -1232,8 +1196,7 @@ tty3270_cr(struct tty3270 *tp)/* * Do line feed. */ -static void -tty3270_lf (struct tty3270 *tp) +static void tty3270_lf (struct tty3270 *tp) {struct tty3270_line temp;int i;
@@ -1253,8 +1216,7 @@ tty3270_lf(struct tty3270 *tp)tty3270_rebuild_update (tp); } -static void -tty3270_ri (struct tty3270 *tp) +static void tty3270_ri (struct tty3270 *tp) {if (tp->cy >0 ) {tty3270_convert_line (tp, tp->cy);
@@ -1265,8 +1227,7 @@ tty3270_ri(struct tty3270 *tp)/* * Insert characters at current position. */ -static void -tty3270_insert_characters (struct tty3270 *tp,int n) +static void tty3270_insert_characters (struct tty3270 *tp,int n) {struct tty3270_line *line;int k;
@@ -1296,8 +1257,7 @@ tty3270_insert_characters(struct tty3270 *tp, int n)/* * Delete characters at current position. */ -static void -tty3270_delete_characters (struct tty3270 *tp,int n) +static void tty3270_delete_characters (struct tty3270 *tp,int n) {struct tty3270_line *line;int i;
@@ -1317,8 +1277,7 @@ tty3270_delete_characters(struct tty3270 *tp, int n)/* * Erase characters at current position. */ -static void -tty3270_erase_characters (struct tty3270 *tp,int n) +static void tty3270_erase_characters (struct tty3270 *tp,int n) {struct tty3270_line *line;struct tty3270_cell *cell;
@@ -1340,8 +1299,7 @@ tty3270_erase_characters(struct tty3270 *tp, int n)* Esc [ 1 K Erase from beginning of line to current position inclusive * Esc [ 2 K Erase entire line (without moving cursor) */ -static void -tty3270_erase_line (struct tty3270 *tp,int mode) +static void tty3270_erase_line (struct tty3270 *tp,int mode) {struct tty3270_line *line;struct tty3270_cell *cell;
@@ -1370,8 +1328,7 @@ tty3270_erase_line(struct tty3270 *tp, int mode)* Esc [ 1 J Erase from top of screen to current position inclusive * Esc [ 2 J Erase entire screen (without moving the cursor) */ -static void -tty3270_erase_display (struct tty3270 *tp,int mode) +static void tty3270_erase_display (struct tty3270 *tp,int mode) {int i;
@@ -1400,8 +1357,7 @@ tty3270_erase_display(struct tty3270 *tp, int mode)* Set attributes found in an escape sequence. * Esc [ <attr> ; <attr> ; ... m */ -static void -tty3270_set_attributes (struct tty3270 *tp) +static void tty3270_set_attributes (struct tty3270 *tp) {static unsigned char f_colors[] = {TAC_DEFAULT ,TAC_RED ,TAC_GREEN ,TAC_YELLOW ,TAC_BLUE ,
@@ -1454,14 +1410,12 @@ tty3270_set_attributes(struct tty3270 *tp) } } -static inline int -tty3270_getpar (struct tty3270 *tp,int ix) +static inline int tty3270_getpar (struct tty3270 *tp,int ix) {return (tp->esc_par[ix] >0 ) ? tp->esc_par[ix] :1 ; } -static void -tty3270_goto_xy (struct tty3270 *tp,int cx,int cy) +static void tty3270_goto_xy (struct tty3270 *tp,int cx,int cy) {int max_cx =max (0 , cx);int max_cy =max (0 , cy);
@@ -1494,8 +1448,7 @@ tty3270_goto_xy(struct tty3270 *tp, int cx, int cy)* Pn is a numeric parameter, a string of zero or more decimal digits. * Ps is a selective parameter. */ -static void -tty3270_escape_sequence (struct tty3270 *tp,char ch) +static void tty3270_escape_sequence (struct tty3270 *tp,char ch) {enum { ESnormal, ESesc, ESsquare, ESgetpars };
@@ -1643,9 +1596,8 @@ tty3270_escape_sequence(struct tty3270 *tp, char ch)/* * String write routine for 3270 ttys */ -static void -tty3270_do_write (struct tty3270 *tp,struct tty_struct *tty, -const unsigned char *buf,int count) +static void tty3270_do_write (struct tty3270 *tp,struct tty_struct *tty, +const unsigned char *buf,int count) {int i_msg, i;
@@ -1717,9 +1669,8 @@ tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,/* * String write routine for 3270 ttys */ -static int -tty3270_write (struct tty_struct * tty, -const unsigned char *buf,int count) +static int tty3270_write (struct tty_struct *tty, +const unsigned char *buf,int count) {struct tty3270 *tp;
@@ -1752,8 +1703,7 @@ static int tty3270_put_char(struct tty_struct *tty, unsigned char ch)* Flush all characters from the ttys characeter buffer put there * by tty3270_put_char. */ -static void -tty3270_flush_chars (struct tty_struct *tty) +static void tty3270_flush_chars (struct tty_struct *tty) {struct tty3270 *tp;
@@ -1769,8 +1719,7 @@ tty3270_flush_chars(struct tty_struct *tty)/* * Check for visible/invisible input switches */ -static void -tty3270_set_termios (struct tty_struct *tty,const struct ktermios *old) +static void tty3270_set_termios (struct tty_struct *tty,const struct ktermios *old) {struct tty3270 *tp;int new;
@@ -1793,8 +1742,7 @@ tty3270_set_termios(struct tty_struct *tty, const struct ktermios *old)/* * Disable reading from a 3270 tty */ -static void -tty3270_throttle (struct tty_struct * tty) +static void tty3270_throttle (struct tty_struct *tty) {struct tty3270 *tp;
@@ -1807,8 +1755,7 @@ tty3270_throttle(struct tty_struct * tty)/* * Enable reading from a 3270 tty */ -static void -tty3270_unthrottle (struct tty_struct * tty) +static void tty3270_unthrottle (struct tty_struct *tty) {struct tty3270 *tp;
@@ -1823,8 +1770,7 @@ tty3270_unthrottle(struct tty_struct * tty)/* * Hang up the tty device. */ -static void -tty3270_hangup (struct tty_struct *tty) +static void tty3270_hangup (struct tty_struct *tty) {struct tty3270 *tp;
@@ -1844,8 +1790,7 @@ tty3270_hangup(struct tty_struct *tty)tty3270_set_timer (tp,1 ); } -static void -tty3270_wait_until_sent (struct tty_struct *tty,int timeout) +static void tty3270_wait_until_sent (struct tty_struct *tty,int timeout) { }
@@ -1953,8 +1898,7 @@ static int __init tty3270_init(void)return 0 ; } -static void __exit -tty3270_exit (void ) +static void __exit tty3270_exit(void) {struct tty_driver *driver;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 649/1191 tty: hvsi: remove an extra variable from hvsi_write()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby <[email protected]>
[ Upstream commit d3352ab0a9701a6d4c88b814815d7320c339f4a8 ]
'source' is the same as 'buf'. Rename the parameter ('buf') to 'source' and drop the local variable.
Likely, the two were introduced to have a different type. But 'char' and 'unsigned char' are the same in the kernel for a long time.
Stable-dep-of: b6b5d64cb161 ("ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove")
--- drivers/tty/hvc/hvsi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/hvc/hvsi.c +1 -2
@@ -905,10 +905,9 @@ static unsigned int hvsi_chars_in_buffer(struct tty_struct *tty) }static int hvsi_write (struct tty_struct *tty, -const unsigned char *buf,int count) +const unsigned char *source,int count) {struct hvsi_struct *hp = tty->driver_data; -const char *source = buf;unsigned long flags;int total =0 ;int origcount = count;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 650/1191 tty: propagate u8 data to tty_operations::write()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 69851e4ab8feeb369119a44ddca430c0ee15f0d8 ]
Data are now typed as u8. Propagate this change to tty_operations::write().
Stable-dep-of: b6b5d64cb161 ("ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove")
--- arch/alpha/kernel/srmcons.c | 3 +-- arch/m68k/emu/nfcon.c | 3 +-- arch/um/drivers/line.c | 2 +- arch/um/drivers/line.h | 3 +-- arch/xtensa/platforms/iss/console.c | 3 +-- drivers/char/ttyprintk.c | 5 ++--- drivers/ipack/devices/ipoctal.c | 6 ++---- drivers/isdn/capi/capi.c | 3 +-- drivers/misc/bcm-vk/bcm_vk_tty.c | 4 +--- drivers/mmc/core/sdio_uart.c | 3 +-- drivers/net/usb/hso.c | 3 +-- drivers/s390/char/con3215.c | 3 +-- drivers/s390/char/sclp_tty.c | 2 +- drivers/s390/char/sclp_vt220.c | 2 +- drivers/s390/char/tty3270.c | 3 +-- drivers/staging/gdm724x/gdm_tty.c | 3 +-- drivers/staging/greybus/uart.c | 3 +-- drivers/tty/amiserial.c | 2 +- drivers/tty/ehv_bytechan.c | 3 +-- drivers/tty/goldfish.c | 6 ++---- drivers/tty/hvc/hvc_console.c | 2 +- drivers/tty/hvc/hvcs.c | 3 +-- drivers/tty/hvc/hvsi.c | 3 +-- drivers/tty/ipwireless/hardware.c | 2 +- drivers/tty/ipwireless/tty.c | 3 +-- drivers/tty/mips_ejtag_fdc.c | 4 ++-- drivers/tty/moxa.c | 8 +++----- drivers/tty/mxser.c | 2 +- drivers/tty/n_gsm.c | 3 +-- drivers/tty/nozomi.c | 5 ++--- drivers/tty/pty.c | 2 +- drivers/tty/serial/kgdb_nmi.c | 2 +- drivers/tty/serial/serial_core.c | 3 +-- drivers/tty/synclink_gt.c | 7 +++---- drivers/tty/ttynull.c | 3 +-- drivers/tty/vcc.c | 3 +-- drivers/tty/vt/vt.c | 4 ++-- drivers/usb/class/cdc-acm.c | 3 +-- drivers/usb/gadget/function/u_serial.c | 2 +- drivers/usb/host/xhci-dbgtty.c | 4 +--- drivers/usb/serial/usb-serial.c | 3 +-- include/linux/tty_driver.h | 3 +-- net/bluetooth/rfcomm/tty.c | 2 +- 43 files changed, 53 insertions(+), 88 deletions(-)
arch/alpha/kernel/srmcons.c +1 -2
@@ -130,8 +130,7 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count) }static int -srmcons_write (struct tty_struct *tty, -const unsigned char *buf,int count) +srmcons_write (struct tty_struct *tty,const u8 *buf,int count) {unsigned long flags;
arch/m68k/emu/nfcon.c +1 -2
@@ -70,8 +70,7 @@ static void nfcon_tty_close(struct tty_struct *tty, struct file *filp) { } -static int nfcon_tty_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int nfcon_tty_write (struct tty_struct *tty,const u8 *buf,int count) {nfputs (buf, count);return count;
arch/um/drivers/line.c +1 -1
@@ -184,7 +184,7 @@ void line_flush_chars(struct tty_struct *tty)line_flush_buffer (tty); } -int line_write (struct tty_struct *tty,const unsigned char *buf,int len) +int line_write (struct tty_struct *tty,const u8 *buf,int len) {struct line *line = tty->driver_data;unsigned long flags;
arch/um/drivers/line.h +1 -2
@@ -64,8 +64,7 @@ extern void line_cleanup(struct tty_struct *tty);extern void line_hangup (struct tty_struct *tty);extern int line_setup (char **conf,unsigned nlines,char **def,char *init,char *name); -extern int line_write (struct tty_struct *tty,const unsigned char *buf, -int len); +extern int line_write (struct tty_struct *tty,const u8 *buf,int len);extern unsigned int line_chars_in_buffer (struct tty_struct *tty);extern void line_flush_buffer (struct tty_struct *tty);extern void line_flush_chars (struct tty_struct *tty);
arch/xtensa/platforms/iss/console.c +1 -2
@@ -52,8 +52,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp) } -static int rs_write (struct tty_struct * tty, -const unsigned char *buf,int count) +static int rs_write (struct tty_struct * tty,const u8 *buf,int count) {/* see drivers/char/serialX.c to reference original version */
drivers/char/ttyprintk.c +2 -3
@@ -51,7 +51,7 @@ static void tpk_flush(void) } } -static int tpk_printk (const unsigned char *buf,int count) +static int tpk_printk (const u8 *buf,int count) {int i;
@@ -103,8 +103,7 @@ static void tpk_close(struct tty_struct *tty, struct file *filp)/* * TTY operations write function. */ -static int tpk_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int tpk_write (struct tty_struct *tty,const u8 *buf,int count) {struct ttyprintk_port *tpkp = tty->driver_data;unsigned long flags;
drivers/ipack/devices/ipoctal.c +2 -4
@@ -437,8 +437,7 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr, }static inline int ipoctal_copy_write_buffer (struct ipoctal_channel *channel, -const unsigned char *buf, -int count) +const u8 *buf,int count) {unsigned long flags;int i;
@@ -459,8 +458,7 @@ static inline int ipoctal_copy_write_buffer(struct ipoctal_channel *channel,return i; } -static int ipoctal_write_tty (struct tty_struct *tty, -const unsigned char *buf,int count) +static int ipoctal_write_tty (struct tty_struct *tty,const u8 *buf,int count) {struct ipoctal_channel *channel = tty->driver_data;unsigned int char_copied;
drivers/isdn/capi/capi.c +1 -2
@@ -1071,8 +1071,7 @@ static void capinc_tty_close(struct tty_struct *tty, struct file *filp)tty_port_close (&mp->port, tty, filp); } -static int capinc_tty_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int capinc_tty_write (struct tty_struct *tty,const u8 *buf,int count) {struct capiminor *mp = tty->driver_data;struct sk_buff *skb;
drivers/misc/bcm-vk/bcm_vk_tty.c +1 -3
@@ -186,9 +186,7 @@ static void bcm_vk_tty_doorbell(struct bcm_vk *vk, u32 db_val) VK_BAR0_REGSEG_DB_BASE + VK_BAR0_REGSEG_TTY_DB_OFFSET); } -static int bcm_vk_tty_write (struct tty_struct *tty, -const unsigned char *buffer, -int count) +static int bcm_vk_tty_write (struct tty_struct *tty,const u8 *buffer,int count) {int index;struct bcm_vk *vk;
drivers/mmc/core/sdio_uart.c +1 -2
@@ -761,8 +761,7 @@ static void sdio_uart_hangup(struct tty_struct *tty)tty_port_hangup (&port->port); } -static int sdio_uart_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int sdio_uart_write (struct tty_struct *tty,const u8 *buf,int count) {struct sdio_uart_port *port = tty->driver_data;int ret;
drivers/net/usb/hso.c +1 -2
@@ -1322,8 +1322,7 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp) }/* close the requested serial port */ -static int hso_serial_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int hso_serial_write (struct tty_struct *tty,const u8 *buf,int count) {struct hso_serial *serial = tty->driver_data;int space, tx_bytes;
drivers/s390/char/con3215.c +1 -2
@@ -939,8 +939,7 @@ static unsigned int tty3215_write_room(struct tty_struct *tty)/* * String write routine for 3215 ttys */ -static int tty3215_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int tty3215_write (struct tty_struct *tty,const u8 *buf,int count) {struct raw3215_info *raw = tty->driver_data;int i, written;
drivers/s390/char/sclp_tty.c +1 -1
@@ -230,7 +230,7 @@ static int sclp_tty_write_string(const unsigned char *str, int count, int may_fa* routine will return the number of characters actually accepted for writing. */ static int -sclp_tty_write (struct tty_struct *tty,const unsigned char *buf,int count) +sclp_tty_write (struct tty_struct *tty,const u8 *buf,int count) {if (sclp_tty_chars_count >0 ) {sclp_tty_write_string (sclp_tty_chars, sclp_tty_chars_count,0 );
drivers/s390/char/sclp_vt220.c +1 -1
@@ -463,7 +463,7 @@ __sclp_vt220_write(const unsigned char *buf, int count, int do_schedule,* number of characters actually accepted for writing. */ static int -sclp_vt220_write (struct tty_struct *tty,const unsigned char *buf,int count) +sclp_vt220_write (struct tty_struct *tty,const u8 *buf,int count) {return __sclp_vt220_write (buf, count,1 ,0 ,1 ); }
drivers/s390/char/tty3270.c +1 -2
@@ -1669,8 +1669,7 @@ static void tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,/* * String write routine for 3270 ttys */ -static int tty3270_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int tty3270_write (struct tty_struct *tty,const u8 *buf,int count) {struct tty3270 *tp;
drivers/staging/gdm724x/gdm_tty.c +1 -2
@@ -146,8 +146,7 @@ static void gdm_tty_send_complete(void *arg)tty_port_tty_wakeup (&gdm->port); } -static int gdm_tty_write (struct tty_struct *tty,const unsigned char *buf, -int len) +static int gdm_tty_write (struct tty_struct *tty,const u8 *buf,int len) {struct gdm *gdm = tty->driver_data;int remain = len;
drivers/staging/greybus/uart.c +1 -2
@@ -427,8 +427,7 @@ static void gb_tty_hangup(struct tty_struct *tty)tty_port_hangup (&gb_tty->port); } -static int gb_tty_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int gb_tty_write (struct tty_struct *tty,const u8 *buf,int count) {struct gb_tty *gb_tty = tty->driver_data;
drivers/tty/amiserial.c +1 -1
@@ -741,7 +741,7 @@ static void rs_flush_chars(struct tty_struct *tty)local_irq_restore (flags); } -static int rs_write (struct tty_struct * tty,const unsigned char *buf,int count) +static int rs_write (struct tty_struct * tty,const u8 *buf,int count) {int c, ret =0 ;struct serial_state *info = tty->driver_data;
drivers/tty/ehv_bytechan.c +1 -2
@@ -466,8 +466,7 @@ static irqreturn_t ehv_bc_tty_tx_isr(int irq, void *data)* ehv_bc_tty_write_room() will never lie, so the tty layer will never send us * too much data. */ -static int ehv_bc_tty_write (struct tty_struct *ttys,const unsigned char *s, -int count) +static int ehv_bc_tty_write (struct tty_struct *ttys,const u8 *s,int count) {struct ehv_bc_data *bc = ttys->driver_data;unsigned long flags;
drivers/tty/goldfish.c +2 -4
@@ -125,8 +125,7 @@ static void goldfish_tty_rw(struct goldfish_tty *qtty, } } -static void goldfish_tty_do_write (int line,const char *buf, -unsigned int count) +static void goldfish_tty_do_write (int line,const u8 *buf,unsigned int count) {struct goldfish_tty *qtty = &goldfish_ttys[line];unsigned long address = (unsigned long )(void *)buf;
@@ -186,8 +185,7 @@ static void goldfish_tty_hangup(struct tty_struct *tty)tty_port_hangup (tty->port); } -static int goldfish_tty_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int goldfish_tty_write (struct tty_struct *tty,const u8 *buf,int count) {goldfish_tty_do_write (tty->index, buf, count);return count;
drivers/tty/hvc/hvc_console.c +1 -1
@@ -496,7 +496,7 @@ static int hvc_push(struct hvc_struct *hp)return n; } -static int hvc_write (struct tty_struct *tty,const unsigned char *buf,int count) +static int hvc_write (struct tty_struct *tty,const u8 *buf,int count) {struct hvc_struct *hp = tty->driver_data;unsigned long flags;
drivers/tty/hvc/hvcs.c +1 -2
@@ -1271,8 +1271,7 @@ static void hvcs_hangup(struct tty_struct * tty)* tty_hangup will allow hvcs_write time to complete execution before it * terminates our device. */ -static int hvcs_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int hvcs_write (struct tty_struct *tty,const u8 *buf,int count) {struct hvcs_struct *hvcsd = tty->driver_data;unsigned int unit_address;
drivers/tty/hvc/hvsi.c +1 -2
@@ -904,8 +904,7 @@ static unsigned int hvsi_chars_in_buffer(struct tty_struct *tty)return hp->n_outbuf; } -static int hvsi_write (struct tty_struct *tty, -const unsigned char *source,int count) +static int hvsi_write (struct tty_struct *tty,const u8 *source,int count) {struct hvsi_struct *hp = tty->driver_data;unsigned long flags;
drivers/tty/ipwireless/hardware.c +1 -1
@@ -1292,7 +1292,7 @@ static void *alloc_ctrl_packet(int header_size, }int ipwireless_send_packet (struct ipw_hardware *hw,unsigned int channel_idx, -const unsigned char *data,unsigned int length, +const u8 *data,unsigned int length,void (*callback) (void *cb,unsigned int length),void *callback_data) {
drivers/tty/ipwireless/tty.c +1 -2
@@ -186,8 +186,7 @@ static void ipw_write_packet_sent_callback(void *callback_data, tty->tx_bytes_queued -= packet_length; } -static int ipw_write (struct tty_struct *linux_tty, -const unsigned char *buf,int count) +static int ipw_write (struct tty_struct *linux_tty,const u8 *buf,int count) {struct ipw_tty *tty = linux_tty->driver_data;int room, ret;
drivers/tty/mips_ejtag_fdc.c +2 -2
@@ -796,8 +796,8 @@ static void mips_ejtag_fdc_tty_hangup(struct tty_struct *tty)tty_port_hangup (tty->port); } -static int mips_ejtag_fdc_tty_write (struct tty_struct *tty, -const unsigned char *buf,int total) +static int mips_ejtag_fdc_tty_write (struct tty_struct *tty,const u8 *buf, +int total) {int count, block;struct mips_ejtag_fdc_tty_port *dport = tty->driver_data;
drivers/tty/moxa.c +3 -5
@@ -487,7 +487,7 @@ module_param(ttymajor, int, 0);*/ static int moxa_open (struct tty_struct *,struct file *);static void moxa_close (struct tty_struct *,struct file *); -static int moxa_write (struct tty_struct *,const unsigned char *,int ); +static int moxa_write (struct tty_struct *,const u8 *,int );static unsigned int moxa_write_room (struct tty_struct *);static void moxa_flush_buffer (struct tty_struct *);static unsigned int moxa_chars_in_buffer (struct tty_struct *);
@@ -1499,8 +1499,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)tty_port_close (&ch->port, tty, filp); } -static int moxa_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int moxa_write (struct tty_struct *tty,const u8 *buf,int count) {struct moxa_port *ch = tty->driver_data;unsigned long flags;
@@ -2162,8 +2161,7 @@ static int MoxaPortLineStatus(struct moxa_port *port)return val; } -static int MoxaPortWriteData (struct tty_struct *tty, -const unsigned char *buffer,int len) +static int MoxaPortWriteData (struct tty_struct *tty,const u8 *buffer,int len) {struct moxa_port *port = tty->driver_data;void __iomem *baseAddr, *ofsAddr, *ofs;
drivers/tty/mxser.c +1 -1
@@ -900,7 +900,7 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)tty_port_close (tty->port, tty, filp); } -static int mxser_write (struct tty_struct *tty,const unsigned char *buf,int count) +static int mxser_write (struct tty_struct *tty,const u8 *buf,int count) {struct mxser_port *info = tty->driver_data;unsigned long flags;
drivers/tty/n_gsm.c +1 -2
@@ -3628,8 +3628,7 @@ static void gsmtty_hangup(struct tty_struct *tty)gsm_dlci_begin_close (dlci); } -static int gsmtty_write (struct tty_struct *tty,const unsigned char *buf, -int len) +static int gsmtty_write (struct tty_struct *tty,const u8 *buf,int len) {int sent;struct gsm_dlci *dlci = tty->driver_data;
drivers/tty/nozomi.c +2 -3
@@ -1599,8 +1599,7 @@ static void ntty_hangup(struct tty_struct *tty)* called when the userspace process writes to the tty (/dev/noz*). * Data is inserted into a fifo, which is then read and transferred to the modem. */ -static int ntty_write (struct tty_struct *tty,const unsigned char *buffer, -int count) +static int ntty_write (struct tty_struct *tty,const u8 *buffer,int count) {int rval = -EINVAL ;struct nozomi *dc =get_dc_by_tty (tty);
@@ -1610,7 +1609,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,if (!dc || !port)return -ENODEV ; - rval =kfifo_in (&port->fifo_ul, (unsigned char *)buffer, count); + rval =kfifo_in (&port->fifo_ul, buffer, count);spin_lock_irqsave (&dc->spin_mutex, flags);/* CTS is only valid on the modem channel */
drivers/tty/pty.c +1 -1
@@ -108,7 +108,7 @@ static void pty_unthrottle(struct tty_struct *tty)* the other side of the pty/tty pair. */ -static int pty_write (struct tty_struct *tty,const unsigned char *buf,int c) +static int pty_write (struct tty_struct *tty,const u8 *buf,int c) {struct tty_struct *to = tty->link;
drivers/tty/serial/kgdb_nmi.c +1 -1
@@ -304,7 +304,7 @@ static unsigned int kgdb_nmi_tty_write_room(struct tty_struct *tty)return 2048 ; } -static int kgdb_nmi_tty_write (struct tty_struct *tty,const unchar *buf,int c) +static int kgdb_nmi_tty_write (struct tty_struct *tty,const u8 *buf,int c) {int i;
drivers/tty/serial/serial_core.c +1 -2
@@ -560,8 +560,7 @@ static void uart_flush_chars(struct tty_struct *tty)uart_start (tty); } -static int uart_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int uart_write (struct tty_struct *tty,const u8 *buf,int count) {struct uart_state *state = tty->driver_data;struct uart_port *port;
drivers/tty/synclink_gt.c +3 -4
@@ -433,7 +433,7 @@ static void tx_set_idle(struct slgt_info *info);static unsigned int tbuf_bytes (struct slgt_info *info);static void reset_tbufs (struct slgt_info *info);static void tdma_reset (struct slgt_info *info); -static bool tx_load (struct slgt_info *info,const char *buf,unsigned int count); +static bool tx_load (struct slgt_info *info,const u8 *buf,unsigned int count);static void get_gtsignals (struct slgt_info *info);static void set_gtsignals (struct slgt_info *info);
@@ -747,8 +747,7 @@ static void update_tx_timer(struct slgt_info *info) } } -static int write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int write (struct tty_struct *tty,const u8 *buf,int count) {int ret =0 ;struct slgt_info *info = tty->driver_data;
@@ -4783,7 +4782,7 @@ static unsigned int tbuf_bytes(struct slgt_info *info)* load data into transmit DMA buffer ring and start transmitter if needed * return true if data accepted, otherwise false (buffers full) */ -static bool tx_load (struct slgt_info *info,const char *buf,unsigned int size) +static bool tx_load (struct slgt_info *info,const u8 *buf,unsigned int size) {unsigned short count;unsigned int i;
drivers/tty/ttynull.c +1 -2
@@ -29,8 +29,7 @@ static void ttynull_hangup(struct tty_struct *tty)tty_port_hangup (&ttynull_port); } -static int ttynull_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int ttynull_write (struct tty_struct *tty,const u8 *buf,int count) {return count; }
drivers/tty/vcc.c +1 -2
@@ -814,8 +814,7 @@ static void vcc_hangup(struct tty_struct *tty)tty_port_hangup (tty->port); } -static int vcc_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int vcc_write (struct tty_struct *tty,const u8 *buf,int count) {struct vcc_port *port;struct vio_vcc *pkt;
drivers/tty/vt/vt.c +2 -2
@@ -2891,7 +2891,7 @@ static int vc_con_write_normal(struct vc_data *vc, int tc, int c, }/* acquires console_lock */ -static int do_con_write (struct tty_struct *tty,const unsigned char *buf,int count) +static int do_con_write (struct tty_struct *tty,const u8 *buf,int count) {struct vc_draw_region draw = { .x =-1 ,
@@ -3288,7 +3288,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)* /dev/ttyN handling */ -static int con_write (struct tty_struct *tty,const unsigned char *buf,int count) +static int con_write (struct tty_struct *tty,const u8 *buf,int count) {int retval;
drivers/usb/class/cdc-acm.c +1 -2
@@ -810,8 +810,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)tty_port_close (&acm->port, tty, filp); } -static int acm_tty_write (struct tty_struct *tty, -const unsigned char *buf,int count) +static int acm_tty_write (struct tty_struct *tty,const u8 *buf,int count) {struct acm *acm = tty->driver_data;int stat;
drivers/usb/gadget/function/u_serial.c +1 -1
@@ -732,7 +732,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)spin_unlock_irq (&port->port_lock); } -static int gs_write (struct tty_struct *tty,const unsigned char *buf,int count) +static int gs_write (struct tty_struct *tty,const u8 *buf,int count) {struct gs_port *port = tty->driver_data;unsigned long flags;
drivers/usb/host/xhci-dbgtty.c +1 -3
@@ -233,9 +233,7 @@ static void dbc_tty_close(struct tty_struct *tty, struct file *file)tty_port_close (&port->port, tty, file); } -static int dbc_tty_write (struct tty_struct *tty, -const unsigned char *buf, -int count) +static int dbc_tty_write (struct tty_struct *tty,const u8 *buf,int count) {struct dbc_port *port = tty->driver_data;unsigned long flags;
drivers/usb/serial/usb-serial.c +1 -2
@@ -361,8 +361,7 @@ static void serial_cleanup(struct tty_struct *tty)module_put (owner); } -static int serial_write (struct tty_struct *tty,const unsigned char *buf, -int count) +static int serial_write (struct tty_struct *tty,const u8 *buf,int count) {struct usb_serial_port *port = tty->driver_data;int retval = -ENODEV ;
include/linux/tty_driver.h +1 -2
@@ -363,8 +363,7 @@ struct tty_operations {void (*close)(struct tty_struct * tty,struct file * filp);void (*shutdown)(struct tty_struct *tty);void (*cleanup)(struct tty_struct *tty); -int (*write)(struct tty_struct * tty, -const unsigned char *buf,int count); +int (*write)(struct tty_struct *tty,const u8 *buf,int count);int (*put_char)(struct tty_struct *tty,unsigned char ch);void (*flush_chars)(struct tty_struct *tty);unsigned int (*write_room)(struct tty_struct *tty);
net/bluetooth/rfcomm/tty.c +1 -1
@@ -774,7 +774,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)tty_port_close (&dev->port, tty, filp); } -static int rfcomm_tty_write (struct tty_struct *tty,const unsigned char *buf,int count) +static int rfcomm_tty_write (struct tty_struct *tty,const u8 *buf,int count) {struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;struct rfcomm_dlc *dlc = dev->dlc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 651/1191 tty: ipoctal: convert to u8 and size_t
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 2f982313279baa066f03f4816f3fa3521a4d41cb ]
Switch character types to u8 and sizes to size_t. To conform to characters/sizes in the rest of the tty layer.
Stable-dep-of: b6b5d64cb161 ("ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove")
--- drivers/ipack/devices/ipoctal.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/ipack/devices/ipoctal.c +6 -8
@@ -158,9 +158,7 @@ static int ipoctal_get_icount(struct tty_struct *tty,static void ipoctal_irq_rx (struct ipoctal_channel *channel,u8 sr) {struct tty_port *port = &channel->tty_port; -unsigned char value; -unsigned char flag; -u8 isr; +u8 isr, value, flag; do { value = ioread8(&channel->regs->r.rhr);
@@ -202,8 +200,8 @@ static void ipoctal_irq_rx(struct ipoctal_channel *channel, u8 sr)static void ipoctal_irq_tx (struct ipoctal_channel *channel) { -unsigned char value;unsigned int *pointer_write = &channel->pointer_write; +u8 value;if (channel->nb_bytes ==0 )return ;
@@ -436,11 +434,11 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,return res; } -static inline int ipoctal_copy_write_buffer (struct ipoctal_channel *channel, -const u8 *buf,int count) +static inline size_t ipoctal_copy_write_buffer (struct ipoctal_channel *channel, +const u8 *buf,size_t count) {unsigned long flags; -int i; +size_t i;unsigned int *pointer_read = &channel->pointer_read;/* Copy the bytes from the user buffer to the internal one */
@@ -461,7 +459,7 @@ static inline int ipoctal_copy_write_buffer(struct ipoctal_channel *channel,static int ipoctal_write_tty (struct tty_struct *tty,const u8 *buf,int count) {struct ipoctal_channel *channel = tty->driver_data; -unsigned int char_copied; +size_t char_copied; char_copied =ipoctal_copy_write_buffer (channel, buf, count);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 652/1191 ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit b6b5d64cb161a28347d64dc3168a636c4abb68d5 ]
Three issues arise when the device is removed while a tty session is still active:
1. UAF of struct ipoctal: the remove callback frees ipoctal via kfree() while tty ops may still access it. Fix by introducing kref-based lifetime management — kref is taken in install() when a tty is opened and released in cleanup() when the tty is finally destroyed; remove() uses kref_put() instead of kfree().
2. NULL dereference in ipoctal_write_tty(): __ipoctal_remove() frees xmit_buf via tty_port_free_xmit_buf() while a userspace process may still hold the tty fd and call write(). Fix by checking for NULL xmit_buf in ipoctal_write_tty().
3. UAF in ipoctal_cleanup(): ipack_put_carrier(ipoctal->dev) dereferences ipoctal->dev after the ipack_device has been freed by ipack_device_del(). Fix by caching ipoctal->carrier_owner during probe() and calling module_put() on the cached pointer directly in cleanup(), avoiding any access to ipoctal->dev.
Also introduce a "removed" flag in struct ipoctal, set at the start of __ipoctal_remove(), and checked in every tty op that accesses hardware resources (port_activate, write_tty, set_termios, hangup, shutdown). This prevents page faults when devm_ioremap() regions are unmapped after remove() returns.
--- drivers/ipack/devices/ipoctal.c | 56 ++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-)
drivers/ipack/devices/ipoctal.c +52 -4
@@ -10,6 +10,7 @@#include <linux/device.h> #include <linux/module.h> #include <linux/interrupt.h> +#include <linux/kref.h> #include <linux/sched.h> #include <linux/tty.h> #include <linux/serial.h>
@@ -25,6 +26,8 @@static const struct tty_operations ipoctal_fops; +static void ipoctal_release (struct kref *kref); +struct ipoctal_channel {struct ipoctal_stats stats;unsigned int nb_bytes;
@@ -49,6 +52,9 @@ struct ipoctal {struct tty_driver *tty_drv;u8 __iomem *mem8_space;u8 __iomem *int_space; +struct kref kref; +struct module *carrier_owner; +bool removed; }; static inline struct ipoctal *chan_to_ipoctal(struct ipoctal_channel *chan,
@@ -70,8 +76,14 @@ static void ipoctal_reset_channel(struct ipoctal_channel *channel)static int ipoctal_port_activate (struct tty_port *port,struct tty_struct *tty) {struct ipoctal_channel *channel; +struct ipoctal *ipoctal; channel =dev_get_drvdata (tty->dev); + ipoctal =chan_to_ipoctal (channel, tty->index); + + +if (ipoctal->removed) +return -ENODEV ;/* * Enable RX. TX will be enabled when
@@ -95,6 +107,7 @@ static int ipoctal_install(struct tty_driver *driver, struct tty_struct *tty)if (res) goto err_put_carrier; +kref_get (&ipoctal->kref); tty->driver_data = channel;return 0 ;
@@ -459,8 +472,13 @@ static inline size_t ipoctal_copy_write_buffer(struct ipoctal_channel *channel,static int ipoctal_write_tty (struct tty_struct *tty,const u8 *buf,int count) {struct ipoctal_channel *channel = tty->driver_data; +struct ipoctal *ipoctal =chan_to_ipoctal (channel, tty->index);size_t char_copied; + +if (ipoctal->removed || !channel->tty_port.xmit_buf) +return 0 ; + char_copied =ipoctal_copy_write_buffer (channel, buf, count);/* As the IP-OCTAL 485 only supports half duplex, do it manually */
@@ -500,8 +518,13 @@ static void ipoctal_set_termios(struct tty_struct *tty,unsigned char mr2 =0 ;unsigned char csr =0 ;struct ipoctal_channel *channel = tty->driver_data; +struct ipoctal *ipoctal =chan_to_ipoctal (channel, tty->index);speed_t baud; + +if (ipoctal->removed) +return ; + cflag = tty->termios.c_cflag;/* Disable and reset everything before change the setup */
@@ -630,10 +653,16 @@ static void ipoctal_hangup(struct tty_struct *tty) {unsigned long flags;struct ipoctal_channel *channel = tty->driver_data; +struct ipoctal *ipoctal;if (channel ==NULL )return ; + ipoctal =chan_to_ipoctal (channel, tty->index); + +if (ipoctal->removed) +return ; +spin_lock_irqsave (&channel->lock, flags); channel->nb_bytes =0 ; channel->pointer_read =0 ;
@@ -650,10 +679,16 @@ static void ipoctal_hangup(struct tty_struct *tty)static void ipoctal_shutdown (struct tty_struct *tty) {struct ipoctal_channel *channel = tty->driver_data; +struct ipoctal *ipoctal;if (channel ==NULL )return ; + ipoctal =chan_to_ipoctal (channel, tty->index); + +if (ipoctal->removed) +return ; +ipoctal_reset_channel (channel);tty_port_set_initialized (&channel->tty_port,0 ); }
@@ -663,8 +698,9 @@ static void ipoctal_cleanup(struct tty_struct *tty)struct ipoctal_channel *channel = tty->driver_data;struct ipoctal *ipoctal =chan_to_ipoctal (channel, tty->index); -/* release the carrier driver */ -ipack_put_carrier (ipoctal->dev); +/* release the carrier driver via cached owner */ +module_put (ipoctal->carrier_owner); +kref_put (&ipoctal->kref, ipoctal_release); }static const struct tty_operations ipoctal_fops = {
@@ -682,6 +718,13 @@ static const struct tty_operations ipoctal_fops = { .cleanup = ipoctal_cleanup, }; +static void ipoctal_release (struct kref *kref) +{ + struct ipoctal *ipoctal = container_of(kref, struct ipoctal, kref); + +kfree (ipoctal); +} +static int ipoctal_probe (struct ipack_device *dev) {int res;
@@ -691,7 +734,10 @@ static int ipoctal_probe(struct ipack_device *dev)if (ipoctal ==NULL )return -ENOMEM ; +kref_init (&ipoctal->kref); + ipoctal->dev = dev; + ipoctal->carrier_owner = dev->bus->owner; res =ipoctal_inst_slot (ipoctal, dev->bus->bus_nr, dev->slot);if (res) goto out_uninst;
@@ -700,7 +746,7 @@ static int ipoctal_probe(struct ipack_device *dev)return 0 ; out_uninst: -kfree (ipoctal); +kref_put (&ipoctal->kref, ipoctal_release);return res; }
@@ -708,6 +754,8 @@ static void __ipoctal_remove(struct ipoctal *ipoctal) {int i; + ipoctal->removed = true; + ipoctal->dev->bus->ops->free_irq (ipoctal->dev);for (i =0 ; i <NR_CHANNELS ; i++) {
@@ -724,7 +772,7 @@ static void __ipoctal_remove(struct ipoctal *ipoctal)tty_unregister_driver (ipoctal->tty_drv);kfree (ipoctal->tty_drv->name);tty_driver_kref_put (ipoctal->tty_drv); -kfree (ipoctal); +kref_put (&ipoctal->kref, ipoctal_release); }static void ipoctal_remove (struct ipack_device *idev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 653/1191 char: xilinx_hwicap: unregister class on init errors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit e7e12b4cc0f0c3a2782aea084d4215e23f5512b3 ]
hwicap_module_init() registers icap_class before reserving the character-device region and registering the platform driver. If either of those later steps fails, the init path must undo the successful class registration before returning an error.
Route the chrdev registration failure through a class unwind label, and let the platform-driver registration failure fall through the existing chrdev unwind before unregistering the class. The normal module exit path is unchanged.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/char/xilinx_hwicap/xilinx_hwicap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/xilinx_hwicap/xilinx_hwicap.c +4 -1
@@ -864,7 +864,7 @@ static int __init hwicap_module_init(void)HWICAP_DEVICES , DRIVER_NAME);if (retval <0 ) -return retval; + goto failed_class; retval =platform_driver_register (&hwicap_platform_driver);if (retval)
@@ -875,6 +875,9 @@ static int __init hwicap_module_init(void) failed:unregister_chrdev_region (devt,HWICAP_DEVICES ); + failed_class: +class_unregister (&icap_class); +return retval; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 654/1191 vfio/pci: clear vdev->msi_perm after freeing it on init failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit dc77acfeb979dded39b247b60fef0399536bfa77 ]
vfio_msi_cap_len() lazily allocates the per-device MSI permission table:
vdev->msi_perm = kmalloc_obj(struct perm_bits, GFP_KERNEL_ACCOUNT);
if (!vdev->msi_perm)
return -ENOMEM;
ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
if (ret) {
kfree(vdev->msi_perm);
return ret; /* vdev->msi_perm left dangling */
}When init_pci_cap_msi_perm() -> alloc_perm_bits() fails with -ENOMEM, the error path frees vdev->msi_perm but leaves the freed pointer stored in it. vdev->msi_perm is not re-zeroed later because struct vfio_pci_core_device is per-device and persists across open/close cycles, and the vfio_config_init() error path returns without calling vfio_config_free(). So the dangling pointer outlives the failed open.
That leads to two use-after-frees on the same device:
1. Reuse. The next vfio_config_init() sees the stale pointer at "if (vdev->msi_perm) return len;" and reuses the freed object. MSI config accesses in vfio_pci_config_rw_single() then dereference and call the freed perm->readfn / perm->writefn function pointers.
2. Double free. A later vfio_config_free() runs free_perm_bits() and kfree() on the already-freed object.
Fix it by NULLing vdev->msi_perm after the kfree(), matching the NULL-after-free discipline already used in free_perm_bits() and vfio_config_free().
BUG: KASAN: slab-use-after-free in vfio_pci_config_rw_single (drivers/vfio/pci/vfio_pci_config.c:1961) Read of size 8 at addr ffff88800fcc88d0 by task exploit/143 Call Trace: ... kasan_report (mm/kasan/report.c:595) vfio_pci_config_rw_single (drivers/vfio/pci/vfio_pci_config.c:1961) vfio_pci_config_rw (drivers/vfio/pci/vfio_pci_config.c:1986) vfio_pci_rw (drivers/vfio/pci/vfio_pci_core.c:1599) vfs_read (fs/read_write.c:572) __x64_sys_pread64 (fs/read_write.c:764) do_syscall_64 (arch/x86/entry/syscall_64.c:94) ...
Followed on device close by a double free of the same object:
Oops: general protection fault, probably for non-canonical address
0x1f63e0e8000008: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:kfree (mm/slub.c:6711)
Call Trace:
vfio_config_free (drivers/vfio/pci/vfio_pci_config.c:1861)
vfio_pci_core_disable (drivers/vfio/pci/vfio_pci_core.c:685)
vfio_pci_core_close_device (drivers/vfio/pci/vfio_pci_core.c:777)
vfio_df_close (drivers/vfio/vfio_main.c:602)
vfio_device_fops_release (drivers/vfio/vfio_main.c:648)
__fput (fs/file_table.c:512)
__x64_sys_close (fs/open.c:1496)
do_syscall_64 (arch/x86/entry/syscall_64.c:94)
...
Kernel panic - not syncing: Fatal exception--- drivers/vfio/pci/vfio_pci_config.c | 1 + 1 file changed, 1 insertion(+)
drivers/vfio/pci/vfio_pci_config.c +1 -0
@@ -1255,6 +1255,7 @@ static int vfio_msi_cap_len(struct vfio_pci_core_device *vdev, u8 pos) ret =init_pci_cap_msi_perm (vdev->msi_perm, len, flags);if (ret) {kfree (vdev->msi_perm); + vdev->msi_perm =NULL ;return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 655/1191 soc: ti: knav_qmss_queue: Implement resource cleanup in remove()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Md Shofiqul Islam <[email protected]>
[ Upstream commit 10a1969353b20caa50c320717e054601631c0d3e ]
Implement the TODO in knav_queue_remove() by stopping PDSPs and freeing queue regions and queue ranges before disabling runtime PM, mirroring the cleanup performed in the probe error path.
Set device_ready to false before cleanup to prevent any further use of the device during teardown.
This ensures resources are released on driver unbind and avoids leaking queue/region state.
Stable-dep-of: 3c8178627599 ("soc: ti: knav_qmss: Remove debugfs file on teardown")
--- drivers/soc/ti/knav_qmss_queue.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/soc/ti/knav_qmss_queue.c +6 -1
@@ -1886,7 +1886,12 @@ static int knav_queue_probe(struct platform_device *pdev)static int knav_queue_remove (struct platform_device *pdev) { -/* TODO: Free resources */ +struct knav_device *kdev =platform_get_drvdata (pdev); + + device_ready = false; +knav_queue_stop_pdsps (kdev); +knav_queue_free_regions (kdev); +knav_free_queue_ranges (kdev);pm_runtime_put_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 656/1191 soc: ti: knav_qmss: Remove debugfs file on teardown
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 3c817862759913097f11467ed4ed2bbf974dabaf ]
knav_queue_probe() creates the global qmss debugfs file whose show callback reads the global knav_qdev state. knav_queue_remove() tears down the queue manager resources but leaves the debugfs file published.
Save the debugfs dentry in struct knav_device and remove it during teardown before the resources used by the show callback are released. While touching the debugfs_create_file() call, spell the unchanged read- only file mode as 0444.
--- drivers/soc/ti/knav_qmss.h | 1 + drivers/soc/ti/knav_qmss_queue.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/soc/ti/knav_qmss.h +1 -0
@@ -304,6 +304,7 @@ struct knav_device {struct list_head pools;struct list_head pdsps;struct list_head qmgrs; +struct dentry *debugfs_file;enum qmss_version version; };
drivers/soc/ti/knav_qmss_queue.c +5 -2
@@ -1870,8 +1870,9 @@ static int knav_queue_probe(struct platform_device *pdev) goto err; } -debugfs_create_file ("qmss" ,S_IFREG |S_IRUGO ,NULL ,NULL , - &knav_queue_debug_fops); + knav_qdev->debugfs_file = +debugfs_create_file ("qmss" ,0444 ,NULL ,NULL , + &knav_queue_debug_fops); device_ready = true;return 0 ;
@@ -1889,6 +1890,8 @@ static int knav_queue_remove(struct platform_device *pdev)struct knav_device *kdev =platform_get_drvdata (pdev); device_ready = false; +debugfs_remove (kdev->debugfs_file); + kdev->debugfs_file =NULL ;knav_queue_stop_pdsps (kdev);knav_queue_free_regions (kdev);knav_free_queue_ranges (kdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 657/1191 mtd: mtdswap: Avoid freeing registered blktrans device twice
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 779aa4c66a96bf43d2d62982ea1a9096a9128d87 ]
In mtdswap_add_mtd(), debugfs setup failure after successful blktrans registration can free mbd_dev twice.
add_mtd_blktrans_dev() initializes the blktrans device reference and publishes the disk. Once that succeeds, del_mtd_blktrans_dev() tears the disk down and drops the blktrans reference; when that reference reaches zero, blktrans_dev_release() frees the mtd_blktrans_dev.
The debugfs failure path called del_mtd_blktrans_dev(mbd_dev), then fell through the common cleanup label and called kfree(mbd_dev) again. Clear the local pointer after deregistration so the common cleanup can still release the mtdswap state without freeing the blktrans object twice.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/mtd/mtdswap.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/mtdswap.c +1 -0
@@ -1452,6 +1452,7 @@ static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) debugfs_failed:del_mtd_blktrans_dev (mbd_dev); + mbd_dev =NULL ; cleanup:mtdswap_cleanup (d);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 658/1191 mtd: part: reject MTDPART_OFS_RETAIN in mtd_add_partition()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: zhouminqiang <[email protected]>
[ Upstream commit b759d5bb6265419344ee9729fd0dc07ad85719d8 ]
mtd_add_partition() does not reject the special offset value MTDPART_OFS_RETAIN (-3), which leads to a WARN_ON in add_mtd_device() when called through the BLKPG ioctl on NAND devices. The RETAIN value depends on cur_offset being the end of the previous partition, but in the dynamic partition path cur_offset equals the offset argument itself, causing undefined behavior.
Commit 5daa7b21496a ("mtd: prepare partition add and del functions for ioctl requests") introduced mtd_add_partition() and correctly rejected MTDPART_OFS_APPEND (-1) and MTDPART_OFS_NXTBLK (-2), since those special offsets rely on cur_offset tracking the previous partition's end. However, commit 1a31368bf92e ("mtd: add a flags for partitions which should just leave smth. after them") later added MTDPART_OFS_RETAIN (-3) for the static
partition table path without updating mtd_add_partition() to also reject this value.
With offset=-3 passed via BLKPG, the RETAIN size calculation in allocate_partition() underflows (parent_size - 0xFFFFFFFFFFFFFFFD = parent_size + 3). If the underflow result does not appear to leave enough space, allocate_partition() jumps to out_register via goto, skipping erasesize initialization. This results in erasesize=0, which triggers:
WARN_ON((!mtd->erasesize || !master->_erase) &&
!(mtd->flags & MTD_NO_ERASE))
in add_mtd_device(). If the underflow result appears to leave enough space, a bogus partition size is calculated, but the "out of reach" sanity check catches the invalid offset and creates a disabled empty partition (offset=0, size=0) instead of returning an error.
Fix this by adding MTDPART_OFS_RETAIN to the rejection list in mtd_add_partition(), consistent with the existing handling of APPEND and NXTBLK.
--- drivers/mtd/mtdpart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/mtdpart.c +2 -1
@@ -248,7 +248,8 @@ int mtd_add_partition(struct mtd_info *parent, const char *name,/* the direct offset is expected */ if (offset ==MTDPART_OFS_APPEND || - offset ==MTDPART_OFS_NXTBLK ) + offset ==MTDPART_OFS_NXTBLK || + offset ==MTDPART_OFS_RETAIN )return -EINVAL ;if (length ==MTDPART_SIZ_FULL )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 659/1191 perf ui hists: Fix uninitialized stack memory free on pstack allocation failure
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 d5fdde1c426922efabe86a515f0782b3eba40577 ]
Fixes heap corruption by initializing the options and actions arrays before the pstack allocation check, preventing an uninitialized stack pointer from being passed to free_popup_options() if the allocation fails.
--- tools/perf/ui/browsers/hists.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/hists.c +3 -3
@@ -3005,15 +3005,15 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h browser->min_pcnt = min_pcnt;hist_browser__update_nr_entries (browser); +memset (options,0 ,sizeof (options)); +memset (actions,0 ,sizeof (actions)); + browser->pstack =pstack__new (3 );if (browser->pstack ==NULL ) goto out;ui_helpline__push (helpline); -memset (options,0 ,sizeof (options)); -memset (actions,0 ,sizeof (actions)); -if (symbol_conf.col_width_list_str)perf_hpp__set_user_width (symbol_conf.col_width_list_str);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 660/1191 software node: Fix software_node_get_reference_args() with index -1
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alban Bedel <[email protected]>
[ Upstream commit ba3dedcf3bd47017307595a7e54924198f018246 ]
The bounds check for the index passed to software_node_get_reference_args() was failing when passed UINT_MAX, this in turn would lead to an out of bound access in the property array. Fix the bound check to also cover the UINT_MAX case.
--- drivers/base/swnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/swnode.c +1 -1
@@ -518,7 +518,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,if (prop->is_inline)return -EINVAL ; -if ((index +1 ) *sizeof (*ref) > prop->length) +if (index >= prop->length /sizeof (*ref))return -ENOENT ; ref_array = prop->pointer;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 661/1191 driver core: soc: remove layering violation for the soc_bus
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit 90be1f15c39858a4f0f4346c39fa150697d231c1 ]
The soc_bus code pokes around in the internal bus structures assuming that it "knows" if a field is not set that it has not been registered yet. That isn't a safe assumption, so just remove the layering violation entirely and keep track if the bus has been registered or not ourselves.
Stable-dep-of: 45dfa004893d ("driver core: soc: Unregister bus on early device registration failure")
--- drivers/base/soc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/soc.c +3 -1
@@ -30,6 +30,7 @@ struct soc_device {static struct bus_type soc_bus_type = { .name ="soc" , }; +static bool soc_bus_registered; static DEVICE_ATTR(machine, 0444, soc_info_show, NULL); static DEVICE_ATTR(family, 0444, soc_info_show, NULL);
@@ -117,7 +118,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attrconst struct attribute_group **soc_attr_groups;int ret; -if (!soc_bus_type.p) { +if (!soc_bus_registered) {if (early_soc_dev_attr)return ERR_PTR (-EBUSY ); early_soc_dev_attr = soc_dev_attr;
@@ -183,6 +184,7 @@ static int __init soc_bus_register(void) ret =bus_register (&soc_bus_type);if (ret)return ret; + soc_bus_registered = true;if (early_soc_dev_attr)return PTR_ERR (soc_device_register (early_soc_dev_attr));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 662/1191 driver core: soc: Unregister bus on early device registration failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 45dfa004893dfeae182ec27eddbd153c6d4ddbf9 ]
soc_bus_register() registers the SoC bus before registering a deferred early SoC device. If soc_device_register() fails in that path, the function returns the error directly and leaves the bus registered.
Store the returned SoC device pointer explicitly so the success and error cases are handled separately. On failure, clear soc_bus_registered and unregister the bus before returning the error.
--- drivers/base/soc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/base/soc.c +13 -2
@@ -179,6 +179,7 @@ EXPORT_SYMBOL_GPL(soc_device_unregister);static int __init soc_bus_register (void ) { +struct soc_device *soc_dev;int ret; ret =bus_register (&soc_bus_type);
@@ -186,10 +187,20 @@ static int __init soc_bus_register(void)return ret; soc_bus_registered = true; -if (early_soc_dev_attr) -return PTR_ERR (soc_device_register (early_soc_dev_attr)); +if (early_soc_dev_attr) { + soc_dev =soc_device_register (early_soc_dev_attr); +if (IS_ERR (soc_dev)) { + ret =PTR_ERR (soc_dev); + goto err_unregister_bus; + } + }return 0 ; + +err_unregister_bus: + soc_bus_registered = false; +bus_unregister (&soc_bus_type); +return ret; }core_initcall (soc_bus_register);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 663/1191 dmaengine: dw-edma: Serialize abort state updates
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit dd80e259f65d932634e26d366570d71669ef6654 ]
dw_edma_abort_interrupt() drops vc.lock before changing request and status. issue_pending() can acquire the lock in that small window, observe the old busy state, and skip starting queued descriptors. Then the abort handler overwrites the channel status as idle, leaving the new descriptors stranded for good.
Keep descriptor completion and the state transition in the same critical section.
--- drivers/dma/dw-edma/dw-edma-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dw-edma/dw-edma-core.c +1 -1
@@ -649,9 +649,9 @@ static void dw_edma_abort_interrupt(struct dw_edma_chan *chan)list_del (&vd->node);vchan_cookie_complete (vd); } -spin_unlock_irqrestore (&chan->vc.lock, flags); chan->request =EDMA_REQ_NONE ; chan->status =EDMA_ST_IDLE ; +spin_unlock_irqrestore (&chan->vc.lock, flags); }static irqreturn_t dw_edma_interrupt (int irq,void *data,bool write)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 664/1191 dmaengine: dw-edma: Serialize channel state checks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit f7d1619f3e10c619b62c6cd6d95371b5c526c85a ]
pause() and resume() read and update channel state without holding vc.lock, while the interrupt handlers update the same state under it. Take the same lock around those state checks so that request, status, and configured stay consistent.
For example, pause() can observe EDMA_ST_BUSY right before the interrupt handler completes the final descriptor and moves the channel to EDMA_ST_IDLE, and then record EDMA_REQ_PAUSE on an already idle channel. No further interrupt will acknowledge the request, and since issue_pending() requires EDMA_REQ_NONE, the channel is wedged for good: terminate_all() leaves the stale request behind, so even reconfiguring the channel does not recover it.
issue_pending() already runs under vc.lock, but it tests configured before taking it. Move that test under the lock as well, so configured, request, and status are evaluated as one channel-state snapshot.
--- drivers/dma/dw-edma/dw-edma-core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +6 -4
@@ -215,6 +215,8 @@ static int dw_edma_device_pause(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);int err =0 ; +guard (spinlock_irqsave)(&chan->vc.lock); +if (!chan->configured) err = -EPERM ;else if (chan->status !=EDMA_ST_BUSY )
@@ -232,6 +234,8 @@ static int dw_edma_device_resume(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);int err =0 ; +guard (spinlock_irqsave)(&chan->vc.lock); +if (!chan->configured) { err = -EPERM ; }else if (chan->status !=EDMA_ST_PAUSE ) {
@@ -280,11 +284,9 @@ static void dw_edma_device_issue_pending(struct dma_chan *dchan)struct dw_edma_chan *chan =dchan2dw_edma_chan (dchan);unsigned long flags; -if (!chan->configured) -return ; -spin_lock_irqsave (&chan->vc.lock, flags); -if (vchan_issue_pending (&chan->vc) && chan->request ==EDMA_REQ_NONE && +if (chan->configured &&vchan_issue_pending (&chan->vc) && + chan->request ==EDMA_REQ_NONE && chan->status ==EDMA_ST_IDLE ) { chan->status =EDMA_ST_BUSY ;dw_edma_start_transfer (chan);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 665/1191 dmaengine: dw-edma: Clear stale requests on termination
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit c0d9c6275adcca7c0ca5f4270bf88026f9864bd1 ]
terminate_all() can finish immediately when the channel is unconfigured, paused, idle, or already stopped in hardware. A pending PAUSE request can survive these paths and block issue_pending() even after termination.
Clear the request whenever termination leaves the channel idle. A running channel keeps its STOP request until the interrupt handler consumes it.
--- drivers/dma/dw-edma/dw-edma-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/dma/dw-edma/dw-edma-core.c +2 -0
@@ -275,6 +275,8 @@ static int dw_edma_device_terminate_all(struct dma_chan *dchan) }else { chan->request =EDMA_REQ_STOP ; } +if (chan->status ==EDMA_ST_IDLE ) + chan->request =EDMA_REQ_NONE ;return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 666/1191 ASoC: meson: Keep link pointers valid on realloc failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
[ Upstream commit 2aaa41cf974f83a6fb105422bac4e2f107150774 ]
meson_card_reallocate_links() grows the DAI link and private data arrays with two consecutive krealloc() calls and updates the owner pointers only after both calls have succeeded.
A successful krealloc() may move the data: it frees the old block and returns a new one. When that happens for the link array and the second krealloc() then fails, card->dai_link still points to the block that krealloc() already freed, and the error path frees the new block too. The probe error path then calls meson_card_clean_references(), which dereferences card->dai_link and kfree()s it again, resulting in a use-after-free and a double free.
Commit card->dai_link and card->num_links right after the first krealloc() succeeds, so the pointer always refers to a valid allocation that meson_card_clean_references() can walk and free. krealloc() with __GFP_ZERO zero-initializes the added entries, so walking them on the error path is safe. With both failure paths reduced to a plain return, drop the goto labels and the error message.
--- sound/soc/meson/meson-card-utils.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
sound/soc/meson/meson-card-utils.c +6 -11
@@ -50,25 +50,20 @@ int meson_card_reallocate_links(struct snd_soc_card *card, num_links *sizeof (*priv->card.dai_link), GFP_KERNEL | __GFP_ZERO);if (!links) - goto err_links; +return -ENOMEM ; + + priv->card.dai_link = links; + priv->card.num_links = num_links; ldata =krealloc (priv->link_data, num_links *sizeof (*priv->link_data),GFP_KERNEL | __GFP_ZERO); +/* meson_card_clean_references() will free the links on this error path */ if (!ldata) - goto err_ldata; +return -ENOMEM ; - priv->card.dai_link = links; priv->link_data = ldata; - priv->card.num_links = num_links;return 0 ; - -err_ldata: -kfree (links); -err_links: -dev_err (priv->card.dev,"failed to allocate links\n" ); -return -ENOMEM ; - }EXPORT_SYMBOL_GPL (meson_card_reallocate_links);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 667/1191 arm64: dts: amlogic: meson-axg-s400: enable mipi_pcie_analog_dphy for PCIe
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jun Yan <[email protected]>
[ Upstream commit 7f1d0cc86cb70fa550163b6f70fd1d484c03218e ]
The PCIe PHY node references mipi_pcie_analog_dphy via its phys property. Enable this analog PHY node to make PCIe functionally viable.
--- arch/arm64/boot/dts/amlogic/meson-axg-s400.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/amlogic/meson-axg-s400.dts +4 -0
@@ -434,6 +434,10 @@ gpio_speaker: gpio-controller@1f { }; }; +&mipi_pcie_analog_dphy { + status = "okay"; +}; + &pdm { pinctrl-0 = <&pdm_dclk_a14_pins>, <&pdm_din0_pins>, <&pdm_din1_pins>, <&pdm_din2_pins>, <&pdm_din3_pins>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 668/1191 RDMA/hfi1: Propagate sdma_txinit_ahg() errors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danila Chernetsov <[email protected]>
[ Upstream commit 091c6162c022cbdfb64219708a71728cfd1d4600 ]
set_txreq_header_ahg() ignores the return value of sdma_txinit_ahg().
If sdma_txinit_ahg() fails, it returns before initializing tx->txreq. However, set_txreq_header_ahg() ignores the error and returns the AHG change count, causing the caller to continue processing the request as though initialization had succeeded.
Propagate sdma_txinit_ahg() failures to the caller and abort request processing when initialization fails.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/infiniband/hw/hfi1/user_sdma.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/infiniband/hw/hfi1/user_sdma.c +8 -5
@@ -1059,6 +1059,7 @@ static int set_txreq_header_ahg(struct user_sdma_request *req, struct user_sdma_txreq *tx, u32 datalen) {u32 ahg[AHG_KDETH_ARRAY_SIZE ]; +int ret;int idx =0 ;u8 omfactor;/* KDETH.OM */ struct hfi1_user_sdma_pkt_q *pq = req->pq;
@@ -1163,11 +1164,13 @@ static int set_txreq_header_ahg(struct user_sdma_request *req,trace_hfi1_sdma_user_header_ahg (pq->dd, pq->ctxt, pq->subctxt, req->info.comp_idx, req->sde->this_idx, req->ahg_idx, ahg, idx, tidval); -sdma_txinit_ahg (&tx->txreq, -SDMA_TXREQ_F_USE_AHG , - datalen, req->ahg_idx, idx, - ahg,sizeof (req->hdr), - user_sdma_txreq_cb); + ret =sdma_txinit_ahg (&tx->txreq, +SDMA_TXREQ_F_USE_AHG , + datalen, req->ahg_idx, idx, + ahg,sizeof (req->hdr), + user_sdma_txreq_cb); +if (ret) +return ret;return idx; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 669/1191 RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
[ Upstream commit 126c757e4cd46f866ddc283143b58eb4d9bf52cd ]
For a user QP, qp->sq.queue is a ring the application writes directly, so rxe_post_send() takes the is_user branch and only schedules send_task without validating the WQE. rxe_requester() consumes it in place via req_next_wqe() and calls copy_data(), which indexes &wqe->dma.sge[cur_sge] with the attacker-controlled num_sge/cur_sge. Only the kernel path bounds num_sge (validate_send_wr()); the user WQE is never checked, so a local unprivileged user can post a WQE with an out-of-range cur_sge or oversized num_sge and force an out-of-bounds read of the per-WQE sge array in copy_data() (vmalloc OOB read, local DoS).
Bound num_sge to qp->sq.max_sge in rxe_requester() before use, the way get_srq_wqe() already guards SRQ entries, and bound cur_sge only when the WQE carries payload (dma.resid): copy_data() returns early on a zero-length copy before touching dma->sge[], so a zero-payload WQE -- the only kind a max_sge == 0 QP can post -- stays valid.
Reproduced under KASAN; the vmalloc-out-of-bounds in copy_data() is gone.
--- drivers/infiniband/sw/rxe/rxe_req.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/infiniband/sw/rxe/rxe_req.c +15 -0
@@ -680,6 +680,21 @@ int rxe_requester(void *arg)if (unlikely (!wqe)) goto exit; +/* +* Don't trust user space data: a user QP's WQE comes from an mmap'd +* ring, so num_sge/cur_sge are attacker-controlled. Bound num_sge like +* get_srq_wqe(); bound cur_sge only when payload exists (dma.resid), +* since copy_data() skips dma->sge[] on a zero-length copy (all a +* max_sge == 0 QP can post). +*/ +if (unlikely (wqe->dma.num_sge > qp->sq.max_sge || + (wqe->dma.resid && + wqe->dma.cur_sge >= qp->sq.max_sge))) { +rxe_dbg_qp (qp,"invalid num_sge/cur_sge in send wqe\n" ); + wqe->status =IB_WC_LOC_QP_OP_ERR ; + goto err; + } +if (rxe_wqe_is_fenced (qp, wqe)) { qp->req.wait_fence =1 ; goto exit;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 670/1191 RDMA/srpt: Fix srpt_alloc_rw_ctxs() unwind counters
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: TanZheng <[email protected]>
[ Upstream commit b38f98e176050850f41bb6415f3a71400056623e ]
When srpt_alloc_rw_ctxs() fails partway through a multi-buffer indirect descriptor, the unwind path destroys RDMA contexts but leaves stale n_rw_ctx and n_rdma values (and a dangling rw_ctxs pointer). Later sq_wr_avail accounting in srpt_queue_response() or srpt_write_pending() can then subtract the wrong number of send queue credits.
Reset the counters and clear rw_ctxs after freeing the heap allocation before returning an error.
--- drivers/infiniband/ulp/srpt/ib_srpt.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/infiniband/ulp/srpt/ib_srpt.c +7 -0
@@ -959,6 +959,7 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx,struct srpt_rdma_ch *ch = ioctx->ch;struct scatterlist *prev =NULL ;unsigned prev_nents; +u8 n_rdma, n_rw_ctx;int ret, i;if (nbufs ==1 ) {
@@ -970,6 +971,9 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx,return -ENOMEM ; } + n_rw_ctx = ioctx->n_rw_ctx; + n_rdma = ioctx->n_rdma; +for (i = ioctx->n_rw_ctx; i < nbufs; i++, db++) {struct srpt_rw_ctx *ctx = &ioctx->rw_ctxs[i];u64 remote_addr =be64_to_cpu (db->va);
@@ -1016,6 +1020,9 @@ static int srpt_alloc_rw_ctxs(struct srpt_send_ioctx *ioctx, }if (ioctx->rw_ctxs != &ioctx->s_rw_ctx)kfree (ioctx->rw_ctxs); + ioctx->rw_ctxs =NULL ; + ioctx->n_rw_ctx = n_rw_ctx; + ioctx->n_rdma = n_rdma;return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 671/1191 kcsan: avoid unintended access checking in NMIs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Elver <[email protected]>
[ Upstream commit a8488ecbd7ba44d65b912dfe88a73f438eba2447 ]
If a watcher deliberately disables interrupts (either by user choice, or because we're dealing with a scoped reordered access) to avoid detecting any data races in interrupts, NMIs are still able to fire.
When we set up a watchpoint on a scoped reordered access, we disabled interrupts because the same CPU cannot observe reordering of its own accesses. To ensure we observe no false positives from NMIs, disable access checking for interrupt contexts as well.
--- kernel/kcsan/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/kcsan/core.c +10 -2
@@ -585,8 +585,14 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsigned* information is lost if dirtied by KCSAN. */ kcsan_save_irqtrace (current); -if (!interrupt_watcher) +if (!interrupt_watcher) {local_irq_save (irq_flags); +/* +* NMIs can still fire, disable checking for all interrupt +* contexts. +*/ +raw_cpu_ptr (&kcsan_cpu_ctx)->disable_count++; + } watchpoint =insert_watchpoint ((unsigned long )ptr, size, is_write);if (watchpoint ==NULL ) {
@@ -699,8 +705,10 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsignedatomic_long_dec (&kcsan_counters[KCSAN_COUNTER_USED_WATCHPOINTS ]); out_unlock: -if (!interrupt_watcher) +if (!interrupt_watcher) { +raw_cpu_ptr (&kcsan_cpu_ctx)->disable_count--;local_irq_restore (irq_flags); + }kcsan_restore_irqtrace (current); ctx->disable_scoped--;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 672/1191 irqchip/gic-v3-its: Prevent leak in its_vpe_irq_domain_alloc()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kemeng Shi <[email protected]>
[ Upstream commit 325ff3e78c64cd619d52b99f7c8b09a3f31e1495 ]
When its_irq_gic_domain_alloc() fails, the following its_vpe_irq_domain_free() fails to invoke its_vep_teardown() for the corresponding interrupt, which leaks the resource.
Invoke its_vpe_teardown() in the error handling path to avoid the leak.
[ tglx: Massaged change log ]
--- drivers/irqchip/irq-gic-v3-its.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +10 -1
@@ -4449,6 +4449,13 @@ static int its_vpe_init(struct its_vpe *vpe)static void its_vpe_teardown (struct its_vpe *vpe) { +/* +* If vpt_page is NULL, then its_vpe_init() has failed, and +* there is nothing to do as no resource has been allocated. +*/ +if (vpe->vpt_page ==NULL ) +return ; +its_vpe_db_proxy_unmap (vpe);its_vpe_id_free (vpe->vpe_id);its_free_pending_table (vpe->vpt_page);
@@ -4527,8 +4534,10 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virqset_bit (i, bitmap); } -if (err) +if (err) { +its_vpe_teardown (vm->vpes[i]);its_vpe_irq_domain_free (domain, virq, i); + }return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 673/1191 RDMA/nldev: validate dynamic counter attribute length
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 74f49255492a62658f36bf2578d7916f1c6ffad1 ]
RDMA_NLDEV_ATTR_STAT_HWCOUNTERS is a nested attribute whose children are consumed directly with nla_get_u32(). The top-level policy validates only the container, so it does not establish the fixed shape of each child.
Require every child payload to be exactly one u32 before reading it.
--- drivers/infiniband/core/nldev.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/infiniband/core/nldev.c +5 -0
@@ -1970,6 +1970,11 @@ static int nldev_stat_set_counter_dynamic_doit(struct nlattr *tb[],nla_for_each_nested (entry_attr, tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS ], rem) { +if (nla_len (entry_attr) !=sizeof (u32)) { + ret = -EINVAL ; + goto out; + } + index =nla_get_u32 (entry_attr);if ((index >= stats->num_counters) || !(stats->descs[index].flags &IB_STAT_FLAG_OPTIONAL )) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 674/1191 ACPI: EC: Avoid _REG disconnect on GPIO IRQ defer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhu Ling <[email protected]>
[ Upstream commit e71bdbce27dcaa7f467a3a198cbe723924f05569 ]
EC event delivery uses either a GPE or, on ACPI reduced hardware platforms, a GpioInt resource. The GPE path does not have a provider lookup that can defer, but acpi_dev_gpio_irq_get() can return -EPROBE_DEFER for the GpioInt path.
ec_install_handlers() currently installs the EC address space handler and executes _REG before looking up the GPIO IRQ. If the GPIO lookup then defers, acpi_ec_setup() tears the handlers down again. Removing the EC address space handler causes ACPICA to execute _REG for disconnect, so firmware may observe an EC OpRegion connected -> disconnected transition during one failed probe attempt.
This is observable when the namespace EC reuses a boot EC that has already installed the EC address space handler. A deferred namespace EC probe can disconnect the already usable boot EC OpRegion until a later reprobe connects it again. AML that gates EC field accesses on _REG state can then return fallback values to other drivers during that window.
Prepare the GPIOInt IRQ before publishing EC OpRegion availability to AML. This leaves the GPE path unchanged, keeps non-deferred GPIO lookup errors non-fatal as before, and still lets the existing acpi_ec_setup() error path clean up real handler installation failures.
--- drivers/acpi/ec.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-)
drivers/acpi/ec.c +26 -14
@@ -1492,6 +1492,24 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec) "ACPI EC", ec) >= 0; } +static int ec_prepare_gpio_irq (struct acpi_ec *ec,struct acpi_device *device) +{ +int irq; + +if (!device || ec->gpe >=0 || ec->irq >=0 ) +return 0 ; + +/* ACPI reduced hardware platforms use a GpioInt from _CRS. */ + irq =acpi_dev_gpio_irq_get (device,0 ); +if (irq == -EPROBE_DEFER ) +return irq; + +if (irq >=0 ) + ec->irq = irq; + +return 0 ; +} +/** * ec_install_handlers - Install service callbacks and register query methods. * @ec: Target EC.
@@ -1506,7 +1524,6 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec)* Return: * -ENODEV if the address space handler cannot be installed, which means * "unable to handle transactions", -* -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred, * or 0 (success) otherwise. */ static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device,
@@ -1539,19 +1556,6 @@ static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device,if (!device)return 0 ; -if (ec->gpe <0 ) { -/* ACPI reduced hardware platforms use a GpioInt from _CRS. */ -int irq =acpi_dev_gpio_irq_get (device,0 ); -/* -* Bail out right away for deferred probing or complete the -* initialization regardless of any other errors. -*/ -if (irq == -EPROBE_DEFER ) -return -EPROBE_DEFER ; -else if (irq >=0 ) - ec->irq = irq; - } -if (!test_bit (EC_FLAGS_QUERY_METHODS_INSTALLED , &ec->flags)) {/* Find and register all query methods */ acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
@@ -1629,6 +1633,14 @@ static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device, bool ca {int ret; +/* +* GPIO IRQ lookup can defer. Do it before publishing the EC +* OpRegion to AML to avoid a spurious _REG(disconnect). +*/ + ret =ec_prepare_gpio_irq (ec, device); +if (ret) +return ret; +/* First EC capable of handling transactions */ if (!first_ec) first_ec = ec;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 675/1191 ACPI: processor: validate MADT IOAPIC entry bounds
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 2c50ffdc73f3a70d745d249f509fc290754121e6 ]
The IOAPIC hotplug lookup parses both MADT and _MAT records directly. The MADT walk previously used a subtable's declared length to advance the cursor after only locating a generic header. The _MAT path likewise passed a generic header to the IOAPIC helper.
Validate that a current record has a complete generic header, that its declared length is contained in the available record range, and that a typed IOAPIC record contains the full fixed IOAPIC body before reading its fields. Use the same relation for both MADT and _MAT provider paths.
--- drivers/acpi/processor_core.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/acpi/processor_core.c +25 -6
@@ -262,11 +262,26 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)EXPORT_SYMBOL_GPL (acpi_get_cpuid);#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC -static int get_ioapic_id (struct acpi_subtable_header *entry,u32 gsi_base, +static bool madt_entry_is_valid (struct acpi_subtable_header *entry, +unsigned long end) +{ +unsigned long start = (unsigned long )entry; + +if (start >= end || end - start <sizeof (*entry)) +return false; + +return entry->length >=sizeof (*entry) && entry->length <= end - start; +} + +static int get_ioapic_id (struct acpi_subtable_header *entry, +const unsigned long end,u32 gsi_base,u64 *phys_addr,int *ioapic_id) {struct acpi_madt_io_apic *ioapic = (struct acpi_madt_io_apic *)entry; +if (!madt_entry_is_valid (entry, end) ||BAD_MADT_ENTRY (ioapic, end)) +return 0 ; +if (ioapic->global_irq_base != gsi_base)return 0 ;
@@ -287,17 +302,19 @@ static int parse_madt_ioapic_entry(u32 gsi_base, u64 *phys_addr)return apic_id; entry = (unsigned long )madt; +if (madt->header.length <sizeof (*madt)) +return apic_id; madt_end = entry + madt->header.length;/* Parse all entries looking for a match. */ entry +=sizeof (struct acpi_table_madt ); -while (entry +sizeof (struct acpi_subtable_header ) < madt_end) { +while (madt_entry_is_valid ((struct acpi_subtable_header *)entry, + madt_end)) { hdr = (struct acpi_subtable_header *)entry;if (hdr->type ==ACPI_MADT_TYPE_IO_APIC && -get_ioapic_id (hdr, gsi_base, phys_addr, &apic_id)) +get_ioapic_id (hdr, madt_end, gsi_base, phys_addr, &apic_id))break ; -else - entry += hdr->length; + entry += hdr->length; }return apic_id;
@@ -324,7 +341,9 @@ static int parse_mat_ioapic_entry(acpi_handle handle, u32 gsi_base, header = (struct acpi_subtable_header *)obj->buffer.pointer;if (header->type ==ACPI_MADT_TYPE_IO_APIC ) -get_ioapic_id (header, gsi_base, phys_addr, &apic_id); +get_ioapic_id (header, + (unsigned long )header + obj->buffer.length, + gsi_base, phys_addr, &apic_id); exit:kfree (buffer.pointer);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 676/1191 ACPI: PCI: Clear driver_data on all paths that free the acpi_pci_root
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Pei <[email protected]>
[ Upstream commit 8a742141f7ab84975aa758b775567ef4740ef0cf ]
acpi_pci_root_add() assigns the freshly allocated root to device->driver_data before dmar_device_add() and pci_acpi_scan_root(). Both failure paths reach the end: label where root is kfree()'d, but only the pci_acpi_scan_root() path clears driver_data first.
When dmar_device_add() fails during a hot-add, root is freed while device->driver_data still points at it. The ACPI core does not clear driver_data on attach failure, so a later acpi_pci_find_root() call may dereference this dangling pointer.
acpi_pci_root_remove() has the same problem: it frees root without clearing device->driver_data, leaving a dangling pointer behind after the root bridge is removed.
Move the NULL assignment to the shared end: label so every error path in acpi_pci_root_add() clears driver_data before freeing root, and clear it in acpi_pci_root_remove() as well, so the object is never left reachable through driver_data after being freed.
--- drivers/acpi/pci_root.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/acpi/pci_root.c +2 -1
@@ -734,7 +734,6 @@ static int acpi_pci_root_add(struct acpi_device *device,dev_err (&device->dev,"Bus %04x:%02x not present in PCI namespace\n" , root->segment, (unsigned int )root->secondary.start); - device->driver_data =NULL ; result = -ENODEV ; goto remove_dmar; }
@@ -770,6 +769,7 @@ static int acpi_pci_root_add(struct acpi_device *device,if (hotadd)dmar_device_remove (handle); end: + device->driver_data =NULL ;kfree (root);return result; }
@@ -793,6 +793,7 @@ static void acpi_pci_root_remove(struct acpi_device *device)pci_unlock_rescan_remove (); + device->driver_data =NULL ;kfree (root); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 677/1191 ext4: fix out-of-bounds read in ext4_read_inline_dir()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 9333cc809f0a89e001b814155a6cb8903a6274df ]
ext4_read_inline_dir() can read a dirent header past the end of its inline buffer, triggering a slab-out-of-bounds read during getdents64():
BUG: KASAN: slab-out-of-bounds in __ext4_check_dir_entry Read of size 2 at addr ffff88800f3dd23c by task exploit/148 ... __ext4_check_dir_entry ext4_read_inline_dir iterate_dir
The dirent payload lives in a buffer of exactly inline_size bytes:
dir_buf = kmalloc(inline_size, GFP_NOFS);
but iteration runs in a position space extra_offset bytes larger (extra_size = extra_offset + inline_size) so the synthetic "." and ".." land at their block-dir offsets. A dirent is formed at "dir_buf + pos - extra_offset", yet the ext4_check_dir_entry() length argument uses the larger extra_size. A position whose dirent header would extend past extra_size is therefore accepted, and the rescan loop's rec_len probe and ext4_check_dir_entry() dereference de->rec_len before the entry is rejected.
Reject a position whose minimum-size dirent header would not fit within extra_size before forming de, in both the rescan and main loops, and pass inline_size rather than extra_size to ext4_check_dir_entry() so the length check matches the physical buffer.
--- fs/ext4/inline.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ext4/inline.c +10 -1
@@ -1579,6 +1579,8 @@ int ext4_read_inline_dir(struct file *file,/* for other entry, the real offset in * the buf has to be tuned accordingly. */ +if (i +ext4_dir_rec_len (1 ,NULL ) > extra_size) +break ; de = (struct ext4_dir_entry_2 *) (dir_buf + i - extra_offset);/* It's too expensive to do a full
@@ -1613,10 +1615,17 @@ int ext4_read_inline_dir(struct file *file,continue ; } +/* +* de lives at dir_buf + ctx->pos - extra_offset, within the +* kmalloc(inline_size) buffer. Make sure its header fits before +* ext4_check_dir_entry() dereferences de->rec_len. +*/ +if (ctx->pos +ext4_dir_rec_len (1 ,NULL ) > extra_size) + goto out; de = (struct ext4_dir_entry_2 *) (dir_buf + ctx->pos - extra_offset);if (ext4_check_dir_entry (inode, file, de, iloc.bh, dir_buf, - extra_size, ctx->pos)) + inline_size, ctx->pos)) goto out; if (le32_to_cpu(de->inode)) { if (!dir_emit(ctx, de->name, de->name_len,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 678/1191 ext4: skip extra isize expansion during mount to prevent deadlock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Zhou <[email protected]>
[ Upstream commit 7461c60b9c6a839b13ad4c3490681a0cf5aa0637 ]
ext4_try_to_expand_extra_isize() is called from __ext4_mark_inode_dirty() while holding an active jbd2 handle. During mount (!SB_ACTIVE), the expand path may move xattrs to external blocks and release ea_inodes via iput(). When !SB_ACTIVE, iput() calls write_inode_now() which acquires s_writepages_rwsem, creating a circular lock dependency:
s_writepages_rwsem --> jbd2_handle --> xattr_sem --> s_writepages_rwsem
This can be triggered via:
ext4_process_orphan() -> ext4_truncate() -> ext4_mark_inode_dirty()
-> ext4_try_to_expand_extra_isize()
or:
ext4_evict_inode() -> ext4_mark_inode_dirty()
-> ext4_try_to_expand_extra_isize()
Skip expansion when !SB_ACTIVE. This is a minor loss of functionality (extra isize won't grow for these inodes during mount), which e2fsck can resolve later if needed.
--- fs/ext4/inode.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/ext4/inode.c +10 -0
@@ -6027,6 +6027,16 @@ static int ext4_try_to_expand_extra_isize(struct inode *inode,if (ext4_test_inode_state (inode,EXT4_STATE_NO_EXPAND ))return -EOVERFLOW ; +/* +* Skip expansion during mount (!SB_ACTIVE). Expanding extra isize +* may move xattrs to external blocks and release ea_inodes via iput. +* When !SB_ACTIVE, iput triggers write_inode_now() which acquires +* s_writepages_rwsem, causing a deadlock with the caller's active +* jbd2 handle (lock order: s_writepages_rwsem -> jbd2_handle). +*/ +if (unlikely (!(inode->i_sb->s_flags &SB_ACTIVE ))) +return -EBUSY ; +/* * In nojournal mode, we can immediately attempt to expand * the inode. When journaled, we first need to obtain extra
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 679/1191 libbpf: Search /lib64 and /lib in resolve_full_path()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo B. Marlière <[email protected]>
[ Upstream commit 7b5ae0481efdac040cea72b4fabd1398109f975b ]
attach_probe/uprobe-lib and uprobe_autoattach selftests fail with "failed to resolve full path for libc.so.6" on older non-usrmerged distros, where libc.so.6 lives under a top-level /lib64 or /lib rather than /usr/lib64 or /usr/lib. Add /lib64:/lib to the search paths, alongside the existing /usr/lib64:/usr/lib and Debian multiarch entries.
--- tools/lib/bpf/libbpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +2 -1
@@ -10735,13 +10735,14 @@ static const char *arch_specific_lib_paths(void)/* Get full path to program/shared library. */ static int resolve_full_path (const char *file,char *result,size_t result_sz) { -const char *search_paths[3 ] = {}; +const char *search_paths[4 ] = {};int i, perm;if (str_has_sfx (file,".so" ) ||strstr (file,".so." )) { search_paths[0 ] =getenv ("LD_LIBRARY_PATH" ); search_paths[1 ] ="/usr/lib64:/usr/lib" ; search_paths[2 ] =arch_specific_lib_paths (); + search_paths[3 ] ="/lib64:/lib" ; perm =R_OK ; }else { search_paths[0 ] =getenv ("PATH" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 680/1191 RDMA/srpt: Pass the mapped task attribute to target_init_cmd()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit ef63cc441703412628a517dda354f3e51fe2dc92 ]
srpt_handle_cmd() maps the initiator-supplied srp_cmd->task_attr into cmd->sam_task_attr, but then hands a hardcoded TCM_SIMPLE_TAG to target_init_cmd().
Pass the already mapped cmd->sam_task_attr instead, so target core sees the attribute the initiator requested.
--- drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -1
@@ -1603,7 +1603,7 @@ static void srpt_handle_cmd(struct srpt_rdma_ch *ch, rc =target_init_cmd (cmd, ch->sess, &send_ioctx->sense_data[0 ],scsilun_to_int (&srp_cmd->lun), data_len, -TCM_SIMPLE_TAG , dir,TARGET_SCF_ACK_KREF ); + cmd->sam_task_attr, dir,TARGET_SCF_ACK_KREF );if (rc !=0 ) {pr_debug ("target_submit_cmd() returned %d for tag %#llx\n" , rc, srp_cmd->tag);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 681/1191 RDMA/erdma: Fix CEQ tasklet use-after-free on removal
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 0ca79979384f031d710c4b3bae065dcb5d95aca3 ]
Each CEQ interrupt handler only schedules eqc->tasklet. The tasklet calls erdma_ceq_completion_handler(), which reads the DMA-coherent EQ ring through get_next_valid_eqe() and updates eq->dbrec through notify_eq().
erdma_ceqs_uninit() frees each CEQ IRQ and then destroys its EQ. free_irq() prevents another hard IRQ and waits for an in-flight handler, but it does not drain a tasklet that the handler already scheduled. The tasklet can therefore access eq->qbuf or eq->dbrec after erdma_eq_destroy() frees them.
Clearing ceq_cb->ready does not synchronize with a tasklet that already passed the check at the start of erdma_ceq_completion_handler().
Kill the tasklet after free_irq(), when no handler can schedule it again, and before erdma_ceq_uninit_one() releases the EQ buffers.
--- drivers/infiniband/hw/erdma/erdma_eq.c | 1 + 1 file changed, 1 insertion(+)
drivers/infiniband/hw/erdma/erdma_eq.c +1 -0
@@ -204,6 +204,7 @@ static void erdma_free_ceq_irq(struct erdma_dev *dev, u16 ceqn)irq_set_affinity_hint (eqc->irq.msix_vector,NULL );free_irq (eqc->irq.msix_vector, eqc); +tasklet_kill (&eqc->tasklet); }static int create_eq_cmd (struct erdma_dev *dev,u32 eqn,struct erdma_eq *eq)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 682/1191 RDMA/nldev: Add NULL check to silence false warnings
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Or Har-Toov <[email protected]>
[ Upstream commit 67e6272d53386f9708f91c4d0015c4a1c470eef5 ]
Using nlmsg_put causes static analysis tools to many false positives of not checking the return value of nlmsg_put.
In all uses in nldev.c, payload parameter is 0 so NULL will never be returned. So let's add useless checks to silence the warnings.
Stable-dep-of: 709ba0e5311b ("RDMA/core: Fix use after free in ib_query_qp()")
--- drivers/infiniband/core/nldev.c | 44 +++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 deletions(-)
drivers/infiniband/core/nldev.c +36 -8
@@ -1043,6 +1043,10 @@ static int nldev_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, nlh =nlmsg_put (msg,NETLINK_CB (skb).portid, nlh->nlmsg_seq,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_GET ),0 ,0 ); +if (!nlh) { + err = -EMSGSIZE ; + goto err_free; + } err =fill_dev_info (msg, device);if (err)
@@ -1128,7 +1132,7 @@ static int _nldev_get_dumpit(struct ib_device *device,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_GET ), 0, NLM_F_MULTI); -if (fill_dev_info (skb, device)) { +if (!nlh ||fill_dev_info (skb, device)) {nlmsg_cancel (skb, nlh); goto out; }
@@ -1187,6 +1191,10 @@ static int nldev_port_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, nlh =nlmsg_put (msg,NETLINK_CB (skb).portid, nlh->nlmsg_seq,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_GET ),0 ,0 ); +if (!nlh) { + err = -EMSGSIZE ; + goto err_free; + } err =fill_port_info (msg, device, port,sock_net (skb->sk));if (err)
@@ -1248,7 +1256,7 @@ static int nldev_port_get_dumpit(struct sk_buff *skb, RDMA_NLDEV_CMD_PORT_GET), 0, NLM_F_MULTI); -if (fill_port_info (skb, device, p,sock_net (skb->sk))) { +if (!nlh ||fill_port_info (skb, device, p,sock_net (skb->sk))) {nlmsg_cancel (skb, nlh); goto out; }
@@ -1290,6 +1298,10 @@ static int nldev_res_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, nlh =nlmsg_put (msg,NETLINK_CB (skb).portid, nlh->nlmsg_seq,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_RES_GET ),0 ,0 ); +if (!nlh) { + ret = -EMSGSIZE ; + goto err_free; + } ret =fill_res_info (msg, device);if (ret)
@@ -1321,7 +1333,7 @@ static int _nldev_res_get_dumpit(struct ib_device *device,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_RES_GET ), 0, NLM_F_MULTI); -if (fill_res_info (skb, device)) { +if (!nlh ||fill_res_info (skb, device)) {nlmsg_cancel (skb, nlh); goto out; }
@@ -1457,7 +1469,7 @@ res_get_common_doit(struct sk_buff *skb, struct nlmsghdr *nlh, RDMA_NL_GET_OP(nlh->nlmsg_type)), 0, 0); -if (fill_nldev_handle (msg, device)) { +if (!nlh ||fill_nldev_handle (msg, device)) { ret = -EMSGSIZE ; goto err_free; }
@@ -1536,7 +1548,7 @@ static int res_get_common_dumpit(struct sk_buff *skb, RDMA_NL_GET_OP(cb->nlh->nlmsg_type)), 0, NLM_F_MULTI); -if (fill_nldev_handle (skb, device)) { +if (!nlh ||fill_nldev_handle (skb, device)) { ret = -EMSGSIZE ; goto err; }
@@ -1798,6 +1810,10 @@ static int nldev_get_chardev(struct sk_buff *skb, struct nlmsghdr *nlh,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_GET_CHARDEV ), 0, 0); +if (!nlh) { + err = -EMSGSIZE ; + goto out_nlmsg; + } data.nl_msg = msg; err =ib_get_client_nl_info (ibdev, client_name, &data);
@@ -1855,6 +1871,10 @@ static int nldev_sys_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_SYS_GET ), 0, 0); +if (!nlh) { +nlmsg_free (msg); +return -EMSGSIZE ; + } err =nla_put_u8 (msg,RDMA_NLDEV_SYS_ATTR_NETNS_MODE , (u8 )ib_devices_shared_netns);
@@ -2040,7 +2060,7 @@ static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_STAT_SET ), 0, 0); -if (fill_nldev_handle (msg, device) || +if (!nlh ||fill_nldev_handle (msg, device) ||nla_put_u32 (msg,RDMA_NLDEV_ATTR_PORT_INDEX , port)) { ret = -EMSGSIZE ; goto err_free_msg;
@@ -2109,6 +2129,10 @@ static int nldev_stat_del_doit(struct sk_buff *skb, struct nlmsghdr *nlh,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_STAT_SET ), 0, 0); +if (!nlh) { + ret = -EMSGSIZE ; + goto err_fill; + } cntn =nla_get_u32 (tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID ]); qpn =nla_get_u32 (tb[RDMA_NLDEV_ATTR_RES_LQPN ]);
@@ -2179,7 +2203,7 @@ stat_get_doit_default_counter(struct sk_buff *skb, struct nlmsghdr *nlh, RDMA_NLDEV_CMD_STAT_GET), 0, 0); -if (fill_nldev_handle (msg, device) || +if (!nlh ||fill_nldev_handle (msg, device) ||nla_put_u32 (msg,RDMA_NLDEV_ATTR_PORT_INDEX , port)) { ret = -EMSGSIZE ; goto err_msg;
@@ -2268,6 +2292,10 @@ stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_STAT_GET ), 0, 0); +if (!nlh) { + ret = -EMSGSIZE ; + goto err_msg; + } ret =rdma_counter_get_mode (device, port, &mode, &mask);if (ret)
@@ -2400,7 +2428,7 @@ static int nldev_stat_get_counter_status_doit(struct sk_buff *skb, 0, 0); ret = -EMSGSIZE ; -if (fill_nldev_handle (msg, device) || +if (!nlh ||fill_nldev_handle (msg, device) ||nla_put_u32 (msg,RDMA_NLDEV_ATTR_PORT_INDEX , port)) goto err_msg;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 683/1191 RDMA/core: Add support to set privileged QKEY parameter
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 465d6b42f1a3b855c06da1d4d3b09907d261af69 ]
Add netlink command that enables/disables privileged QKEY by default.
It is disabled by default, since according to IB spec only privileged users are allowed to use privileged QKEY.
According to the IB specification rel-1.6, section 3.5.3:
"QKEYs with the most significant bit set are considered controlled QKEYs, and a HCA does not allow a consumer to arbitrarily specify a controlled QKEY."
Using rdma tool,
$rdma system set privileged-qkey on
When enabled non-privileged users would be able to use controlled QKEYs which are considered privileged.
Using rdma tool,
$rdma system set privileged-qkey off
When disabled only privileged users would be able to use controlled QKEYs.
You can also use the command below to check the parameter state:
$rdma system show
netns shared privileged-qkey off copy-on-fork on
Stable-dep-of: 709ba0e5311b ("RDMA/core: Fix use after free in ib_query_qp()")
--- drivers/infiniband/core/core_priv.h | 1 + drivers/infiniband/core/nldev.c | 63 ++++++++++++++++++++++++---- drivers/infiniband/core/uverbs_cmd.c | 3 +- include/uapi/rdma/rdma_netlink.h | 2 + 4 files changed, 60 insertions(+), 9 deletions(-)
drivers/infiniband/core/core_priv.h +1 -0
@@ -376,4 +376,5 @@ void rdma_umap_priv_init(struct rdma_umap_priv *priv,void ib_cq_pool_cleanup (struct ib_device *dev); +bool rdma_nl_get_privileged_qkey (void );#endif /* _CORE_PRIV_H */
drivers/infiniband/core/nldev.c +55 -8
103 lines not on this page · raw message
drivers/infiniband/core/uverbs_cmd.c +2 -1
@@ -1859,7 +1859,8 @@ static int modify_qp(struct uverbs_attr_bundle *attrs,if (cmd->base.attr_mask &IB_QP_PATH_MIG_STATE ) attr->path_mig_state = cmd->base.path_mig_state;if (cmd->base.attr_mask &IB_QP_QKEY ) { -if (cmd->base.qkey &IB_QP_SET_QKEY && !capable (CAP_NET_RAW )) { +if (cmd->base.qkey &IB_QP_SET_QKEY && + !rdma_nl_get_privileged_qkey ()) { ret = -EPERM ; goto release_qp; }
include/uapi/rdma/rdma_netlink.h +2 -0
@@ -554,6 +554,8 @@ enum rdma_nldev_attr {RDMA_NLDEV_ATTR_STAT_HWCOUNTER_INDEX ,/* u32 */ RDMA_NLDEV_ATTR_STAT_HWCOUNTER_DYNAMIC ,/* u8 */ + RDMA_NLDEV_SYS_ATTR_PRIVILEGED_QKEY_MODE, /* u8 */ +/* * Always the end */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 684/1191 RDMA/core: Add an option to display driver-specific QPs in the rdmatool
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chiara Meiohas <[email protected]>
[ Upstream commit e18fa0bbcedf82aaa1db27079ef6a43e11367592 ]
Utilize the -dd flag (driver-specific details) in the rdmatool to view driver-specific QPs which are not exposed yet.
Add the netlink attribute to mark request to convey driver details and use it to return QP subtype as a string.
$ rdma resource show qp link ibp8s0f1 link ibp8s0f1/1 lqpn 360 type UD state RTS sq-psn 0 comm [mlx5_ib] link ibp8s0f1/1 lqpn 0 type SMI state RTS sq-psn 0 comm [ib_core] link ibp8s0f1/1 lqpn 1 type GSI state RTS sq-psn 0 comm [ib_core]
$ rdma resource show qp link ibp8s0f1 -dd link ibp8s0f1/1 lqpn 360 type UD state RTS sq-psn 0 comm [mlx5_ib] link ibp8s0f1/1 lqpn 465 type DRIVER subtype REG_UMR state RTS sq-psn 0 comm [mlx5_ib] link ibp8s0f1/1 lqpn 0 type SMI state RTS sq-psn 0 comm [ib_core] link ibp8s0f1/1 lqpn 1 type GSI state RTS sq-psn 0 comm [ib_core]
$ rdma resource show 0: ibp8s0f0: pd 3 cq 4 qp 3 cm_id 0 mr 0 ctx 0 srq 2 1: ibp8s0f1: pd 3 cq 4 qp 3 cm_id 0 mr 0 ctx 0 srq 2
$ rdma resource show -dd 0: ibp8s0f0: pd 3 cq 4 qp 4 cm_id 0 mr 0 ctx 0 srq 2 1: ibp8s0f1: pd 3 cq 4 qp 4 cm_id 0 mr 0 ctx 0 srq 2
Stable-dep-of: 709ba0e5311b ("RDMA/core: Fix use after free in ib_query_qp()")
--- drivers/infiniband/core/nldev.c | 23 +++++++++++++++++++---- drivers/infiniband/core/restrack.c | 12 ++++++++++-- include/rdma/restrack.h | 7 +++++-- include/uapi/rdma/rdma_netlink.h | 6 ++++++ 4 files changed, 40 insertions(+), 8 deletions(-)
drivers/infiniband/core/nldev.c +19 -4
@@ -137,6 +137,8 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = { [RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME]= { .type = NLA_NUL_STRING, .len = RDMA_NLDEV_ATTR_EMPTY_STRING }, [RDMA_NLDEV_ATTR_RES_TYPE] = { .type = NLA_U8 }, + [RDMA_NLDEV_ATTR_RES_SUBTYPE] = { .type = NLA_NUL_STRING, + .len = RDMA_NLDEV_ATTR_EMPTY_STRING }, [RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]= { .type = NLA_U32 }, [RDMA_NLDEV_ATTR_RES_USECNT] = { .type = NLA_U64 }, [RDMA_NLDEV_ATTR_RES_SRQ] = { .type = NLA_NESTED },
@@ -164,6 +166,7 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = { [RDMA_NLDEV_ATTR_STAT_HWCOUNTER_INDEX] = { .type = NLA_U32 }, [RDMA_NLDEV_ATTR_STAT_HWCOUNTER_DYNAMIC] = { .type = NLA_U8 }, [RDMA_NLDEV_SYS_ATTR_PRIVILEGED_QKEY_MODE] = { .type = NLA_U8 }, + [RDMA_NLDEV_ATTR_DRIVER_DETAILS] = { .type = NLA_U8 }, }; static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
@@ -400,7 +403,8 @@ static int fill_res_info_entry(struct sk_buff *msg,return -EMSGSIZE ; } -static int fill_res_info (struct sk_buff *msg,struct ib_device *device) +static int fill_res_info (struct sk_buff *msg,struct ib_device *device, +bool show_details) {static const char *const names[RDMA_RESTRACK_MAX ] = { [RDMA_RESTRACK_PD ] ="pd" ,
@@ -425,7 +429,7 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)for (i =0 ; i <RDMA_RESTRACK_MAX ; i++) {if (!names[i])continue ; - curr =rdma_restrack_count (device, i); + curr =rdma_restrack_count (device, i, show_details); ret =fill_res_info_entry (msg, names[i], curr);if (ret) goto err;
@@ -1288,6 +1292,7 @@ static int nldev_res_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ]; +bool show_details = false;struct ib_device *device;struct sk_buff *msg;u32 index;
@@ -1303,6 +1308,9 @@ static int nldev_res_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,if (!device)return -EINVAL ; +if (tb[RDMA_NLDEV_ATTR_DRIVER_DETAILS ]) + show_details =nla_get_u8 (tb[RDMA_NLDEV_ATTR_DRIVER_DETAILS ]); + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL );if (!msg) { ret = -ENOMEM ;
@@ -1317,7 +1325,7 @@ static int nldev_res_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, goto err_free; } - ret =fill_res_info (msg, device); + ret =fill_res_info (msg, device, show_details);if (ret) goto err_free;
@@ -1347,7 +1355,7 @@ static int _nldev_res_get_dumpit(struct ib_device *device,RDMA_NL_GET_TYPE (RDMA_NL_NLDEV ,RDMA_NLDEV_CMD_RES_GET ), 0, NLM_F_MULTI); -if (!nlh ||fill_res_info (skb, device)) { +if (!nlh ||fill_res_info (skb, device, false)) {nlmsg_cancel (skb, nlh); goto out; }
@@ -1518,6 +1526,7 @@ static int res_get_common_dumpit(struct sk_buff *skb,struct rdma_restrack_entry *res;struct rdma_restrack_root *rt;int err, ret =0 , idx =0 ; +bool show_details = false;struct nlattr *table_attr;struct nlattr *entry_attr;struct ib_device *device;
@@ -1546,6 +1555,9 @@ static int res_get_common_dumpit(struct sk_buff *skb,if (!device)return -EINVAL ; +if (tb[RDMA_NLDEV_ATTR_DRIVER_DETAILS ]) + show_details =nla_get_u8 (tb[RDMA_NLDEV_ATTR_DRIVER_DETAILS ]); +/* * If no PORT_INDEX is supplied, we will return all QPs from that device */
@@ -1583,6 +1595,9 @@ static int res_get_common_dumpit(struct sk_buff *skb,* objects. */ xa_for_each (&rt->xa, id, res) { +if (xa_get_mark (&rt->xa, res->id,RESTRACK_DD ) && !show_details) + goto next; +if (idx < start || !rdma_restrack_get (res)) goto next;
drivers/infiniband/core/restrack.c +10 -2
@@ -59,8 +59,10 @@ void rdma_restrack_clean(struct ib_device *dev)* rdma_restrack_count() - the current usage of specific object * @dev: IB device * @type: actual type of object to operate +* @show_details: count driver specific objects */ -int rdma_restrack_count (struct ib_device *dev,enum rdma_restrack_type type) +int rdma_restrack_count (struct ib_device *dev,enum rdma_restrack_type type, +bool show_details) {struct rdma_restrack_root *rt = &dev->res[type];struct rdma_restrack_entry *e;
@@ -68,8 +70,11 @@ int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type)u32 cnt =0 ;xa_lock (&rt->xa); -xas_for_each (&xas, e,U32_MAX ) +xas_for_each (&xas, e,U32_MAX ) { +if (xa_get_mark (&rt->xa, e->id,RESTRACK_DD ) && !show_details) +continue ; cnt++; + }xa_unlock (&rt->xa);return cnt; }
@@ -198,6 +203,9 @@ void rdma_restrack_add(struct rdma_restrack_entry *res) ret =xa_insert (&rt->xa, res->id, res,GFP_KERNEL );if (ret) res->id =0 ; + +if (qp->qp_type >=IB_QPT_DRIVER ) +xa_set_mark (&rt->xa, res->id,RESTRACK_DD ); }else if (res->type ==RDMA_RESTRACK_COUNTER ) {/* Special case to ensure that cntn points to right counter */ struct rdma_counter *counter;
include/rdma/restrack.h +5 -2
@@ -14,6 +14,9 @@#include <uapi/rdma/rdma_netlink.h> #include <linux/xarray.h> +/* Mark entry as containing driver specific details, it is used to provide QP subtype for now */ +#define RESTRACK_DD XA_MARK_1 +struct ib_device ;struct sk_buff ;
@@ -116,8 +119,8 @@ struct rdma_restrack_entry {u32 id; }; -int rdma_restrack_count (struct ib_device *dev, -enum rdma_restrack_type type); +int rdma_restrack_count (struct ib_device *dev,enum rdma_restrack_type type, +bool show_details);/** * rdma_is_kernel_res() - check the owner of resource * @res: resource entry
include/uapi/rdma/rdma_netlink.h +6 -0
@@ -556,6 +556,12 @@ enum rdma_nldev_attr {RDMA_NLDEV_SYS_ATTR_PRIVILEGED_QKEY_MODE ,/* u8 */ +RDMA_NLDEV_ATTR_DRIVER_DETAILS ,/* u8 */ +/* +* QP subtype string, used for driver QPs +*/ + RDMA_NLDEV_ATTR_RES_SUBTYPE, /* string */ +/* * Always the end */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 685/1191 RDMA/restrack: Fix typos in the comments
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kalesh AP <[email protected]>
[ Upstream commit d43358cda7c4696e08880aaa58a7df82e471fa7c ]
Fix couple of occurrences of the misspelled word "reource" in the comments with the correct spelling "resource".
Stable-dep-of: 709ba0e5311b ("RDMA/core: Fix use after free in ib_query_qp()")
--- drivers/infiniband/core/restrack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/core/restrack.c +2 -2
@@ -173,7 +173,7 @@ void rdma_restrack_new(struct rdma_restrack_entry *res,EXPORT_SYMBOL (rdma_restrack_new);/** -* rdma_restrack_add() - add object to the reource tracking database +* rdma_restrack_add() - add object to the resource tracking database * @res: resource entry */ void rdma_restrack_add (struct rdma_restrack_entry *res)
@@ -275,7 +275,7 @@ int rdma_restrack_put(struct rdma_restrack_entry *res)EXPORT_SYMBOL (rdma_restrack_put);/** -* rdma_restrack_del() - delete object from the reource tracking database +* rdma_restrack_del() - delete object from the resource tracking database * @res: resource entry */ void rdma_restrack_del (struct rdma_restrack_entry *res)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 686/1191 RDMA/nldev: Fix locking when accessing mr->pd
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Gunthorpe <[email protected]>
[ Upstream commit 50d5c02ab8e62325548bd3a6e6b758a9dcd6e7c3 ]
Sashiko points out that, due to rereg_mr, the PD is actually variable and all the touches in nldev are racy.
Use mr->device instead of mr->pd->device.
Getting the PD restrack ID is more tricky. To avoid disturbing all the happy paths, add an rdma_restrack_sync() operation which is sort of like flush_workqueue() or synchronize_irq(): after it returns, all the old nldev touches to the mr are gone and everything sees the new PD. This makes it safe to reach into the PD pointer.
Stable-dep-of: 709ba0e5311b ("RDMA/core: Fix use after free in ib_query_qp()")
--- drivers/infiniband/core/nldev.c | 15 +++++---- drivers/infiniband/core/restrack.c | 49 ++++++++++++++++++++++++++++ drivers/infiniband/core/restrack.h | 1 + drivers/infiniband/core/uverbs_cmd.c | 10 ++++-- include/rdma/ib_verbs.h | 5 +++ 5 files changed, 72 insertions(+), 8 deletions(-)
drivers/infiniband/core/nldev.c +9 -6
@@ -662,7 +662,7 @@ static int fill_res_mr_entry(struct sk_buff *msg, bool has_cap_net_admin, struct rdma_restrack_entry *res, uint32_t port) { struct ib_mr *mr = container_of(res, struct ib_mr, res); -struct ib_device *dev = mr->pd->device; +struct ib_device *dev = mr->device;if (has_cap_net_admin) {if (nla_put_u32 (msg,RDMA_NLDEV_ATTR_RES_RKEY , mr->rkey))
@@ -678,9 +678,12 @@ static int fill_res_mr_entry(struct sk_buff *msg, bool has_cap_net_admin,if (nla_put_u32 (msg,RDMA_NLDEV_ATTR_RES_MRN , res->id))return -EMSGSIZE ; -if (!rdma_is_kernel_res (res) && -nla_put_u32 (msg,RDMA_NLDEV_ATTR_RES_PDN , mr->pd->res.id)) -return -EMSGSIZE ; +if (!rdma_is_kernel_res (res)) { +struct ib_pd *pd =READ_ONCE (mr->pd); + +if (nla_put_u32 (msg,RDMA_NLDEV_ATTR_RES_PDN , pd->res.id)) +return -EMSGSIZE ; + }if (fill_res_name_pid (msg, res))return -EMSGSIZE ;
@@ -694,7 +697,7 @@ static int fill_res_mr_raw_entry(struct sk_buff *msg, bool has_cap_net_admin, struct rdma_restrack_entry *res, uint32_t port) { struct ib_mr *mr = container_of(res, struct ib_mr, res); -struct ib_device *dev = mr->pd->device; +struct ib_device *dev = mr->device;if (!dev->ops.fill_res_mr_entry_raw)return -EINVAL ;
@@ -966,7 +969,7 @@ static int fill_stat_mr_entry(struct sk_buff *msg, bool has_cap_net_admin, struct rdma_restrack_entry *res, uint32_t port) { struct ib_mr *mr = container_of(res, struct ib_mr, res); -struct ib_device *dev = mr->pd->device; +struct ib_device *dev = mr->device;if (nla_put_u32 (msg,RDMA_NLDEV_ATTR_RES_MRN , res->id)) goto err;
drivers/infiniband/core/restrack.c +49 -0
61 lines not on this page · raw message
drivers/infiniband/core/restrack.h +1 -0
@@ -27,6 +27,7 @@ int rdma_restrack_init(struct ib_device *dev);void rdma_restrack_clean (struct ib_device *dev);void rdma_restrack_add (struct rdma_restrack_entry *res);void rdma_restrack_del (struct rdma_restrack_entry *res); +void rdma_restrack_sync (struct rdma_restrack_entry *res);void rdma_restrack_new (struct rdma_restrack_entry *res,enum rdma_restrack_type type); void rdma_restrack_set_name(struct rdma_restrack_entry *res,
drivers/infiniband/core/uverbs_cmd.c +8 -2
@@ -46,6 +46,7 @@#include "uverbs.h" #include "core_priv.h" +#include "restrack.h" /* * Copy a response to userspace. If the provided 'resp' is larger than the
@@ -813,6 +814,10 @@ static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs) ret =PTR_ERR (new_pd); goto put_uobjs; } +if (new_pd == orig_pd) { +uobj_put_obj_read (new_pd); + cmd.flags &= ~IB_MR_REREG_PD ; + } }else { new_pd = mr->pd; }
@@ -858,9 +863,10 @@ static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs) mr = new_mr; }else {if (cmd.flags &IB_MR_REREG_PD ) { -atomic_dec (&orig_pd->usecnt); - mr->pd = new_pd;atomic_inc (&new_pd->usecnt); +WRITE_ONCE (mr->pd, new_pd); +rdma_restrack_sync (&mr->res); +atomic_dec (&orig_pd->usecnt); }if (cmd.flags &IB_MR_REREG_TRANS ) { mr->iova = cmd.hca_va;
include/rdma/ib_verbs.h +5 -0
@@ -1817,6 +1817,11 @@ struct ib_dm {struct ib_mr {struct ib_device *device; +/* +* Due to IB_MR_REREG_PD pd is not a fixed pointer and can change. For a +* user MR, this value should only be read from a system call that holds +* the uobject lock, or the driver should disable in-place REREG_PD. +*/ struct ib_pd *pd;u32 lkey;u32 rkey;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 687/1191 RDMA/core: Add rdma_restrack_begin/abort/commit_del() operations
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 8d186210677c0322db886973bcec9aa4d21b51cd ]
Add rdma_restrack_abort_del(), rdma_restrack_begin_del() and rdma_restrack_commit_del() functions to allow deleting a resource from the xarray to effectively prevent future access to it and wait for all current users to finish while preserving its index in the xarray to allow to re-insert it if needed with guaranteed success.
This is a preparatory change for subsequent patches in the series which will use these functions to fix the cleanup flow.
Stable-dep-of: 709ba0e5311b ("RDMA/core: Fix use after free in ib_query_qp()")
--- drivers/infiniband/core/restrack.c | 165 +++++++++++++++++++++++------ drivers/infiniband/core/restrack.h | 3 + 2 files changed, 135 insertions(+), 33 deletions(-)
drivers/infiniband/core/restrack.c +132 -33
@@ -127,6 +127,46 @@ static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, res->user = true; } +static struct rdma_restrack_root *res_to_rt (struct rdma_restrack_entry *res) +{ +struct ib_device *dev =res_to_dev (res); + +if (WARN_ON (!dev)) +return NULL ; + +return &dev->res[res->type]; +} + +static void restrack_drain_res (struct rdma_restrack_root *rt, +struct rdma_restrack_entry *res) +{ +if (rt) { +struct rdma_restrack_entry *old; + + old =xa_cmpxchg (&rt->xa, res->id, res,XA_ZERO_ENTRY , +GFP_KERNEL ); +WARN_ON (old != res); + } + +rdma_restrack_put (res); +wait_for_completion (&res->comp); +} + +static void restrack_restore_res (struct rdma_restrack_root *rt, +struct rdma_restrack_entry *res) +{ +reinit_completion (&res->comp); +kref_init (&res->kref); + +if (rt) { +struct rdma_restrack_entry *old; + + old =xa_cmpxchg (&rt->xa, res->id,XA_ZERO_ENTRY , res, +GFP_KERNEL ); +WARN_ON (old); + } +} +/** * rdma_restrack_set_name() - set the task for this resource * @res: resource entry
@@ -175,22 +215,23 @@ void rdma_restrack_new(struct rdma_restrack_entry *res,EXPORT_SYMBOL (rdma_restrack_new);/** -* rdma_restrack_add() - add object to the resource tracking database +* rdma_restrack_add() - add object to the resource tracking database. +* If this resource reuses an ID of a resource that was already destroyed +* after calling rdma_restrack_begin() but didn't yet call +* rdma_restrack_commit_del() it can result in an untracked QP. * @res: resource entry */ void rdma_restrack_add (struct rdma_restrack_entry *res) { -struct ib_device *dev =res_to_dev (res);struct rdma_restrack_root *rt;int ret =0 ; -if (!dev) -return ; -if (res->no_track) goto out; - rt = &dev->res[res->type]; + rt =res_to_rt (res); +if (!rt) +return ;if (res->type ==RDMA_RESTRACK_QP ) {/* Special case to ensure that LQPN points to right QP */
@@ -227,6 +268,28 @@ void rdma_restrack_add(struct rdma_restrack_entry *res) }EXPORT_SYMBOL (rdma_restrack_add); +/** +* rdma_restrack_abort_del() - re-add object to the resource tracking database +* it can only be used after rdma_restrack_begin_del(). +* @res: resource entry +*/ +void rdma_restrack_abort_del (struct rdma_restrack_entry *res) +{ +struct rdma_restrack_root *rt =NULL ; + +if (!res->valid) +return ; + +if (!res->no_track) { + rt =res_to_rt (res); +if (!rt) +return ; + } + +restrack_restore_res (rt, res); +} +EXPORT_SYMBOL (rdma_restrack_abort_del); +int __must_check rdma_restrack_get (struct rdma_restrack_entry *res) {return kref_get_unless_zero (&res->kref);
@@ -263,7 +326,7 @@ static void restrack_release(struct kref *kref)struct rdma_restrack_entry *res; res = container_of(kref, struct rdma_restrack_entry, kref); -if (res->task) { +if (res->task && !res->valid) {put_task_struct (res->task); res->task =NULL ; }
@@ -289,37 +352,20 @@ EXPORT_SYMBOL(rdma_restrack_put);*/ void rdma_restrack_sync (struct rdma_restrack_entry *res) { -struct rdma_restrack_entry *old;struct rdma_restrack_root *rt; -struct task_struct *task; -struct ib_device *dev;if (!res->valid || res->no_track)return ; - dev =res_to_dev (res); -if (WARN_ON (!dev)) + rt =res_to_rt (res); +if (!rt)return ; - rt = &dev->res[res->type];if (WARN_ON (xa_get_mark (&rt->xa, res->id,RESTRACK_DD )))return ; - old =xa_cmpxchg (&rt->xa, res->id, res,XA_ZERO_ENTRY ,GFP_KERNEL ); -if (WARN_ON (old != res)) -return ; - - task = res->task; -if (task) -get_task_struct (task); -rdma_restrack_put (res); -wait_for_completion (&res->comp); -reinit_completion (&res->comp); -if (task) - res->task = task; -kref_init (&res->kref); - -xa_cmpxchg (&rt->xa, res->id,XA_ZERO_ENTRY , res,GFP_KERNEL ); +restrack_drain_res (rt, res); +restrack_restore_res (rt, res); }EXPORT_SYMBOL (rdma_restrack_sync);
@@ -331,7 +377,6 @@ void rdma_restrack_del(struct rdma_restrack_entry *res) {struct rdma_restrack_entry *old;struct rdma_restrack_root *rt; -struct ib_device *dev;if (!res->valid) {if (res->task) {
@@ -344,12 +389,10 @@ void rdma_restrack_del(struct rdma_restrack_entry *res)if (res->no_track) goto out; - dev =res_to_dev (res); -if (WARN_ON (!dev)) + rt =res_to_rt (res); +if (!rt)return ; - rt = &dev->res[res->type]; - old =xa_erase (&rt->xa, res->id);WARN_ON (old != res);
@@ -357,5 +400,61 @@ void rdma_restrack_del(struct rdma_restrack_entry *res) res->valid = false;rdma_restrack_put (res);wait_for_completion (&res->comp); +if (res->task) { +put_task_struct (res->task); + res->task =NULL ; + } }EXPORT_SYMBOL (rdma_restrack_del); + +/** +* rdma_restrack_begin_del() - invalidate the object from the resource tracking +* database but preserve its index in the array. +* Since this preserves the index in the array until rdma_restrack_commit_del() +* is called, if rdma_restrack_add() is called in between with an old QP ID it +* can result in an untracked QP. +* @res: resource entry +*/ +void rdma_restrack_begin_del (struct rdma_restrack_entry *res) +{ +struct rdma_restrack_root *rt =NULL ; + +if (!res->valid) +return ; + +if (!res->no_track) { + rt =res_to_rt (res); +if (!rt) +return ; + } + +restrack_drain_res (rt, res); +} +EXPORT_SYMBOL (rdma_restrack_begin_del); + +/** +* rdma_restrack_commit_del() - delete object from the resource tracking +* database and free the task. +* @res: resource entry +*/ +void rdma_restrack_commit_del (struct rdma_restrack_entry *res) +{ +struct rdma_restrack_root *rt; + +if (!res->valid || res->no_track) + goto out; + + rt =res_to_rt (res); +if (!rt) +return ; + +xa_erase (&rt->xa, res->id); + +out: + res->valid = false; +if (res->task) { +put_task_struct (res->task); + res->task =NULL ; + } +} +EXPORT_SYMBOL (rdma_restrack_commit_del);
drivers/infiniband/core/restrack.h +3 -0
@@ -26,8 +26,11 @@ struct rdma_restrack_root {int rdma_restrack_init (struct ib_device *dev);void rdma_restrack_clean (struct ib_device *dev);void rdma_restrack_add (struct rdma_restrack_entry *res); +void rdma_restrack_abort_del (struct rdma_restrack_entry *res);void rdma_restrack_del (struct rdma_restrack_entry *res);void rdma_restrack_sync (struct rdma_restrack_entry *res); +void rdma_restrack_begin_del (struct rdma_restrack_entry *res); +void rdma_restrack_commit_del (struct rdma_restrack_entry *res);void rdma_restrack_new (struct rdma_restrack_entry *res,enum rdma_restrack_type type); void rdma_restrack_set_name(struct rdma_restrack_entry *res,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 688/1191 RDMA/core: Fix use after free in ib_query_qp()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 709ba0e5311bd034eb4d9c1c00cc4e1109d6dc3e ]
When querying a QP via the netlink flow the only synchronization mechanism for the said QP is rdma_restrack_get(), meanwhile during the QP destroy path rdma_restrack_del() is called at the end of the ib_destroy_qp_user() function which is too late, since by then the vendor specific resources for said QP would already be destroyed, and till the rdma_restrack_del() is called this QP can still be accessed, which could cause the use after free below.
Fix this by moving the rdma_restrack_begin_del() to the start of the ib_destroy_qp_user(), which in turn waits for all usages of the QP to be done then removes it from the database to prevent access to it while it is being destroyed.
RIP: 0010:ib_query_qp+0x15/0x50 [ib_core] Code: 48 83 05 5d 8e b9 ff 01 eb b5 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 c7 46 40 00 00 00 00 48 c7 46 78 00 00 00 00 <48> 8b 07 48 8b 80 88 01 00 00 48 85 c0 74 1a 48 83 05 54 91 b9 ff RSP: 0018:ff11000108a8f2f0 EFLAGS: 00010202 RAX: 0000000000000000 RBX: ff11000108a8f370 RCX: ff11000108a8f370 RDX: 0000000000000000 RSI: ff11000108a8f3d8 RDI: 0000000000000000 RBP: ff1100010de5a000 R08: 0000000000000e80 R09: 0000000000000004 R10: ff110001057a604c R11: 0000000000000000 R12: ff11000108a8f370 R13: ff110001090e8000 R14: 0000000000000000 R15: ff110001057a602c FS: 00007f2ffd8db6c0(0000) GS:ff110008dc90b000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 000000010b9a7004 CR4: 0000000000373eb0 Call Trace: <TASK> mlx5_ib_gsi_query_qp+0x21/0x50 [mlx5_ib] mlx5_ib_query_qp+0x689/0x9d0 [mlx5_ib] ib_query_qp+0x35/0x50 [ib_core] fill_res_qp_entry_query.isra.0+0x47/0x280 [ib_core] ? __wake_up+0x40/0x50 ? netlink_broadcast_filtered+0x15a/0x550 ? kobject_uevent_env+0x562/0x710 ? ep_poll_callback+0x242/0x270 ? __nla_put+0xc/0x20 ? nla_put+0x28/0x40 ? nla_put_string+0x2e/0x40 [ib_core] fill_res_qp_entry+0x138/0x190 [ib_core] res_get_common_dumpit+0x4a5/0x800 [ib_core] ? fill_res_qp_entry_query.isra.0+0x280/0x280 [ib_core] nldev_res_get_qp_dumpit+0x1e/0x30 [ib_core] netlink_dump+0x16f/0x450 __netlink_dump_start+0x1ce/0x2e0 rdma_nl_rcv_msg+0x1d3/0x330 [ib_core] ? nldev_res_get_qp_raw_dumpit+0x30/0x30 [ib_core] rdma_nl_rcv_skb.constprop.0.isra.0+0x108/0x180 [ib_core] rdma_nl_rcv+0x12/0x20 [ib_core] netlink_unicast+0x255/0x380 ? __alloc_skb+0xfa/0x1e0 netlink_sendmsg+0x1f3/0x420 __sock_sendmsg+0x38/0x60 ____sys_sendmsg+0x1e8/0x230 ? copy_msghdr_from_user+0xea/0x170 ___sys_sendmsg+0x7c/0xb0 ? __futex_wait+0x95/0xf0 ? __futex_wake_mark+0x40/0x40 ? futex_wait+0x67/0x100 ? futex_wake+0xac/0x1b0 __sys_sendmsg+0x5f/0xb0 do_syscall_64+0x55/0xb90 entry_SYSCALL_64_after_hwframe+0x4b/0x53
--- drivers/infiniband/core/verbs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/core/verbs.c +4 -1
@@ -2016,6 +2016,8 @@ int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata)if (qp->real_qp != qp)return __ib_destroy_shared_qp (qp); +rdma_restrack_begin_del (&qp->res); + sec = qp->qp_sec;if (sec)ib_destroy_qp_security_begin (sec);
@@ -2028,6 +2030,7 @@ int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata)if (ret) {if (sec)ib_destroy_qp_security_abort (sec); +rdma_restrack_abort_del (&qp->res);return ret; }
@@ -2040,7 +2043,7 @@ int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata)if (sec)ib_destroy_qp_security_end (sec); -rdma_restrack_del (&qp->res); +rdma_restrack_commit_del (&qp->res);kfree (qp);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 689/1191 RDMA/core: Fix potential use after free in ib_destroy_cq_user()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 3481bec4dfc4aee24ffea5a547ee95b70b67d9d5 ]
When accessing a CQ via the netlink path the only synchronization mechanism for the said CQ is rdma_restrack_get(). Currently, rdma_restrack_del() is invoked at the end of ib_destroy_cq_user(), which is too late, since by that point vendor-specific resources associated with the CQ might already be freed. This can leave a short window where the CQ remains accessible through restrack, leading to a potential use-after-free.
Fix this by moving the rdma_restrack_begin_del() call to the start of ib_destroy_cq_user(), ensuring that the CQ is removed from restrack before its internal resources are released. This guarantees that no new users hold references to a CQ that is in the process of destruction.
In addition, this change preserves the intended inverted order between create and destroy routines: resources are added to restrack at the end of successful creation, and hence shall be removed from the restrack first thing during the destruction flow, which keeps the lifecycle management consistent and predictable.
--- drivers/infiniband/core/verbs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c +6 -2
@@ -2108,11 +2108,15 @@ int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata)if (atomic_read (&cq->usecnt))return -EBUSY ; +rdma_restrack_begin_del (&cq->res); + ret = cq->device->ops.destroy_cq (cq, udata); -if (ret) +if (ret) { +rdma_restrack_abort_del (&cq->res);return ret; + } -rdma_restrack_del (&cq->res); +rdma_restrack_commit_del (&cq->res);kfree (cq);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 690/1191 RDMA/core: Fix potential use after free in ib_destroy_srq_user()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 88244ecc71cc0b3ed200f5ef7ddea6686adfd730 ]
When accessing a SRQ via the netlink path the only synchronization mechanism for the said SRQ is rdma_restrack_get(). Currently, rdma_restrack_del() is invoked at the end of ib_destroy_srq_user(), which is too late, since by that point vendor-specific resources associated with the SRQ might already be freed. This can leave a short window where the SRQ remains accessible through restrack, leading to a potential use-after-free.
Fix this by moving the rdma_restrack_begin_del() call to the start of ib_destroy_srq_user(), ensuring that the SRQ is removed from restrack before its internal resources are released. This guarantees that no new users hold references to a SRQ that is in the process of destruction.
In addition, this change preserves the intended inverted order between create and destroy routines: resources are added to restrack at the end of successful creation, and hence shall be removed from the restrack first thing during the destruction flow, which keeps the lifecycle management consistent and predictable.
--- drivers/infiniband/core/verbs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c +6 -2
@@ -1080,16 +1080,20 @@ int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata)if (atomic_read (&srq->usecnt))return -EBUSY ; +rdma_restrack_begin_del (&srq->res); + ret = srq->device->ops.destroy_srq (srq, udata); -if (ret) +if (ret) { +rdma_restrack_abort_del (&srq->res);return ret; + }atomic_dec (&srq->pd->usecnt);if (srq->srq_type ==IB_SRQT_XRC && srq->ext.xrc.xrcd)atomic_dec (&srq->ext.xrc.xrcd->usecnt);if (ib_srq_has_cq (srq->srq_type))atomic_dec (&srq->ext.cq->usecnt); -rdma_restrack_del (&srq->res); +rdma_restrack_commit_del (&srq->res);kfree (srq);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 691/1191 RDMA/core: Fix potential use after free in counter_release()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 235ef2d0e750885c29340b0fc40620a7a4f52e12 ]
When accessing a counter via the netlink path the only synchronization mechanism for the said counter is rdma_restrack_get(). Currently, rdma_restrack_del() is invoked at the end of counter_release(), which is too late, since by that point vendor-specific resources associated with the counter might already be freed. This can leave a short window where the counter remains accessible through restrack, leading to a potential use-after-free.
Fix this by moving the rdma_restrack_del() call to be before the freeing of the vendor-specific resources, ensuring that the counter is removed from restrack before its internal resources are released. This guarantees that no new users hold references to a counter that is in the process of destruction.
--- drivers/infiniband/core/counters.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/core/counters.c +3 -2
@@ -217,7 +217,6 @@ static void rdma_counter_free(struct rdma_counter *counter)mutex_unlock (&port_counter->lock); -rdma_restrack_del (&counter->res);rdma_free_hw_stats_struct (counter->stats);kfree (counter); }
@@ -312,6 +311,7 @@ static void counter_release(struct kref *kref) counter = container_of(kref, struct rdma_counter, kref);counter_history_stat_update (counter); +rdma_restrack_del (&counter->res); counter->device->ops.counter_dealloc (counter);rdma_counter_free (counter); }
@@ -472,7 +472,8 @@ static struct rdma_counter *rdma_get_counter_by_id(struct ib_device *dev,return NULL ; counter = container_of(res, struct rdma_counter, res); -kref_get (&counter->kref); +if (!kref_get_unless_zero (&counter->kref)) + counter =NULL ;rdma_restrack_put (res);return counter;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 692/1191 RDMA/core: Add driver APIs pre_destroy_cq() and post_destroy_cq()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Zhang <[email protected]>
[ Upstream commit 5a2a5b65d5d67279be9e1f0e4b9baf39ee594cb1 ]
Currently in ib_free_cq, it disables IRQ or cancel the CQ work before driver destroy_cq. This isn't good as a new IRQ or a CQ work can be submitted immediately after disabling IRQ or canceling CQ work, which may run concurrently with destroy_cq and cause crashes.
The right flow should be:
1. Driver disables CQ to make sure no new CQ event will be submitted;
2. Disables IRQ or Cancels CQ work in core layer, to make sure no CQ
polling work is running;
3. Free all resources to destroy the CQ.
This patch adds 2 driver APIs:
- pre_destroy_cq(): Disable a CQ to prevent it from generating any new work completions, but not free any kernel resources;
- post_destroy_cq(): Free all kernel resources.
In ib_free_cq, the IRQ is disabled or CQ work is canceled after pre_destroy_cq, and before post_destroy_cq.
Stable-dep-of: 29dc2f8e1c97 ("RDMA/core: Fix potential use after free in ib_free_cq()")
--- drivers/infiniband/core/cq.c | 12 ++++++++++-- drivers/infiniband/core/device.c | 2 ++ include/rdma/ib_verbs.h | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-)
drivers/infiniband/core/cq.c +10 -2
@@ -317,13 +317,18 @@ EXPORT_SYMBOL(__ib_alloc_cq_any);*/ void ib_free_cq (struct ib_cq *cq) { -int ret; +int ret =0 ;if (WARN_ON_ONCE (atomic_read (&cq->usecnt)))return ;if (WARN_ON_ONCE (cq->cqe_used))return ; +if (cq->device->ops.pre_destroy_cq) { + ret = cq->device->ops.pre_destroy_cq (cq); +WARN_ONCE (ret,"Disable of kernel CQ shouldn't fail" ); + } +switch (cq->poll_ctx) {case IB_POLL_DIRECT :break ;
@@ -340,7 +345,10 @@ void ib_free_cq(struct ib_cq *cq)rdma_dim_destroy (cq);trace_cq_free (cq); - ret = cq->device->ops.destroy_cq (cq,NULL ); +if (cq->device->ops.post_destroy_cq) + cq->device->ops.post_destroy_cq (cq); +else + ret = cq->device->ops.destroy_cq (cq,NULL );WARN_ONCE (ret,"Destroy of kernel CQ shouldn't fail" );rdma_restrack_del (&cq->res);kfree (cq->wc);
drivers/infiniband/core/device.c +2 -0
@@ -2735,8 +2735,10 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)SET_DEVICE_OP (dev_ops, modify_srq);SET_DEVICE_OP (dev_ops, modify_wq);SET_DEVICE_OP (dev_ops, peek_cq); +SET_DEVICE_OP (dev_ops, pre_destroy_cq);SET_DEVICE_OP (dev_ops, poll_cq);SET_DEVICE_OP (dev_ops, port_groups); +SET_DEVICE_OP (dev_ops, post_destroy_cq);SET_DEVICE_OP (dev_ops, post_recv);SET_DEVICE_OP (dev_ops, post_send);SET_DEVICE_OP (dev_ops, post_srq_recv);
include/rdma/ib_verbs.h +9 -0
@@ -2476,6 +2476,15 @@ struct ib_device_ops {int (*modify_cq)(struct ib_cq *cq,u16 cq_count,u16 cq_period);int (*destroy_cq)(struct ib_cq *cq,struct ib_udata *udata);int (*resize_cq)(struct ib_cq *cq,int cqe,struct ib_udata *udata); +/** +* pre_destroy_cq - Prevent a cq from generating any new work +* completions, but not free any kernel resources +*/ +int (*pre_destroy_cq)(struct ib_cq *cq); +/** +* post_destroy_cq - Free all kernel resources +*/ +void (*post_destroy_cq)(struct ib_cq *cq);struct ib_mr *(*get_dma_mr)(struct ib_pd *pd,int mr_access_flags); struct ib_mr *(*reg_user_mr)(struct ib_pd *pd, u64 start, u64 length, u64 virt_addr, int mr_access_flags,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 693/1191 RDMA/core: Fix potential use after free in ib_free_cq()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 29dc2f8e1c97372c2871a70088707933515fbd5b ]
When accessing a CQ via the netlink path the only synchronization mechanism for the said CQ is rdma_restrack_get(). Currently, rdma_restrack_del() is invoked at the end of ib_free_cq(), which is too late, since by that point vendor-specific resources associated with the CQ might already be freed. This can leave a short window where the CQ remains accessible through restrack, leading to a potential use-after-free.
Fix this by moving the rdma_restrack_del() call to be before the freeing of the vendor-specific resources ensuring that the CQ is removed from restrack before its internal resources are released.
This guarantees that no new users hold references to a CQ that is in the process of destruction.
--- drivers/infiniband/core/cq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/cq.c +1 -1
@@ -324,6 +324,7 @@ void ib_free_cq(struct ib_cq *cq)if (WARN_ON_ONCE (cq->cqe_used))return ; +rdma_restrack_del (&cq->res);if (cq->device->ops.pre_destroy_cq) { ret = cq->device->ops.pre_destroy_cq (cq);WARN_ONCE (ret,"Disable of kernel CQ shouldn't fail" );
@@ -350,7 +351,6 @@ void ib_free_cq(struct ib_cq *cq)else ret = cq->device->ops.destroy_cq (cq,NULL );WARN_ONCE (ret,"Destroy of kernel CQ shouldn't fail" ); -rdma_restrack_del (&cq->res);kfree (cq->wc);kfree (cq); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 694/1191 RDMA/core: Fix potential use after free in ib_dealloc_pd_user()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patrisious Haddad <[email protected]>
[ Upstream commit 8b90e701342275f414e36e7421c502237df241ad ]
When accessing a PD via the netlink path the only synchronization mechanism for the said PD is rdma_restrack_get(). Currently, rdma_restrack_del() is invoked at the end of ib_dealloc_pd_user(), which is too late, since by that point vendor-specific resources associated with the PD might already be freed. This can leave a short window where the PD remains accessible through restrack, leading to a potential use-after-free.
Fix this by moving the rdma_restrack_begin_del() call to the start of ib_dealloc_pd_user(), ensuring that the PD is removed from restrack before its internal resources are released. This guarantees that no new users hold references to a PD that is in the process of destruction.
In addition, this change preserves the intended inverted order between create and destroy routines: resources are added to restrack at the end of successful creation, and hence shall be removed from the restrack first thing during the destruction flow, which keeps the lifecycle management consistent and predictable.
--- drivers/infiniband/core/verbs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/infiniband/core/verbs.c +5 -2
@@ -332,6 +332,7 @@ int ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata) {int ret; +rdma_restrack_begin_del (&pd->res);if (pd->__internal_mr) { ret = pd->device->ops.dereg_mr (pd->__internal_mr,NULL );WARN_ON (ret);
@@ -339,10 +340,12 @@ int ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata) } ret = pd->device->ops.dealloc_pd (pd, udata); -if (ret) +if (ret) { +rdma_restrack_abort_del (&pd->res);return ret; + } -rdma_restrack_del (&pd->res); +rdma_restrack_commit_del (&pd->res);kfree (pd);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 695/1191 iommu/qcom: Remove sysfs device on probe failure path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
[ Upstream commit c579f18e79599c16168925cb149e1db3f29eea5f ]
In qcom_iommu_device_probe(), if iommu_device_register() fails, the sysfs device created by iommu_device_sysfs_add() is not released. Add a goto label to do the cleanup.
--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +3 -1
@@ -847,7 +847,7 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) ret =iommu_device_register (&qcom_iommu->iommu, &qcom_iommu_ops, dev);if (ret) {dev_err (dev,"Failed to register iommu\n" ); - goto err_pm_disable; + goto err_sysfs_remove; }if (qcom_iommu->local_base) {
@@ -858,6 +858,8 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)return 0 ; +err_sysfs_remove: +iommu_device_sysfs_remove (&qcom_iommu->iommu); err_pm_disable:pm_runtime_disable (dev);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 696/1191 iommu/qcom: Fix inverted fault report check in qcom_iommu_fault()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mukesh Ojha <[email protected]>
[ Upstream commit 1f33b8208a1978b0c0d6ad60a47fe4bb7a235e58 ]
report_iommu_fault() returns 0 when a fault handler successfully handles the fault, and -ENOSYS when no handler is installed. The condition '!report_iommu_fault()' evaluates to true (printing "Unhandled context fault") precisely when the fault *was* handled, and stays silent when no handler is present — the opposite of what is intended.
Remove the '!' so the driver logs unhandled faults correctly.
--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +1 -1
@@ -210,7 +210,7 @@ static irqreturn_t qcom_iommu_fault(int irq, void *dev) fsynr =iommu_readl (ctx,ARM_SMMU_CB_FSYNR0 ); iova =iommu_readq (ctx,ARM_SMMU_CB_FAR ); -if (!report_iommu_fault (ctx->domain, ctx->dev, iova,0 )) { +if (report_iommu_fault (ctx->domain, ctx->dev, iova,0 )) { dev_err_ratelimited(ctx->dev, "Unhandled context fault: fsr=0x%x, " "iova=0x%016llx, fsynr=0x%x, cb=%d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 697/1191 thermal: intel: int3400: clean up ODVP on probe failures
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit d83dc9ce57a746a6dca28439bcc0575d26fa6986 ]
evaluate_odvp() creates per-ODVP sysfs files before the thermal zone and later probe resources are registered. The current unwind path only calls cleanup_odvp() from the late sysfs failure path, so failures after evaluate_odvp() but before that label, including thermal_tripless_zone_device_register() failures, leave the ODVP files and storage behind.
Move the ODVP cleanup to the common ART/TRT unwind path so every failure after evaluate_odvp() releases the ODVP state. Also clear the cached ODVP pointers in cleanup_odvp(), because evaluate_odvp() can already call it for partial setup failures while probe continues.
--- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +3 -1
@@ -336,8 +336,10 @@ static void cleanup_odvp(struct int3400_thermal_priv *priv)kfree (priv->odvp_attrs[i].attr.attr.name); }kfree (priv->odvp_attrs); + priv->odvp_attrs =NULL ; }kfree (priv->odvp); + priv->odvp =NULL ; priv->odvp_count =0 ; }
@@ -613,7 +615,6 @@ static int int3400_thermal_probe(struct platform_device *pdev)return 0 ; free_sysfs: -cleanup_odvp (priv);if (!ZERO_OR_NULL_PTR (priv->data_vault)) {sysfs_remove_group (&pdev->dev.kobj, &data_attribute_group);kfree (priv->data_vault);
@@ -627,6 +628,7 @@ static int int3400_thermal_probe(struct platform_device *pdev)acpi_thermal_rel_misc_device_remove (priv->adev->handle);thermal_zone_device_unregister (priv->thermal); free_art_trt: +cleanup_odvp (priv);kfree (priv->trts);kfree (priv->arts); free_priv:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 698/1191 ext4: drain in-flight DIO before buffered write fallback
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baokun Li <[email protected]>
[ Upstream commit 15cdefd0c0522f9d5e12d947fa04f4c11649b699 ]
generic/746 started failing intermittently on ext3 (no-extent inodes). The test triggers 'Page cache invalidation failure on direct I/O' warnings and subsequent fsync returns -EIO. Adding a 50ms delay between ext4_buffered_write_iter() and filemap_write_and_wait_range() in ext4_dio_write_iter() makes the race almost always reproducible.
On no-extent inodes, DIO writes to holes cannot use unwritten extents, so ext4_iomap_alloc() leaves m_flags=0 and ext4_map_blocks() returns 0. The iomap layer then returns -ENOTBLK, causing fallback to buffered I/O.
The fallback path in ext4_dio_write_iter() calls ext4_buffered_write_iter() which dirties pages, then does flush and invalidate. However, there's an unprotected window between ext4_buffered_write_iter() returning (with inode lock released) and the subsequent flush+invalidate.
Concurrent async DIO completions from other threads can run kiocb_invalidate_post_direct_write() during this window. If pages have been re-dirtied, post-invalidation finds dirty pages and triggers the warning, setting -EIO in the error sequence.
Consider a file with two 4k extents: [hole][written]. Thread A does DIO to the written extent, while thread B does DIO spanning both:
kworker A (4k DIO, allocated block) kworker B (8k DIO, fallback)
----------------------------------- ----------------------------
inode_lock_shared() inode_lock_shared()
iomap_dio_rw(): iomap_dio_rw():
kiocb_invalidate_pages -> clean iomap_begin -> -ENOTBLK
submit_bio (async) dio->size = 0 inode_unlock_shared() inode_unlock_shared()
[bio pending in block layer] /* fallback: lock released */
ext4_buffered_write_iter()
inode_lock(exclusive)
generic_perform_write()
-> dirty pages [0, 8k]
inode_unlock(exclusive)
/* pages dirty, no lock */
[bio completes] filemap_write_and_wait_range()
iomap_dio_complete() -> flush dirty pages
kiocb_invalidate_post_direct_write() invalidate_mapping_pages()
invalidate_inode_pages2_range()
-> finds dirty page!
-> dio_warn_stale_pagecache()
-> errseq_set(-EIO)This issue can be triggered through normal I/O paths, not just intentionally overlapping DIO writes from userspace. For example, generic/746 uses a loop device where multiple kworkers issue concurrent I/O to the backing file. Additionally, when block_size < folio_size, non-overlapping DIO writes that share a large folio can also trigger the race.
Add inode_dio_wait() in ext4_buffered_write_iter() before ext4_write_checks() to drain all in-flight DIO. This ensures that all DIO clears existing pages before submitting IO (via kiocb_invalidate_pages()), all BIO waits for all DIO to complete (via inode_dio_wait()), and ext4_write_checks() observes the inode size after all completed DIO so that ext4_block_zero_eof() does not race with in-flight DIO, thus eliminating the race.
--- fs/ext4/file.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/ext4/file.c +7 -0
@@ -277,6 +277,13 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,return -EOPNOTSUPP ;inode_lock (inode); + +/* +* Prevent concurrent direct I/O and buffered I/O to the same file +* range. Wait for in-flight DIO to finish before dirtying pages. +*/ +inode_dio_wait (inode); + ret =ext4_write_checks (iocb, from);if (ret <=0 ) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 699/1191 wifi: ath6kl: avoid buffer overreads in WMI event handlers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Johnson <[email protected]>
[ Upstream commit f57314aade9d74d30f3360ec5ef85a83654748be ]
The following WMI event handlers currently read from the event buffer without first verifying that the message was large enough to hold the expected event:ath6kl_wmi_scan_complete_rx() ath6kl_wmi_addba_req_event_rx() ath6kl_wmi_delba_req_event_rx()
Add length checks to prevent overread.
--- drivers/net/wireless/ath/ath6kl/wmi.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath6kl/wmi.c +15 -2
@@ -1296,6 +1296,9 @@ static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len, {struct wmi_scan_complete_event *ev; +if (len <sizeof (*ev)) +return -EINVAL ; + ev = (struct wmi_scan_complete_event *) datap;ath6kl_scan_complete_evt (vif,a_sle32_to_cpu (ev->status));
@@ -3372,7 +3375,12 @@ static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,static int ath6kl_wmi_addba_req_event_rx (struct wmi *wmi,u8 *datap,int len,struct ath6kl_vif *vif) { -struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap; +struct wmi_addba_req_event *cmd; + +if (len <sizeof (*cmd)) +return -EINVAL ; + + cmd = (struct wmi_addba_req_event *)datap;aggr_recv_addba_req_evt (vif, cmd->tid,le16_to_cpu (cmd->st_seq_no), cmd->win_sz);
@@ -3383,7 +3391,12 @@ static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,static int ath6kl_wmi_delba_req_event_rx (struct wmi *wmi,u8 *datap,int len,struct ath6kl_vif *vif) { -struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap; +struct wmi_delba_event *cmd; + +if (len <sizeof (*cmd)) +return -EINVAL ; + + cmd = (struct wmi_delba_event *)datap;aggr_recv_delba_req_evt (vif, cmd->tid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 700/1191 wifi: ath11k: Correctly copy the hint BSSID in WMI scan request
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Johnson <[email protected]>
[ Upstream commit 6fe2dddf59bbb2a96be0fcf23a205807b25ac173 ]
Currently, in ath11k_wmi_send_scan_start_cmd(), the logic to populate the hint_bssid copies the BSSID in the wrong direction, from the firmware message to the argument buffer. Swap the parameters so that the BSSID is correctly populated in the firmware message from the argument buffer.
This issue was reported on ath12k, but exists in ath11k as well.
Compile tested only.
--- drivers/net/wireless/ath/ath11k/wmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/wmi.c +2 -2
@@ -2325,8 +2325,8 @@ int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,for (i =0 ; i < params->num_hint_bssid; ++i) { hint_bssid->freq_flags = params->hint_bssid[i].freq_flags; -ether_addr_copy (¶ms->hint_bssid[i].bssid.addr[0 ], - &hint_bssid->bssid.addr[0 ]); +ether_addr_copy (&hint_bssid->bssid.addr[0 ], + ¶ms->hint_bssid[i].bssid.addr[0 ]); hint_bssid++; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 701/1191 wifi: ath11k: Avoid buffer overread in ath11k_wmi_tlv_op_rx()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Johnson <[email protected]>
[ Upstream commit 9ef9dd30058cc9223c72f711dca1a28a5947d0c5 ]
Currently, in ath11k_wmi_tlv_op_rx(), the firmware buffer is read without first verifying that the buffer has enough data to hold a header. This could result in a buffer overread.
Add an upfront length check before dereferencing skb->data as a wmi_cmd_hdr. The check is placed before the trace_ath11k_wmi_event() call to preserve the existing trace semantics (tracing the full raw WMI event including the header), unlike the analogous ath12k fix which could use skb_pull_data() directly.
Compile tested only.
--- drivers/net/wireless/ath/ath11k/wmi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/wmi.c +4 -2
@@ -8046,13 +8046,15 @@ static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)struct wmi_cmd_hdr *cmd_hdr;enum wmi_tlv_event_id id; +if (skb->len <sizeof (*cmd_hdr)) + goto out; + cmd_hdr = (struct wmi_cmd_hdr *)skb->data; id =FIELD_GET (WMI_CMD_HDR_CMD_ID , (cmd_hdr->cmd_id));trace_ath11k_wmi_event (ab, id, skb->data, skb->len); -if (skb_pull (skb,sizeof (struct wmi_cmd_hdr )) ==NULL ) - goto out; +skb_pull (skb,sizeof (*cmd_hdr));switch (id) {/* Process all the WMI events here */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 702/1191 ext4: fix buffer_head leak in ext4_init_orphan_info
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanghui Yang <[email protected]>
[ Upstream commit 05704335803b69c1bfa8637b7ada942bf2ee8a41 ]
ext4_init_orphan_info() reads orphan file blocks with ext4_bread() and stores the returned buffer_head in oi->of_binfo[i].ob_bh.
If ext4_bread() succeeds but the orphan block magic or checksum validation fails, the function jumps to out_free. However, the old out_free loop starts releasing buffers from i - 1, so the current buffer_head at index i is skipped.
This leaks the buffer_head reference obtained by ext4_bread() on the bad magic and bad checksum error paths.
Fix this by tracking the number of successfully read buffer_heads and releasing exactly those buffer_heads on the error path.
--- fs/ext4/orphan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/ext4/orphan.c +6 -2
@@ -573,6 +573,7 @@ int ext4_init_orphan_info(struct super_block *sb)int i, j;int ret;int free; +int loaded =0 ;__le32 *bdata;int inodes_per_ob =ext4_inodes_per_orphan_block (sb);struct ext4_orphan_block_tail *ot;
@@ -616,6 +617,7 @@ int ext4_init_orphan_info(struct super_block *sb) ret = -EIO ; goto out_free; } + loaded++; ot =ext4_orphan_block_tail (sb, oi->of_binfo[i].ob_bh);if (le32_to_cpu (ot->ob_magic) !=EXT4_ORPHAN_BLOCK_MAGIC ) {ext4_error (sb,"orphan file block %d: bad magic" , i);
@@ -638,8 +640,10 @@ int ext4_init_orphan_info(struct super_block *sb)iput (inode);return 0 ; out_free: -for (i--; i >=0 ; i--) -brelse (oi->of_binfo[i].ob_bh); +while (loaded >0 ) { + loaded--; +brelse (oi->of_binfo[loaded].ob_bh); + }kvfree (oi->of_binfo); out_put:iput (inode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 703/1191 ext4: check dir entry fits before reading the hash trailer in ext4_search_dir()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit c7e6b863d298f56522d0d08554bbea7f142e6588 ]
For casefolded encrypted directories ext4 stores an 8-byte hash trailer after the name (EXT4_DIRENT_HASHES()), at an offset derived from de->name_len. On the sb_no_casefold_compat_fallback() path ext4_match() reads that trailer, but ext4_search_dir()'s by-hand pre-check only tests de->name + de->name_len <= dlimit, which proves the name fits, not the rounded trailer. A crafted entry whose name ends at the block boundary passes the check while EXT4_DIRENT_HASHES(de) lands past the block end, so ext4_match() reads out of bounds on an ordinary lookup. KASAN reports it as a use-after-free when the page after the directory block holds a freed object:
BUG: KASAN: use-after-free in ext4_match (fs/ext4/namei.c:1435) Read of size 4 at addr ffff888010458000 by task exploit Call Trace: ext4_match (fs/ext4/namei.c:1435) ext4_search_dir (fs/ext4/namei.c:1470) __ext4_find_entry (fs/ext4/namei.c:1268 fs/ext4/namei.c:1632) ext4_lookup (fs/ext4/namei.c:1703 fs/ext4/namei.c:1769) ... filename_lookup (fs/namei.c:2842) vfs_statx (fs/stat.c:353) __do_sys_newfstatat (fs/stat.c:538) do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Require, for hash-in-dirent directories, that the whole entry including the rounded trailer fits before calling ext4_match(). This is the same bound ext4_check_dir_entry() already enforces via ext4_dir_rec_len(), so no well-formed entry is rejected. The other caller, ext4_find_dest_de(), runs ext4_check_dir_entry() first and is unaffected.
--- fs/ext4/namei.c | 2 ++ 1 file changed, 2 insertions(+)
fs/ext4/namei.c +2 -0
@@ -1542,6 +1542,8 @@ int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size,/* this code is executed quadratically often */ /* do minimal checking `by hand' */ if (de->name + de->name_len <= dlimit && + (!ext4_hash_in_dirent (dir) || + (char *)de +ext4_dir_rec_len (de->name_len, dir) <= dlimit) &&ext4_match (dir, fname, de)) {/* found a match - just to be sure, do * a full check */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 704/1191 ARM: dts: allwinner: a10: Fix PMU interrupt
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andre Przywara <[email protected]>
[ Upstream commit eb7051f756460d7b951e94d9656e31ebb631ba28 ]
The Performance Monitoring Unit of the Cortex-A8 cores in the Allwinner A10 SoC is connected to interrupt line 66, not 3. This is shown in the manual (where interrupt 3 is assigned to UART2, also in our .dtsi), but has also been confirmed by triggering an PMU overflow interrupt and inspecting the IRQ controller status registers (from U-Boot). Please note that "perf stat" does not use interrupts, this might explain why this evaded the initial testing.
--- arch/arm/boot/dts/sun4i-a10.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/sun4i-a10.dtsi +1 -1
@@ -185,7 +185,7 @@ de: display-engine { pmu { compatible = "arm,cortex-a8-pmu"; - interrupts = <3>; + interrupts = <66>; }; reserved-memory {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 705/1191 perf cs-etm: Flush thread stacks after decoder reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit ea5075e3776846d4941dddf1549426ebd3feb81f ]
Perf resets the CoreSight decoder when moving to a new AUX trace buffer, this causes trace discontinunity globally.
For callchain synthesis, keeping thread-stack state after decoder reset can leave stale call/return history attached to threads that are decoded later, producing incorrect synthesized callchains.
Flush all host thread stacks after a decoder reset. When virtualization is present, flush the guest thread stacks as well.
Stable-dep-of: ec99be8a31db ("perf cs-etm: Avoid truncating AUX buffer sizes to int")
--- tools/perf/util/cs-etm.c | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
tools/perf/util/cs-etm.c +45 -0
@@ -1635,6 +1635,45 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,return 0 ; } + +static int cs_etm__flush_stack_cb (struct thread *thread, +void *data__maybe_unused ) +{ +thread_stack__flush (thread); +return 0 ; +} + +static void cs_etm__flush_machine_stack (struct cs_etm_queue *etmq,pid_t pid) +{ +struct machine *machine; + + machine =machines__find (&etmq->etm->session->machines, pid); +if (machine) +machine__for_each_thread (machine, cs_etm__flush_stack_cb,NULL ); +} + +static void cs_etm__flush_all_stack (struct cs_etm_queue *etmq) +{ +enum cs_etm_pid_fmt pid_fmt =cs_etm__get_pid_fmt (etmq); + +if (!etmq->etm->synth_opts.last_branch) +return ; + +switch (pid_fmt) { +case CS_ETM_PIDFMT_CTXTID2 : +/* Clear the guest stack if virtualization is supported */ +cs_etm__flush_machine_stack (etmq,DEFAULT_GUEST_KERNEL_ID ); + fallthrough; +case CS_ETM_PIDFMT_CTXTID : +cs_etm__flush_machine_stack (etmq,HOST_KERNEL_ID ); +break ; +case CS_ETM_PIDFMT_NONE : +default : +break ; + + } +} +/* * cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue * if need be.
@@ -1657,6 +1696,12 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) ret =cs_etm_decoder__reset (etmq->decoder);if (ret)return ret; + +/* +* Since the decoder is reset, this causes a global trace +* discontinuity. Flush all thread stacks. +*/ +cs_etm__flush_all_stack (etmq); }return etmq->buf_len;
Signature · 1 line
2.53.0
Re: [PATCH 6.1 0705/1191] perf cs-etm: Flush thread stacks after decoder reset
Hi Sasha, Greg,
Quoted 92 lines · Greg Kroah-Hartman
6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit
ea5075e3776846d4941dddf1549426ebd3feb81f]Perf resets the CoreSight decoder when moving to a new AUX trace buffer, this causes trace discontinunity globally.
For callchain synthesis, keeping thread-stack state after decoder reset can leave stale call/return history attached to threads that are decoded later, producing incorrect synthesized callchains.
Flush all host thread stacks after a decoder reset. When virtualization is present, flush the guest thread stacks as well.
Reviewed-by James Clark <[email protected]>Signed-off-by Leo Yan <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Stable-dep-of:
ec99be8a31db("perf cs-etm: Avoid truncating AUX buffer sizes to int")Signed-off-by Sasha Levin <[email protected]>--- tools/perf/util/cs-etm.c | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)tools/perf/util/cs-etm.c +45
-0@@ -1635,6 +1635,45 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,return 0 ; } + +static int cs_etm__flush_stack_cb (struct thread *thread, +void *data__maybe_unused ) +{ +thread_stack__flush (thread); +return 0 ; +} + +static void cs_etm__flush_machine_stack (struct cs_etm_queue *etmq,pid_t pid) +{ +struct machine *machine; + + machine =machines__find (&etmq->etm->session->machines, pid); +if (machine) +machine__for_each_thread (machine, cs_etm__flush_stack_cb,NULL ); +} + +static void cs_etm__flush_all_stack (struct cs_etm_queue *etmq) +{ +enum cs_etm_pid_fmt pid_fmt =cs_etm__get_pid_fmt (etmq); + +if (!etmq->etm->synth_opts.last_branch) +return ; + +switch (pid_fmt) { +case CS_ETM_PIDFMT_CTXTID2 : +/* Clear the guest stack if virtualization is supported */ +cs_etm__flush_machine_stack (etmq,DEFAULT_GUEST_KERNEL_ID ); + fallthrough; +case CS_ETM_PIDFMT_CTXTID : +cs_etm__flush_machine_stack (etmq,HOST_KERNEL_ID ); +break ; +case CS_ETM_PIDFMT_NONE : +default : +break ; + + } +} +/* * cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue * if need be. @@ -1657,6 +1696,12 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) ret =cs_etm_decoder__reset (etmq->decoder);if (ret)return ret; + +/* +* Since the decoder is reset, this causes a global trace +* discontinuity. Flush all thread stacks. +*/ +cs_etm__flush_all_stack (etmq); }return etmq->buf_len;Signature · 1 line
2.53.0
This one is a problem for at lsast 6.1.y and older, when building the tools in 6.1.y the build fails. for instance CS_ETM_PIDFMT_CTXTID2 is undeclared.
gcc -Wp,-MD,/build/package/package/debian/build/build-tools/tools/perf/util/.cs-etm.o.d -Wp,-MT,/build/package/package/debian/build/build-tools/tools/perf/util/cs-etm.o -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wdate-time -D_FORTIFY_SOURCE=2 -I/build/package/package/tools/perf -I/build/package/package/debian/build/build-tools/tools/perf -isystem /build/package/package/debian/build/build-tools/include -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wno-type-limits -Wstrict-aliasing=3 -Wshadow -DHAVE_SYSCALL_TABLE_SUPPORT -DHAVE_ARCH_X86_64_SUPPORT -I/build/package/package/debian/build/build-tools/tools/perf/arch/x86/include/generated -DHAVE_PERF_REGS_SUPPORT -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET -DNDEBUG=1 -O6 -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/build/package/package/tools/lib/perf/include -I/build/package/package/tools/perf/util/include -I/build/package/package/tools/perf/arch/x86/include -I/build/package/package/tools/include/ -I/build/package/package/tools/arch/x86/include/uapi -I/build/package/package/tools/include/uapi -I/build/package/package/tools/arch/x86/include/ -I/build/package/package/tools/arch/x86/ -I/build/package/package/debian/build/build-tools/tools/perf//util -I/build/package/package/debian/build/build-tools/tools/perf/ -I/build/package/package/tools/perf/util -I/build/package/package/tools/perf -I/build/package/package/tools/lib/ -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP -DHAVE_PTHREAD_BARRIER -DHAVE_EVENTFD_SUPPORT -DHAVE_GET_CURRENT_DIR_NAME -DHAVE_GETTID -DHAVE_FILE_HANDLE -DHAVE_DWARF_GETLOCATIONS_SUPPORT -DHAVE_GLIBC_SUPPORT -DHAVE_AIO_SUPPORT -DHAVE_SCHED_GETCPU_SUPPORT -DHAVE_SETNS_SUPPORT -DHAVE_CSTRACE_SUPPORT -DHAVE_LIBELF_SUPPORT -DHAVE_ELF_GETPHDRNUM_SUPPORT -DHAVE_GELF_GETNOTE_SUPPORT -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT -DHAVE_DWARF_SUPPORT -DHAVE_LIBBPF_SUPPORT -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID -DHAVE_LIBBPF_BPF_PROG_LOAD -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP -DHAVE_LIBBPF_BPF_PROGRAM__SET_INSNS -DHAVE_LIBBPF_BTF__RAW_DATA -DHAVE_LIBBPF_BPF_MAP_CREATE -DHAVE_BPF_PROLOGUE -DHAVE_JITDUMP -DHAVE_DWARF_UNWIND_SUPPORT -DNO_LIBUNWIND_DEBUG_FRAME -DHAVE_LIBUNWIND_SUPPORT -DHAVE_SLANG_SUPPORT -DHAVE_LIBPERL_SUPPORT -DHAVE_TIMERFD_SUPPORT -DHAVE_LIBPYTHON_SUPPORT -DHAVE_CPLUS_DEMANGLE_SUPPORT -DHAVE_ZLIB_SUPPORT -DHAVE_LZMA_SUPPORT -DHAVE_ZSTD_SUPPORT -DHAVE_LIBCAP_SUPPORT -DHAVE_BACKTRACE_SUPPORT -DHAVE_LIBNUMA_SUPPORT -DHAVE_KVM_STAT_SUPPORT -DHAVE_PERF_READ_VDSO32 -DHAVE_PERF_READ_VDSOX32 -DHAVE_LIBBABELTRACE_SUPPORT -DHAVE_AUXTRACE_SUPPORT -I/build/package/package/debian/build/build-tools/tools/perf/ -D"BUILD_STR(s)=#s" -c -o /build/package/package/debian/build/build-tools/tools/perf/util/cs-etm.o util/cs-etm.cutil/cs-etm.c: In function 'cs_etm__flush_all_stack':util/cs-etm.c:1656:14: error: variable 'pid_fmt' has initializer but incomplete type
1656 | enum cs_etm_pid_fmt pid_fmt = cs_etm__get_pid_fmt(etmq);
| ^~~~~~~~~~~~~~
util/cs-etm.c:1656:59: warning: passing argument 1 of 'cs_etm__get_pid_fmt' makes integer from pointer without a cast [-Wint-conversion]
1656 | enum cs_etm_pid_fmt pid_fmt = cs_etm__get_pid_fmt(etmq);
| ^~~~
| |
| struct cs_etm_queue *
util/cs-etm.c:167:28: note: expected 'u8' {aka 'unsigned char'} but argument is of type 'struct cs_etm_queue *'
167 | int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt)
| ~~~^~~~~~~~~~~~~
util/cs-etm.c:1656:39: error: too few arguments to function 'cs_etm__get_pid_fmt'
1656 | enum cs_etm_pid_fmt pid_fmt = cs_etm__get_pid_fmt(etmq);
| ^~~~~~~~~~~~~~~~~~~
util/cs-etm.c:167:5: note: declared here
167 | int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt)
| ^~~~~~~~~~~~~~~~~~~util/cs-etm.c:1656:29: error: storage size of 'pid_fmt' isn't known
1656 | enum cs_etm_pid_fmt pid_fmt = cs_etm__get_pid_fmt(etmq);
| ^~~~~~~util/cs-etm.c:1662:14: error: 'CS_ETM_PIDFMT_CTXTID2' undeclared (first use in this function)
1662 | case CS_ETM_PIDFMT_CTXTID2:
| ^~~~~~~~~~~~~~~~~~~~~
util/cs-etm.c:1662:14: note: each undeclared identifier is reported only once for each function it appears in
util/cs-etm.c:1665:17: error: 'fallthrough' undeclared (first use in this function)
1665 | fallthrough;
| ^~~~~~~~~~~
util/cs-etm.c:1666:14: error: 'CS_ETM_PIDFMT_CTXTID' undeclared (first use in this function)
1666 | case CS_ETM_PIDFMT_CTXTID:
| ^~~~~~~~~~~~~~~~~~~~Not sure if 5414b532611b ("perf cs-etm: Make PID format accessible from struct cs_etm_auxtrace") would be suitable for backporting.
Sasha, could you have look?
Regards,
Salvatore
Sasha Levin
maintainerRe: [PATCH 6.1 0705/1191] perf cs-etm: Flush thread stacks after decoder reset
Quoted 6 lines
util/cs-etm.c: In function 'cs_etm__flush_all_stack':util/cs-etm.c:1656:14: error: variable 'pid_fmt' has initializer but incomplete type
1656 | enumcs_etm_pid_fmtpid_fmt=cs_etm__get_pid_fmt(etmq);Not sure if
5414b532611b("perf cs-etm: Make PID format accessible from structcs_etm_auxtrace") would be suitable for backporting.
It is not. That is where the enum and the one-argument cs_etm__get_pid_fmt() come from, and it conflicts on 6.1 and 5.15. 5.10 has no cs_etm__get_pid_fmt() at all.
So both cs-etm commits come back out of 6.1, 5.15 and 5.10 instead. Reverting the dependency alone conflicts; taking it out together with ec99be8a31db ("perf
cs-etm: Avoid truncating AUX buffer sizes to int") restores the pre-series cs-etm.c exactly. 6.6 and newer keep both.
They shipped in v6.1.188, v5.15.221 and v5.10.270, so the perf build is fixed there as of the next release. Thanks for the report; the build gate never compiles tools/perf, so this would not have been caught here.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 6.1 0705/1191] perf cs-etm: Flush thread stacks after decoder reset
Quoted 10 lines · Sasha Levin
Quoted 6 lines
util/cs-etm.c: In function 'cs_etm__flush_all_stack':util/cs-etm.c:1656:14: error: variable 'pid_fmt' has initializer but incomplete type
1656 | enumcs_etm_pid_fmtpid_fmt=cs_etm__get_pid_fmt(etmq);Not sure if
5414b532611b("perf cs-etm: Make PID format accessible from structcs_etm_auxtrace") would be suitable for backporting.It is not. That is where the enum and the one-argument
cs_etm__get_pid_fmt()come from, and it conflicts on 6.1 and 5.15. 5.10 has nocs_etm__get_pid_fmt()at all.
There is a dependency commit:
5414b532611b ("perf cs-etm: Make PID format accessible from struct cs_etm_auxtrace")
which changed cs_etm__get_pid_fmt() to take a single argument and introduced CS_ETM_PIDFMT_{CTXTID,CTXTID2}. It landed in v6.5:
$ git describe --contains 5414b532611b19671cb10813e5d56e011574d698 v6.5-rc1~18^2~123
Quoted 4 lines
So both cs-etm commits come back out of 6.1, 5.15 and 5.10 instead. Reverting the dependency alone conflicts; taking it out together with
ec99be8a31db("perf
cs-etm: Avoid truncating AUX buffer sizes to int") restores the pre-seriescs-etm.cexactly. 6.6 and newer keep both.
Makes sense to me. Sorry for any incontinence.
Leo
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Greg Kroah-Hartman
maintainerRe: [PATCH 6.1 0705/1191] perf cs-etm: Flush thread stacks after decoder reset
Quoted 2 lines · Leo Yan
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Now deleted.
Greg Kroah-Hartman
maintainerPATCH 706/1191 perf cs-etm: Avoid truncating AUX buffer sizes to int
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit ec99be8a31db999a4f866be74ea7db61dbb19f24 ]
cs_etm__get_trace() returns an int, but it used to return etmq->buf_len on success. That value comes from auxtrace_buffer::size, which is a size_t. For a large AUX trace block, returning the byte count through an int can overflow and make a valid buffer look like a negative error.
The callers do not need the actual byte count from cs_etm__get_trace(). The buffer length is already stored in the etmq->buf_len. The callers only need to distinguish three states:
< 0: error
= 0: no more AUX buffers
Quoted 1 line
0: data is available
Make cs_etm__get_trace() return 0 for all non-error cases and use etmq->buf_len to indicate whether a new buffer was found. Then make cs_etm__get_data_block() return 1 whenever data is available, instead of returning the buffer length.
Also refactor cs_etm__get_data_block() to make its return value semantics clearer.
--- tools/perf/util/cs-etm.c | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-)
tools/perf/util/cs-etm.c +26 -20
@@ -1087,8 +1087,7 @@ cs_etm__get_trace(struct cs_etm_queue *etmq) etmq->buf_used =0 ; etmq->buf_len = aux_buffer->size; etmq->buf = aux_buffer->data; - -return etmq->buf_len; +return 0 ; } static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm,
@@ -1685,26 +1684,33 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) {int ret; -if (!etmq->buf_len) { - ret =cs_etm__get_trace (etmq); -if (ret <=0 ) -return ret; -/* -* We cannot assume consecutive blocks in the data file -* are contiguous, reset the decoder to force re-sync. -*/ - ret =cs_etm_decoder__reset (etmq->decoder); -if (ret) -return ret; +/* The current block is not finished */ +if (etmq->buf_len) +return 1 ; -/* -* Since the decoder is reset, this causes a global trace -* discontinuity. Flush all thread stacks. -*/ -cs_etm__flush_all_stack (etmq); - } + ret =cs_etm__get_trace (etmq); +if (ret <0 ) +return ret; + +/* No more buffer to read */ +if (!etmq->buf_len) +return 0 ; + +/* +* We cannot assume consecutive blocks in the data file +* are contiguous, reset the decoder to force re-sync. +*/ + ret =cs_etm_decoder__reset (etmq->decoder); +if (ret) +return ret; + +/* +* Since the decoder is reset, this causes a global trace +* discontinuity. Flush all thread stacks. +*/ +cs_etm__flush_all_stack (etmq); -return etmq->buf_len; +return 1 ; } static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, u8 trace_chan_id,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 707/1191 leds: pca9532: Fix phantom device registration on missing hardware
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmo Chou <[email protected]>
[ Upstream commit 8d6b6c05b8e33d11e3fb3203309385e1a9cceecd ]
The initial PWM and PSC register writes in pca9532_configure() do not check the return values of i2c_smbus_write_byte_data(). If the I2C device is physically absent from the bus, the write fails with -ENXIO. However, the driver ignores this error and allows probe() to complete successfully.
This results in the registration of phantom LED class devices and gpiochips backed by non-existent hardware. Subsequent GPIO reads from these phantom chips return bogus values (due to -ENXIO being truncated to an unsigned char in pca9532_gpio_get_value()), silently corrupting hardware state tracking in userspace.
Propagate the I2C write failures back to probe() so the driver core can gracefully abort binding and release devres-managed resources.
--- drivers/leds/leds-pca9532.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/leds/leds-pca9532.c +8 -4
@@ -355,10 +355,14 @@ static int pca9532_configure(struct i2c_client *client,for (i =0 ; i <2 ; i++) { data->pwm[i] = pdata->pwm[i]; data->psc[i] = pdata->psc[i]; -i2c_smbus_write_byte_data (client,PCA9532_REG_PWM (maxleds, i), - data->pwm[i]); -i2c_smbus_write_byte_data (client,PCA9532_REG_PSC (maxleds, i), - data->psc[i]); + err =i2c_smbus_write_byte_data (client,PCA9532_REG_PWM (maxleds, i), + data->pwm[i]); +if (err <0 ) +return err; + err =i2c_smbus_write_byte_data (client,PCA9532_REG_PSC (maxleds, i), + data->psc[i]); +if (err <0 ) +return err; }for (i =0 ; i < data->chip_info->num_leds; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 708/1191 drm/tve200: add OF module alias for autoloading
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
[ Upstream commit b6c3585f2058e0fbfa8cb403458f5cc6cf5c5e06 ]
The TVE200 DRM driver can be built as a module and uses tve200_of_match as its OF match table, but the table is not exported for module alias generation.
Add the MODULE_DEVICE_TABLE(of, ...) entry so modpost can generate OF module aliases for OF based module autoloading.
--- drivers/gpu/drm/tve200/tve200_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/tve200/tve200_drv.c +1 -0
@@ -258,6 +258,7 @@ static const struct of_device_id tve200_of_match[] = { }, {}, }; +MODULE_DEVICE_TABLE (of, tve200_of_match);static struct platform_driver tve200_driver = { .driver = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 709/1191 netfilter: nf_nat_sip: rewind offset when NAT shrinks the packet
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 16aecbe3036f6097c26b51b12e4c1cf207769690 ]
sashiko says:
If map_addr() changes the packet length, such as when the public NAT IP string is shorter or longer than the internal IP, coff will still point to the offset relative to the pre-mangled packet.
If the packet shrinks, coff could overshoot the correct position, potentially causing the next ct_sip_parse_header_uri() call to silently skip bytes and miss subsequent Contact headers. Could this lead to a failure to NAT those subsequent headers and leak internal network details?
--- net/netfilter/nf_nat_sip.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_nat_sip.c +5 -0
@@ -267,12 +267,17 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff, SIP_HDR_CONTACT, &in_header, &matchoff, &matchlen, &addr, &port) > 0) { +int old_len = skb->len, delta; +if (!map_addr (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, &addr, port)) {nf_ct_helper_log (skb, ct,"cannot mangle contact" );return NF_DROP ; } + + delta = (int )skb->len - old_len; + coff += delta; } if (!map_sip_addr(skb, protoff, dataoff, dptr, datalen, SIP_HDR_FROM) ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 710/1191 fs/ntfs3: fix out-of-bounds read of INDEX_ROOT in reparse/objid init
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Wu <[email protected]>
[ Upstream commit 2064bc663f89e61b8681c1fb9d1ce445de72063d ]
ntfs_reparse_init() and ntfs_objid_init() parse the index root of the $Extend/$Reparse and $Extend/$ObjId metafiles (the INDEX_ROOT attributes named $R and $O). They read its type and rule fields through resident_data(), which does not check that the resident attribute is large enough to hold them.
mi_enum_attr() accepts a resident attribute with data_off == asize and data_size == 0. For such an attribute placed last in its MFT record, resident_data() returns a pointer to the end of the record_size buffer, so reading root->type / root->rule reads past the allocation.
Use resident_data_ex(attr, sizeof(struct INDEX_ROOT)) and bail out when it returns NULL, as ntfs_security_init() already does for $SDH / $SII.
The attribute is only parsed while mounting a crafted image, so this needs CAP_SYS_ADMIN.
BUG: KASAN: slab-out-of-bounds in ntfs_reparse_init (fs/ntfs3/fsntfs.c:2306) Read of size 4 at addr ffff88801219dc00 by task mount ntfs_reparse_init (fs/ntfs3/fsntfs.c:2306) ntfs_fill_super (fs/ntfs3/super.c:1604) get_tree_bdev_flags (fs/super.c:1703) vfs_get_tree (fs/super.c:1758) path_mount (fs/namespace.c:4131) __x64_sys_mount (fs/namespace.c:4360)
--- fs/ntfs3/fsntfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ntfs3/fsntfs.c +4 -4
@@ -2284,8 +2284,8 @@ int ntfs_reparse_init(struct ntfs_sb_info *sbi) goto out; } - root_r =resident_data (attr); -if (root_r->type !=ATTR_ZERO || + root_r =resident_data_ex (attr,sizeof (struct INDEX_ROOT )); +if (!root_r || root_r->type !=ATTR_ZERO || root_r->rule !=NTFS_COLLATION_TYPE_UINTS ) { err = -EINVAL ; goto out;
@@ -2322,8 +2322,8 @@ int ntfs_objid_init(struct ntfs_sb_info *sbi) goto out; } - root =resident_data (attr); -if (root->type !=ATTR_ZERO || + root =resident_data_ex (attr,sizeof (struct INDEX_ROOT )); +if (!root || root->type !=ATTR_ZERO || root->rule !=NTFS_COLLATION_TYPE_UINTS ) { err = -EINVAL ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 711/1191 arm64: dts: rockchip: Fix Gru WLAN sideband interrupt
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabio Estevam <[email protected]>
[ Upstream commit a761818d9ee11183df0aefd16bf9fe46cc1c4c6d ]
The Marvell WLAN host wake interrupt is wired to GPIO0 8 and is not one of the PCI INTx interrupts. The PCI device schema therefore interprets the two-cell GPIO interrupt specifier as an invalid PCI interrupt and reports dtbs_check warnings:
pcie@0,0: wifi@0,0:interrupts:0:0: 8 is not one of [1, 2, 3, 4] pcie@0,0: wifi@0,0:interrupts:0: [8, 8] is too long
Describe the sideband interrupt with interrupts-extended, which explicitly carries the interrupt controller and removes the ambiguity.
--- arch/arm64/boot/dts/rockchip/rk3399-gru-chromebook.dtsi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/boot/dts/rockchip/rk3399-gru-chromebook.dtsi +1 -2
@@ -511,8 +511,7 @@ &pci_rootport { mvl_wifi: wifi@0,0 { compatible = "pci1b4b,2b42"; reg = <0x0000 0x0 0x0 0x0 0x0>; - interrupt-parent = <&gpio0>; - interrupts = <8 IRQ_TYPE_LEVEL_LOW>; + interrupts-extended = <&gpio0 8 IRQ_TYPE_LEVEL_LOW>; pinctrl-names = "default"; pinctrl-0 = <&wlan_host_wake_l>; wakeup-source;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 712/1191 ARM: lpc32xx: only run SoC init on LPC32xx hardware
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 717ea4000867e6dffee5e1ed92150a9704ae9f68 ]
lpc32xx_check_uid() and lpc32xx_pm_init() are arch_initcalls that poke LPC32xx-only registers. Since the multiplatform conversion they also run on other ARCH_MULTI_V5 boards where access faults e.g. on versatile:
Unable to handle kernel paging request at virtual address f4004130 PC is at lpc32xx_check_uid+0x2c/0x9c
Drop the arch_initcall() registrations and call both functions directly from lpc3250_machine_init(), the machine's .init_machine hook. The calls are placed in link order (common.c, pm.c, phy3250.c) to keep their previous relative ordering.
--- arch/arm/mach-lpc32xx/common.c | 5 +---- arch/arm/mach-lpc32xx/common.h | 2 ++ arch/arm/mach-lpc32xx/phy3250.c | 2 ++ arch/arm/mach-lpc32xx/pm.c | 5 +---- 4 files changed, 6 insertions(+), 8 deletions(-)
arch/arm/mach-lpc32xx/common.c +1 -4
@@ -106,7 +106,7 @@ void __init lpc32xx_map_io(void)iotable_init (lpc32xx_io_desc,ARRAY_SIZE (lpc32xx_io_desc)); } -static int __init lpc32xx_check_uid (void ) +void __init lpc32xx_check_uid (void ) {u32 uid[4 ];
@@ -119,7 +119,4 @@ static int __init lpc32xx_check_uid(void) system_serial_low = uid[0 ]; system_serial_high = uid[1 ]; } - -return 1 ; } -arch_initcall (lpc32xx_check_uid);
arch/arm/mach-lpc32xx/common.h +2 -0
@@ -16,6 +16,8 @@* Other arch specific structures and functions */ extern void __init lpc32xx_map_io (void ); +extern void __init lpc32xx_check_uid (void ); +extern void __init lpc32xx_pm_init (void );extern void __init lpc32xx_serial_init (void );/*
arch/arm/mach-lpc32xx/phy3250.c +2 -0
@@ -71,6 +71,8 @@ static const struct of_dev_auxdata lpc32xx_auxdata_lookup[] __initconst = {static void __init lpc3250_machine_init (void ) { +lpc32xx_check_uid (); +lpc32xx_pm_init ();lpc32xx_serial_init ();of_platform_default_populate (NULL , lpc32xx_auxdata_lookup,NULL );
arch/arm/mach-lpc32xx/pm.c +1 -4
@@ -120,7 +120,7 @@ static const struct platform_suspend_ops lpc32xx_pm_ops = {#define EMC_DYN_MEM_CTRL_OFS 0x20#define EMC_SRMMC (1 << 3)#define EMC_CTRL_REG io_p2v(LPC32XX_EMC_BASE + EMC_DYN_MEM_CTRL_OFS) -static int __init lpc32xx_pm_init (void ) +void __init lpc32xx_pm_init (void ) {/* * Setup SDRAM self-refresh clock to automatically disable o
@@ -129,7 +129,4 @@ static int __init lpc32xx_pm_init(void)__raw_writel (__raw_readl (EMC_CTRL_REG ) |EMC_SRMMC ,EMC_CTRL_REG );suspend_set_ops (&lpc32xx_pm_ops); - -return 0 ; } -arch_initcall (lpc32xx_pm_init);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 713/1191 selftests/bpf: Fix incorrect error checking for pthread_create
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Yang <[email protected]>
[ Upstream commit b04b8d4e198aefc863e7b702ececb957845b0c25 ]
pthread_create returns 0 on success and a positive error code on failure; it never returns a negative value. The current conditional branch can never be taken. Failures during thread creation are silently ignored, which will lead to invalid memory access when waiting on threads or dereferencing thread handles later.
--- tools/testing/selftests/bpf/test_progs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_progs.c +1 -1
@@ -1260,7 +1260,7 @@ static void server_main(void) data[i].worker_id = i; data[i].sock_fd = env.worker_socks[i]; rc =pthread_create (&dispatcher_threads[i],NULL , dispatch_thread, &data[i]); -if (rc <0 ) { +if (rc) {perror ("Failed to launch dispatcher thread" );exit (EXIT_ERR_SETUP_INFRA ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 714/1191 selftests/bpf: Fix memory leak on subtest_states reallocation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Yang <[email protected]>
[ Upstream commit 06efb01c6530e9cfc247178cb96aa8adb3beaf61 ]
Fix memory leak in subtest_states reallocation,
and revert subtest_num if allocation fails.
--- tools/testing/selftests/bpf/test_progs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/test_progs.c +5 -4
@@ -404,18 +404,19 @@ bool test__start_subtest(const char *subtest_name)struct test_state *state = env.test_state;struct subtest_state *subtest_state;size_t sub_state_size =sizeof (*subtest_state); +void *tmp;if (env.subtest_state)test__end_subtest (); state->subtest_num++; - state->subtest_states = -realloc (state->subtest_states, - state->subtest_num * sub_state_size); -if (!state->subtest_states) { + tmp =realloc (state->subtest_states, state->subtest_num * sub_state_size); +if (!tmp) { + state->subtest_num--;fprintf (stderr,"Not enough memory to allocate subtest result\n" );return false; } + state->subtest_states = tmp; subtest_state = &state->subtest_states[state->subtest_num -1 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 715/1191 pinctrl: mediatek: Use C99 initializers in PINCTRL_PIN_GROUP()
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 bb5eace1562fcef3c7ac9d0bd3e01af1187e46d0 ]
For the better flexibility use C99 initializers in PINCTRL_PIN_GROUP().
Stable-dep-of: 88292b7103d2 ("pinctrl: mediatek: free EINT resources on unbind")
--- drivers/pinctrl/mediatek/pinctrl-moore.h | 12 ++++++------ drivers/pinctrl/mediatek/pinctrl-paris.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/pinctrl/mediatek/pinctrl-moore.h +6 -6
@@ -37,12 +37,12 @@ .funcs = NULL, \ } -#define PINCTRL_PIN_GROUP (name, id) \ - { \ - name, \ - id##_pins, \ - ARRAY_SIZE(id##_pins), \ - id##_funcs, \ +#define PINCTRL_PIN_GROUP (_name_, id) \ + { \ + .name = _name_, \ + .pins = id##_pins, \ + .num_pins = ARRAY_SIZE(id##_pins), \ + .data = id##_funcs, \ } int mtk_moore_pinctrl_probe(struct platform_device *pdev,
drivers/pinctrl/mediatek/pinctrl-paris.h +6 -6
@@ -49,12 +49,12 @@ __VA_ARGS__, { } }, \ } -#define PINCTRL_PIN_GROUP (name, id) \ - { \ - name, \ - id##_pins, \ - ARRAY_SIZE(id##_pins), \ - id##_funcs, \ +#define PINCTRL_PIN_GROUP (_name_, id) \ + { \ + .name = _name_, \ + .pins = id##_pins, \ + .num_pins = ARRAY_SIZE(id##_pins), \ + .data = id##_funcs, \ }int mtk_paris_pinctrl_probe (struct platform_device *pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 716/1191 pinctrl: mediatek: Add EINT support for multiple addresses
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao Chang <[email protected]>
[ Upstream commit 3ef9f710efcb5cc1335b5b09c16c757f703d7e5f ]
For flexible routing, eint will be divided into 5 bases, and it will obtain the operation address through the pins array.
Stable-dep-of: 88292b7103d2 ("pinctrl: mediatek: free EINT resources on unbind")
--- drivers/pinctrl/mediatek/mtk-eint.c | 313 +++++++++++------- drivers/pinctrl/mediatek/mtk-eint.h | 23 +- .../pinctrl/mediatek/pinctrl-mtk-common-v2.c | 37 ++- .../pinctrl/mediatek/pinctrl-mtk-common-v2.h | 1 + drivers/pinctrl/mediatek/pinctrl-paris.h | 7 + 5 files changed, 254 insertions(+), 127 deletions(-)
drivers/pinctrl/mediatek/mtk-eint.c +197 -116
@@ -1,11 +1,13 @@// SPDX-License-Identifier: GPL-2.0 -// Copyright (c) 2014-2018 MediaTek Inc. +// Copyright (c) 2014-2025 MediaTek Inc. /* * Library for MediaTek External Interrupt Support * * Author: Maoguang Meng <[email protected]> * Sean Wang <[email protected]> +* Hao Chang <[email protected]> +* Qingliang Li <[email protected]> * */
@@ -20,6 +22,7 @@#include <linux/platform_device.h> #include "mtk-eint.h" +#include "pinctrl-mtk-common-v2.h" #define MTK_EINT_EDGE_SENSITIVE 0#define MTK_EINT_LEVEL_SENSITIVE 1
@@ -68,13 +71,11 @@ static void __iomem *mtk_eint_get_offset(struct mtk_eint *eint, unsigned int eint_num, unsigned int offset) { -unsigned int eint_base =0 ; +unsigned int idx = eint->pins[eint_num].index; +unsigned int inst = eint->pins[eint_num].instance;void __iomem *reg; -if (eint_num >= eint->hw->ap_num) - eint_base = eint->hw->ap_num; - - reg = eint->base + offset + ((eint_num - eint_base) /32 ) *4 ; + reg = eint->base[inst] + offset + (idx /32 *4 );return reg; }
@@ -83,7 +84,7 @@ static unsigned int mtk_eint_can_en_debounce(struct mtk_eint *eint, unsigned int eint_num) {unsigned int sens; -unsigned int bit =BIT (eint_num %32 ); +unsigned int bit =BIT (eint->pins[eint_num].index %32 );void __iomem *reg =mtk_eint_get_offset (eint, eint_num, eint->regs->sens);
@@ -92,7 +93,7 @@ static unsigned int mtk_eint_can_en_debounce(struct mtk_eint *eint,else sens =MTK_EINT_EDGE_SENSITIVE ; -if (eint_num < eint->hw->db_cnt && sens !=MTK_EINT_EDGE_SENSITIVE ) +if (eint->pins[eint_num].debounce && sens !=MTK_EINT_EDGE_SENSITIVE )return 1 ;else return 0 ;
@@ -102,9 +103,9 @@ static int mtk_eint_flip_edge(struct mtk_eint *eint, int hwirq) {int start_level, curr_level;unsigned int reg_offset; -u32 mask =BIT (hwirq &0x1f ); -u32 port = (hwirq >>5 ) & eint->hw->port_mask; -void __iomem *reg = eint->base + (port <<2 ); +unsigned int mask =BIT (eint->pins[hwirq].index &0x1f ); +unsigned int port = (eint->pins[hwirq].index >>5 ) & eint->hw->port_mask; +void __iomem *reg = eint->base[eint->pins[hwirq].instance] + (port <<2 ); curr_level = eint->gpio_xlate->get_gpio_state (eint->pctl, hwirq);
@@ -126,11 +127,13 @@ static int mtk_eint_flip_edge(struct mtk_eint *eint, int hwirq)static void mtk_eint_mask (struct irq_data *d) {struct mtk_eint *eint =irq_data_get_irq_chip_data (d); -u32 mask =BIT (d->hwirq &0x1f ); +unsigned int idx = eint->pins[d->hwirq].index; +unsigned int inst = eint->pins[d->hwirq].instance; +unsigned int mask =BIT (idx &0x1f );void __iomem *reg =mtk_eint_get_offset (eint, d->hwirq, eint->regs->mask_set); - eint->cur_mask[d->hwirq >>5 ] &= ~mask; + eint->cur_mask[inst][idx >>5 ] &= ~mask;writel (mask, reg); }
@@ -138,22 +141,24 @@ static void mtk_eint_mask(struct irq_data *d)static void mtk_eint_unmask (struct irq_data *d) {struct mtk_eint *eint =irq_data_get_irq_chip_data (d); -u32 mask =BIT (d->hwirq &0x1f ); +unsigned int idx = eint->pins[d->hwirq].index; +unsigned int inst = eint->pins[d->hwirq].instance; +unsigned int mask =BIT (idx &0x1f );void __iomem *reg =mtk_eint_get_offset (eint, d->hwirq, eint->regs->mask_clr); - eint->cur_mask[d->hwirq >>5 ] |= mask; + eint->cur_mask[inst][idx >>5 ] |= mask;writel (mask, reg); -if (eint->dual_edge[d->hwirq]) +if (eint->pins[d->hwirq].dual_edge)mtk_eint_flip_edge (eint, d->hwirq); }static unsigned int mtk_eint_get_mask (struct mtk_eint *eint,unsigned int eint_num) { -unsigned int bit =BIT (eint_num %32 ); +unsigned int bit =BIT (eint->pins[eint_num].index %32 );void __iomem *reg =mtk_eint_get_offset (eint, eint_num, eint->regs->mask);
@@ -163,7 +168,7 @@ static unsigned int mtk_eint_get_mask(struct mtk_eint *eint,static void mtk_eint_ack (struct irq_data *d) {struct mtk_eint *eint =irq_data_get_irq_chip_data (d); -u32 mask =BIT (d->hwirq &0x1f ); +unsigned int mask =BIT (eint->pins[d->hwirq].index &0x1f );void __iomem *reg =mtk_eint_get_offset (eint, d->hwirq, eint->regs->ack);
@@ -174,7 +179,7 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type) {struct mtk_eint *eint =irq_data_get_irq_chip_data (d);bool masked; -u32 mask =BIT (d->hwirq &0x1f ); +unsigned int mask =BIT (eint->pins[d->hwirq].index &0x1f );void __iomem *reg; if (((type & IRQ_TYPE_EDGE_BOTH) && (type & IRQ_TYPE_LEVEL_MASK)) ||
@@ -186,9 +191,9 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type) }if ((type &IRQ_TYPE_EDGE_BOTH ) ==IRQ_TYPE_EDGE_BOTH ) - eint->dual_edge[d->hwirq] =1 ; + eint->pins[d->hwirq].dual_edge =1 ;else - eint->dual_edge[d->hwirq] =0 ; + eint->pins[d->hwirq].dual_edge =0 ;if (!mtk_eint_get_mask (eint, d->hwirq)) {mtk_eint_mask (d);
@@ -223,27 +228,32 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)static int mtk_eint_irq_set_wake (struct irq_data *d,unsigned int on) {struct mtk_eint *eint =irq_data_get_irq_chip_data (d); -int shift = d->hwirq &0x1f ; -int reg = d->hwirq >>5 ; +unsigned int idx = eint->pins[d->hwirq].index; +unsigned int inst = eint->pins[d->hwirq].instance; +unsigned int shift = idx &0x1f ; +unsigned int port = idx >>5 ;if (on) - eint->wake_mask[reg] |=BIT (shift); + eint->wake_mask[inst][port] |=BIT (shift);else - eint->wake_mask[reg] &= ~BIT (shift); + eint->wake_mask[inst][port] &= ~BIT (shift);return 0 ; }static void mtk_eint_chip_write_mask (const struct mtk_eint *eint, -void __iomem *base,u32 *buf) +void __iomem *base,unsigned int **buf) { -int port; +int inst, port, port_num;void __iomem *reg; -for (port =0 ; port < eint->hw->ports; port++) { - reg = base + (port <<2 ); -writel_relaxed (~buf[port], reg + eint->regs->mask_set); -writel_relaxed (buf[port], reg + eint->regs->mask_clr); +for (inst =0 ; inst < eint->nbase; inst++) { + port_num =DIV_ROUND_UP (eint->base_pin_num[inst],32 ); +for (port =0 ; port < port_num; port++) { + reg = eint->base[inst] + (port <<2 ); +writel_relaxed (~buf[inst][port], reg + eint->regs->mask_set); +writel_relaxed (buf[inst][port], reg + eint->regs->mask_clr); + } } }
@@ -303,15 +313,18 @@ static struct irq_chip mtk_eint_irq_chip = {static unsigned int mtk_eint_hw_init (struct mtk_eint *eint) { -void __iomem *dom_en = eint->base + eint->regs->dom_en; -void __iomem *mask_set = eint->base + eint->regs->mask_set; -unsigned int i; - -for (i =0 ; i < eint->hw->ap_num; i +=32 ) { -writel (0xffffffff , dom_en); -writel (0xffffffff , mask_set); - dom_en +=4 ; - mask_set +=4 ; +void __iomem *dom_reg, *mask_reg; +unsigned int i, j; + +for (i =0 ; i < eint->nbase; i++) { + dom_reg = eint->base[i] + eint->regs->dom_en; + mask_reg = eint->base[i] + eint->regs->mask_set; +for (j =0 ; j < eint->base_pin_num[i]; j +=32 ) { +writel (0xffffffff , dom_reg); +writel (0xffffffff , mask_reg); + dom_reg +=4 ; + mask_reg +=4 ; + } }return 0 ;
@@ -322,14 +335,16 @@ mtk_eint_debounce_process(struct mtk_eint *eint, int index) {unsigned int rst, ctrl_offset;unsigned int bit, dbnc; +unsigned int inst = eint->pins[index].instance; +unsigned int idx = eint->pins[index].index; - ctrl_offset = (index /4 ) *4 + eint->regs->dbnc_ctrl; - dbnc =readl (eint->base + ctrl_offset); - bit =MTK_EINT_DBNC_SET_EN << ((index %4 ) *8 ); + ctrl_offset = (idx /4 ) *4 + eint->regs->dbnc_ctrl; + dbnc =readl (eint->base[inst] + ctrl_offset); + bit =MTK_EINT_DBNC_SET_EN << ((idx %4 ) *8 );if ((bit & dbnc) >0 ) { - ctrl_offset = (index /4 ) *4 + eint->regs->dbnc_set; - rst =MTK_EINT_DBNC_RST_BIT << ((index %4 ) *8 ); -writel (rst, eint->base + ctrl_offset); + ctrl_offset = (idx /4 ) *4 + eint->regs->dbnc_set; + rst =MTK_EINT_DBNC_RST_BIT << ((idx %4 ) *8 ); +writel (rst, eint->base[inst] + ctrl_offset); } }
@@ -337,65 +352,68 @@ static void mtk_eint_irq_handler(struct irq_desc *desc) {struct irq_chip *chip =irq_desc_get_chip (desc);struct mtk_eint *eint =irq_desc_get_handler_data (desc); -unsigned int status, eint_num; -int offset, mask_offset, index; -void __iomem *reg =mtk_eint_get_offset (eint,0 , eint->regs->stat); +unsigned int i, j, port, status, shift, mask, eint_num; +void __iomem *reg;int dual_edge, start_level, curr_level;chained_irq_enter (chip, desc); -for (eint_num =0 ; eint_num < eint->hw->ap_num; eint_num +=32 , - reg +=4 ) { - status =readl (reg); -while (status) { - offset =__ffs (status); - mask_offset = eint_num >>5 ; - index = eint_num + offset; - status &= ~BIT (offset); - -/* -* If we get an interrupt on pin that was only required -* for wake (but no real interrupt requested), mask the -* interrupt (as would mtk_eint_resume do anyway later -* in the resume sequence). -*/ -if (eint->wake_mask[mask_offset] &BIT (offset) && - !(eint->cur_mask[mask_offset] &BIT (offset))) { -writel_relaxed (BIT (offset), reg - - eint->regs->stat + - eint->regs->mask_set); - } - - dual_edge = eint->dual_edge[index]; -if (dual_edge) { -/* -* Clear soft-irq in case we raised it last -* time. -*/ -writel (BIT (offset), reg - eint->regs->stat + - eint->regs->soft_clr); - - start_level = - eint->gpio_xlate->get_gpio_state (eint->pctl, - index); - } - -generic_handle_domain_irq (eint->domain, index); - -if (dual_edge) { - curr_level =mtk_eint_flip_edge (eint, index); +for (i =0 ; i < eint->nbase; i++) { +for (j =0 ; j < eint->base_pin_num[i]; j +=32 ) { + port = j >>5 ; + status =readl (eint->base[i] + port *4 + eint->regs->stat); +while (status) { + shift =__ffs (status); + status &= ~BIT (shift); + mask =BIT (shift); + eint_num = eint->pin_list[i][shift + j];/* -* If level changed, we might lost one edge -* interrupt, raised it through soft-irq. +* If we get an interrupt on pin that was only required +* for wake (but no real interrupt requested), mask the +* interrupt (as would mtk_eint_resume do anyway later +* in the resume sequence). */ -if (start_level != curr_level) -writel (BIT (offset), reg - - eint->regs->stat + - eint->regs->soft_set); +if (eint->wake_mask[i][port] & mask && + !(eint->cur_mask[i][port] & mask)) { + reg =mtk_eint_get_offset (eint, eint_num, + eint->regs->mask_set); +writel_relaxed (mask, reg); + } + + dual_edge = eint->pins[eint_num].dual_edge; +if (dual_edge) { +/* +* Clear soft-irq in case we raised it last +* time. +*/ + reg =mtk_eint_get_offset (eint, eint_num, + eint->regs->soft_clr); +writel (mask, reg); + + start_level = + eint->gpio_xlate->get_gpio_state (eint->pctl, + eint_num); + } + +generic_handle_domain_irq (eint->domain, eint_num); + +if (dual_edge) { + curr_level =mtk_eint_flip_edge (eint, eint_num); + +/* +* If level changed, we might lost one edge +* interrupt, raised it through soft-irq. +*/ +if (start_level != curr_level) { + reg =mtk_eint_get_offset (eint, eint_num, + eint->regs->soft_set); +writel (mask, reg); + } + } + +if (eint->pins[eint_num].debounce) +mtk_eint_debounce_process (eint, eint_num); } - -if (index < eint->hw->db_cnt) -mtk_eint_debounce_process (eint, index); } }chained_irq_exit (chip, desc);
@@ -423,6 +441,8 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_num,int virq, eint_offset;unsigned int set_offset, bit, clr_bit, clr_offset, rst, i, unmask, dbnc; +unsigned int inst = eint->pins[eint_num].instance; +unsigned int idx = eint->pins[eint_num].index;struct irq_data *d;if (!eint->hw->db_time)
@@ -432,8 +452,8 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_num, eint_offset = (eint_num %4 ) *8 ; d =irq_get_irq_data (virq); - set_offset = (eint_num /4 ) *4 + eint->regs->dbnc_set; - clr_offset = (eint_num /4 ) *4 + eint->regs->dbnc_clr; + set_offset = (idx /4 ) *4 + eint->regs->dbnc_set; + clr_offset = (idx /4 ) *4 + eint->regs->dbnc_clr;if (!mtk_eint_can_en_debounce (eint, eint_num))return -EINVAL ;
@@ -454,12 +474,12 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_num, } clr_bit =0xff << eint_offset; -writel (clr_bit, eint->base + clr_offset); +writel (clr_bit, eint->base[inst] + clr_offset); bit = ((dbnc <<MTK_EINT_DBNC_SET_DBNC_BITS ) |MTK_EINT_DBNC_SET_EN ) << eint_offset; rst =MTK_EINT_DBNC_RST_BIT << eint_offset; -writel (rst | bit, eint->base + set_offset); +writel (rst | bit, eint->base[inst] + set_offset);/* * Delay a while (more than 2T) to wait for hw debounce counter reset
@@ -487,32 +507,69 @@ EXPORT_SYMBOL_GPL(mtk_eint_find_irq);int mtk_eint_do_init (struct mtk_eint *eint) { -int i; +unsigned int size, i, port, inst =0 ; +struct mtk_pinctrl *hw = (struct mtk_pinctrl *)eint->pctl;/* If clients don't assign a specific regs, let's use generic one */ if (!eint->regs) eint->regs = &mtk_generic_eint_regs; - eint->wake_mask =devm_kcalloc (eint->dev, eint->hw->ports, -sizeof (*eint->wake_mask),GFP_KERNEL ); -if (!eint->wake_mask) + eint->base_pin_num =devm_kmalloc_array (eint->dev, eint->nbase,sizeof (u16), +GFP_KERNEL | __GFP_ZERO); +if (!eint->base_pin_num)return -ENOMEM ; - eint->cur_mask =devm_kcalloc (eint->dev, eint->hw->ports, -sizeof (*eint->cur_mask),GFP_KERNEL ); -if (!eint->cur_mask) -return -ENOMEM ; +if (eint->nbase ==1 ) { + size = eint->hw->ap_num *sizeof (struct mtk_eint_pin ); + eint->pins =devm_kmalloc (eint->dev, size,GFP_KERNEL ); +if (!eint->pins) + goto err_pins; + + eint->base_pin_num[inst] = eint->hw->ap_num; +for (i =0 ; i < eint->hw->ap_num; i++) { + eint->pins[i].instance = inst; + eint->pins[i].index = i; + eint->pins[i].debounce = (i < eint->hw->db_cnt) ?1 :0 ; + } + } - eint->dual_edge =devm_kcalloc (eint->dev, eint->hw->ap_num, -sizeof (int ),GFP_KERNEL ); -if (!eint->dual_edge) -return -ENOMEM ; +if (hw && hw->soc && hw->soc->eint_pin) { + eint->pins = hw->soc->eint_pin; +for (i =0 ; i < eint->hw->ap_num; i++) { + inst = eint->pins[i].instance; +if (inst >= eint->nbase) +continue ; + eint->base_pin_num[inst]++; + } + } + + eint->pin_list =devm_kmalloc (eint->dev, eint->nbase *sizeof (u16 *),GFP_KERNEL ); +if (!eint->pin_list) + goto err_pin_list; + + eint->wake_mask =devm_kmalloc (eint->dev, eint->nbase *sizeof (u32 *),GFP_KERNEL ); +if (!eint->wake_mask) + goto err_wake_mask; + + eint->cur_mask =devm_kmalloc (eint->dev, eint->nbase *sizeof (u32 *),GFP_KERNEL ); +if (!eint->cur_mask) + goto err_cur_mask; + +for (i =0 ; i < eint->nbase; i++) { + eint->pin_list[i] =devm_kzalloc (eint->dev, eint->base_pin_num[i] *sizeof (u16), +GFP_KERNEL ); + port =DIV_ROUND_UP (eint->base_pin_num[i],32 ); + eint->wake_mask[i] =devm_kzalloc (eint->dev, port *sizeof (u32),GFP_KERNEL ); + eint->cur_mask[i] =devm_kzalloc (eint->dev, port *sizeof (u32),GFP_KERNEL ); +if (!eint->pin_list[i] || !eint->wake_mask[i] || !eint->cur_mask[i]) + goto err_eint; + } eint->domain =irq_domain_add_linear (eint->dev->of_node, eint->hw->ap_num, &irq_domain_simple_ops,NULL );if (!eint->domain) -return -ENOMEM ; + goto err_eint;if (eint->hw->db_time) {for (i =0 ; i <MTK_EINT_DBNC_MAX ; i++)
@@ -523,8 +580,11 @@ int mtk_eint_do_init(struct mtk_eint *eint)mtk_eint_hw_init (eint);for (i =0 ; i < eint->hw->ap_num; i++) { + inst = eint->pins[i].instance; +if (inst >= eint->nbase) +continue ; + eint->pin_list[inst][eint->pins[i].index] = i;int virq =irq_create_mapping (eint->domain, i); -irq_set_chip_and_handler (virq, &mtk_eint_irq_chip, handle_level_irq);irq_set_chip_data (virq, eint);
@@ -534,6 +594,27 @@ int mtk_eint_do_init(struct mtk_eint *eint) eint);return 0 ; + +err_eint: +for (i =0 ; i < eint->nbase; i++) { +if (eint->cur_mask[i]) +devm_kfree (eint->dev, eint->cur_mask[i]); +if (eint->wake_mask[i]) +devm_kfree (eint->dev, eint->wake_mask[i]); +if (eint->pin_list[i]) +devm_kfree (eint->dev, eint->pin_list[i]); + } +devm_kfree (eint->dev, eint->cur_mask); +err_cur_mask: +devm_kfree (eint->dev, eint->wake_mask); +err_wake_mask: +devm_kfree (eint->dev, eint->pin_list); +err_pin_list: +if (eint->nbase ==1 ) +devm_kfree (eint->dev, eint->pins); +err_pins: +devm_kfree (eint->dev, eint->base_pin_num); +return -ENOMEM ; }EXPORT_SYMBOL_GPL (mtk_eint_do_init);
drivers/pinctrl/mediatek/mtk-eint.h +18 -5
@@ -1,10 +1,11 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* Copyright (C) 2014-2018 MediaTek Inc. +* Copyright (C) 2014-2025 MediaTek Inc. * * Author: Maoguang Meng <[email protected]> * Sean Wang <[email protected]> -* +* Hao Chang <[email protected]> +* Qingliang Li <[email protected]> */ #ifndef __MTK_EINT_H#define __MTK_EINT_H
@@ -40,6 +41,14 @@ struct mtk_eint_hw {const unsigned int *db_time; }; +struct mtk_eint_pin { +u16 number; +u8 instance; +u8 index; +bool debounce; +bool dual_edge; +}; +extern const unsigned int debounce_time_mt2701[];extern const unsigned int debounce_time_mt6765[];extern const unsigned int debounce_time_mt6795[];
@@ -56,17 +65,21 @@ struct mtk_eint_xt {struct mtk_eint {struct device *dev; -void __iomem *base; +void __iomem **base; +u8 nbase; +u16 *base_pin_num;struct irq_domain *domain;int irq;int *dual_edge; -u32 *wake_mask; -u32 *cur_mask; +u16 **pin_list; +u32 **wake_mask; +u32 **cur_mask;/* Used to fit into various EINT device */ const struct mtk_eint_hw *hw;const struct mtk_eint_regs *regs; +struct mtk_eint_pin *pins;u16 num_db_time;/* Used to fit into various pinctrl device */
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +31 -6
@@ -13,6 +13,7 @@#include <linux/platform_device.h> #include <linux/io.h> #include <linux/module.h> +#include <linux/of_address.h> #include <linux/of_irq.h> #include "mtk-eint.h"
@@ -367,7 +368,7 @@ static const struct mtk_eint_xt mtk_eint_xt = {int mtk_build_eint (struct mtk_pinctrl *hw,struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node; -int ret; +int ret, i, j, count_reg_names;if (!IS_ENABLED (CONFIG_EINT_MTK ))return 0 ;
@@ -379,10 +380,24 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)if (!hw->eint)return -ENOMEM ; - hw->eint->base =devm_platform_ioremap_resource_byname (pdev,"eint" ); -if (IS_ERR (hw->eint->base)) { - ret =PTR_ERR (hw->eint->base); - goto err_free_eint; + count_reg_names =of_property_count_strings (np,"reg-names" ); +if (count_reg_names < hw->soc->nbase_names) +return -EINVAL ; + + hw->eint->nbase = count_reg_names - hw->soc->nbase_names; + hw->eint->base =devm_kmalloc_array (&pdev->dev, hw->eint->nbase, +sizeof (*hw->eint->base),GFP_KERNEL | __GFP_ZERO); +if (!hw->eint->base) { + ret = -ENOMEM ; + goto err_free_base; + } + +for (i = hw->soc->nbase_names, j =0 ; i < count_reg_names; i++, j++) { + hw->eint->base[j] =of_iomap (np, i); +if (IS_ERR (hw->eint->base[j])) { + ret =PTR_ERR (hw->eint->base[j]); + goto err_free_eint; + } } hw->eint->irq =irq_of_parse_and_map (np,0 );
@@ -401,9 +416,19 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev) hw->eint->pctl = hw; hw->eint->gpio_xlate = &mtk_eint_xt; -return mtk_eint_do_init (hw->eint); + ret =mtk_eint_do_init (hw->eint); +if (ret) + goto err_free_eint; + +return 0 ; err_free_eint: +for (j =0 ; j < hw->eint->nbase; j++) { +if (hw->eint->base[j]) +iounmap (hw->eint->base[j]); + } +devm_kfree (hw->dev, hw->eint->base); +err_free_base:devm_kfree (hw->dev, hw->eint); hw->eint =NULL ;return ret;
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h +1 -0
@@ -241,6 +241,7 @@ struct mtk_pin_soc {unsigned int nfuncs;const struct mtk_eint_regs *eint_regs;const struct mtk_eint_hw *eint_hw; +struct mtk_eint_pin *eint_pin;/* Specific parameters per SoC */ u8 gpio_m;
drivers/pinctrl/mediatek/pinctrl-paris.h +7 -0
@@ -49,6 +49,13 @@ __VA_ARGS__, { } }, \ } +#define MTK_EINT_PIN (_number, _instance, _index, _debounce) { \ + .number = _number, \ + .instance = _instance, \ + .index = _index, \ + .debounce = _debounce, \ + } +#define PINCTRL_PIN_GROUP (_name_, id) \ { \ .name = _name_, \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 717/1191 pinctrl: mediatek: Fix the invalid conditions
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao Chang <[email protected]>
[ Upstream commit 86dee87f4b2e6ac119b03810e58723d0b27787a4 ]
The variable count_reg_names is defined as an int type and cannot be directly compared to an unsigned int. To resolve this issue, first verify the correctness of count_reg_names.
Stable-dep-of: 88292b7103d2 ("pinctrl: mediatek: free EINT resources on unbind")
--- drivers/pinctrl/mediatek/mtk-eint.c | 4 ++-- drivers/pinctrl/mediatek/mtk-eint.h | 2 +- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/pinctrl/mediatek/mtk-eint.c +2 -2
@@ -507,7 +507,7 @@ EXPORT_SYMBOL_GPL(mtk_eint_find_irq);int mtk_eint_do_init (struct mtk_eint *eint) { -unsigned int size, i, port, inst =0 ; +unsigned int size, i, port, virq, inst =0 ;struct mtk_pinctrl *hw = (struct mtk_pinctrl *)eint->pctl;/* If clients don't assign a specific regs, let's use generic one */
@@ -584,7 +584,7 @@ int mtk_eint_do_init(struct mtk_eint *eint)if (inst >= eint->nbase)continue ; eint->pin_list[inst][eint->pins[i].index] = i; -int virq =irq_create_mapping (eint->domain, i); + virq =irq_create_mapping (eint->domain, i);irq_set_chip_and_handler (virq, &mtk_eint_irq_chip, handle_level_irq);irq_set_chip_data (virq, eint);
drivers/pinctrl/mediatek/mtk-eint.h +1 -1
@@ -66,7 +66,7 @@ struct mtk_eint_xt {struct mtk_eint {struct device *dev;void __iomem **base; -u8 nbase; +int nbase;u16 *base_pin_num;struct irq_domain *domain;int irq;
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +5 -2
@@ -381,10 +381,13 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)return -ENOMEM ; count_reg_names =of_property_count_strings (np,"reg-names" ); -if (count_reg_names < hw->soc->nbase_names) +if (count_reg_names <0 ) +return -EINVAL ; + + hw->eint->nbase = count_reg_names - (int )hw->soc->nbase_names; +if (hw->eint->nbase <=0 )return -EINVAL ; - hw->eint->nbase = count_reg_names - hw->soc->nbase_names; hw->eint->base =devm_kmalloc_array (&pdev->dev, hw->eint->nbase,sizeof (*hw->eint->base),GFP_KERNEL | __GFP_ZERO);if (!hw->eint->base) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 718/1191 pinctrl: mediatek: eint: Fix invalid pointer dereference for v1 platforms
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nícolas F. R. A. Prado <[email protected]>
[ Upstream commit 1c9977b263475373b31bbf86af94a5c9ae2be42c ]
Commit 3ef9f710efcb ("pinctrl: mediatek: Add EINT support for multiple addresses") introduced an access to the 'soc' field of struct mtk_pinctrl in mtk_eint_do_init() and for that an include of pinctrl-mtk-common-v2.h.
However, pinctrl drivers relying on the v1 common driver include pinctrl-mtk-common.h instead, which provides another definition of struct mtk_pinctrl that does not contain an 'soc' field.
Since mtk_eint_do_init() can be called both by v1 and v2 drivers, it will now try to dereference an invalid pointer when called on v1 platforms. This has been observed on Genio 350 EVK (MT8365), which crashes very early in boot (the kernel trace can only be seen with earlycon).
In order to fix this, since 'struct mtk_pinctrl' was only needed to get a 'struct mtk_eint_pin', make 'struct mtk_eint_pin' a parameter of mtk_eint_do_init() so that callers need to supply it, removing mtk_eint_do_init()'s dependency on any particular 'struct mtk_pinctrl'.
Stable-dep-of: 88292b7103d2 ("pinctrl: mediatek: free EINT resources on unbind")
--- drivers/pinctrl/mediatek/mtk-eint.c | 26 ++++++++----------- drivers/pinctrl/mediatek/mtk-eint.h | 5 ++-- .../pinctrl/mediatek/pinctrl-mtk-common-v2.c | 2 +- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 2 +- 4 files changed, 16 insertions(+), 19 deletions(-)
drivers/pinctrl/mediatek/mtk-eint.c +11 -15
@@ -22,7 +22,6 @@#include <linux/platform_device.h> #include "mtk-eint.h" -#include "pinctrl-mtk-common-v2.h" #define MTK_EINT_EDGE_SENSITIVE 0#define MTK_EINT_LEVEL_SENSITIVE 1
@@ -505,10 +504,9 @@ int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n) }EXPORT_SYMBOL_GPL (mtk_eint_find_irq); -int mtk_eint_do_init (struct mtk_eint *eint) +int mtk_eint_do_init (struct mtk_eint *eint,struct mtk_eint_pin *eint_pin) {unsigned int size, i, port, virq, inst =0 ; -struct mtk_pinctrl *hw = (struct mtk_pinctrl *)eint->pctl;/* If clients don't assign a specific regs, let's use generic one */ if (!eint->regs)
@@ -519,7 +517,15 @@ int mtk_eint_do_init(struct mtk_eint *eint)if (!eint->base_pin_num)return -ENOMEM ; -if (eint->nbase ==1 ) { +if (eint_pin) { + eint->pins = eint_pin; +for (i =0 ; i < eint->hw->ap_num; i++) { + inst = eint->pins[i].instance; +if (inst >= eint->nbase) +continue ; + eint->base_pin_num[inst]++; + } + }else { size = eint->hw->ap_num *sizeof (struct mtk_eint_pin ); eint->pins =devm_kmalloc (eint->dev, size,GFP_KERNEL );if (!eint->pins)
@@ -533,16 +539,6 @@ int mtk_eint_do_init(struct mtk_eint *eint) } } -if (hw && hw->soc && hw->soc->eint_pin) { - eint->pins = hw->soc->eint_pin; -for (i =0 ; i < eint->hw->ap_num; i++) { - inst = eint->pins[i].instance; -if (inst >= eint->nbase) -continue ; - eint->base_pin_num[inst]++; - } - } - eint->pin_list =devm_kmalloc (eint->dev, eint->nbase *sizeof (u16 *),GFP_KERNEL );if (!eint->pin_list) goto err_pin_list;
@@ -610,7 +606,7 @@ int mtk_eint_do_init(struct mtk_eint *eint) err_wake_mask:devm_kfree (eint->dev, eint->pin_list); err_pin_list: -if (eint->nbase ==1 ) +if (!eint_pin)devm_kfree (eint->dev, eint->pins); err_pins:devm_kfree (eint->dev, eint->base_pin_num);
drivers/pinctrl/mediatek/mtk-eint.h +3 -2
@@ -88,7 +88,7 @@ struct mtk_eint { };#if IS_ENABLED (CONFIG_EINT_MTK ) -int mtk_eint_do_init (struct mtk_eint *eint); +int mtk_eint_do_init (struct mtk_eint *eint,struct mtk_eint_pin *eint_pin);int mtk_eint_do_suspend (struct mtk_eint *eint);int mtk_eint_do_resume (struct mtk_eint *eint); int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,
@@ -96,7 +96,8 @@ int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,int mtk_eint_find_irq (struct mtk_eint *eint,unsigned long eint_n);#else -static inline int mtk_eint_do_init (struct mtk_eint *eint) +static inline int mtk_eint_do_init (struct mtk_eint *eint, +struct mtk_eint_pin *eint_pin) {return -EOPNOTSUPP ; }
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +1 -1
@@ -419,7 +419,7 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev) hw->eint->pctl = hw; hw->eint->gpio_xlate = &mtk_eint_xt; - ret =mtk_eint_do_init (hw->eint); + ret =mtk_eint_do_init (hw->eint, hw->soc->eint_pin);if (ret) goto err_free_eint;
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +1 -1
@@ -1030,7 +1030,7 @@ static int mtk_eint_init(struct mtk_pinctrl *pctl, struct platform_device *pdev) pctl->eint->pctl = pctl; pctl->eint->gpio_xlate = &mtk_eint_xt; -return mtk_eint_do_init (pctl->eint); +return mtk_eint_do_init (pctl->eint,NULL ); }/* This is used as a common probe function */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 719/1191 pinctrl: mediatek: free EINT resources on unbind
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Yeh <[email protected]>
[ Upstream commit 88292b7103d260e3e606eb3bb2794060a5fde48e ]
mtk_eint_do_init() creates an IRQ domain, populates it with a mapping for every EINT line and installs a chained handler on the parent interrupt, but none of these are ever released. This was harmless while the drivers were built-in, but now that they can be built as modules and unbound/rmmod'd it leaves behind a dangling IRQ domain, interrupt mappings whose chip data points at freed memory, and a chained handler that keeps firing into that freed data.
The plain allocations in mtk_eint_do_init() already use the device-managed devm_*() helpers, so tear the remaining resources down the same way:
register a devm action that detaches the chained handler, waits for any in-flight handler to finish, disposes of the per-line mappings and removes the IRQ domain. This mirrors the device-managed lifecycle adopted for the GPIO chip and keeps the whole EINT setup self-cleaning on unbind.
--- drivers/pinctrl/mediatek/mtk-eint.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/pinctrl/mediatek/mtk-eint.c +24 -1
@@ -12,8 +12,10 @@*/ #include <linux/delay.h> +#include <linux/device.h> #include <linux/err.h> #include <linux/gpio/driver.h> +#include <linux/interrupt.h> #include <linux/io.h> #include <linux/irqchip/chained_irq.h> #include <linux/irqdomain.h>
@@ -504,6 +506,27 @@ int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n) }EXPORT_SYMBOL_GPL (mtk_eint_find_irq); +static void mtk_eint_teardown (void *data) +{ +struct mtk_eint *eint = data; +unsigned int i, virq; + +/* Detach the demux handler so it can no longer reference freed data. */ +irq_set_chained_handler_and_data (eint->irq,NULL ,NULL ); + +/* Wait for any in-flight handler to finish before tearing down. */ +synchronize_irq (eint->irq); + +/* Dispose of all child mappings before the domain is removed. */ +for (i =0 ; i < eint->hw->ap_num; i++) { + virq =irq_find_mapping (eint->domain, i); +if (virq) +irq_dispose_mapping (virq); + } + +irq_domain_remove (eint->domain); +} +int mtk_eint_do_init (struct mtk_eint *eint,struct mtk_eint_pin *eint_pin) {unsigned int size, i, port, virq, inst =0 ;
@@ -589,7 +612,7 @@ int mtk_eint_do_init(struct mtk_eint *eint, struct mtk_eint_pin *eint_pin)irq_set_chained_handler_and_data (eint->irq, mtk_eint_irq_handler, eint); -return 0 ; +return devm_add_action_or_reset (eint->dev, mtk_eint_teardown, eint); err_eint:for (i =0 ; i < eint->nbase; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 720/1191 tools/build: Add bpftool-skeletons feature test
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tomas Glozar <[email protected]>
[ Upstream commit 8a635c3856ddb74ed3fe7c856b271cdfeb65f293 ]
Add bpftool-skeletons feature test, testing the presence of a bpftool capable of generating skeletons.
This is to be used for tools that do not require building their own bootstrap bpftool from the kernel source tree.
Stable-dep-of: d5a1d1270c89 ("tools/build: Allow versioning of all LLVM tools defined in Makefile.include")
--- tools/build/Makefile.feature | 3 ++- tools/build/feature/Makefile | 3 +++ tools/scripts/Makefile.include | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-)
tools/build/Makefile.feature +2 -1
@@ -107,7 +107,8 @@ FEATURE_TESTS_EXTRA := \ libbpf-bpf_create_map \ libpfm4 \ libdebuginfod \ - clang-bpf-co-re + clang-bpf-co-re \ + bpftool-skeletons FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
tools/build/feature/Makefile +3 -0
@@ -380,6 +380,9 @@ $(OUTPUT)test-file-handle.bin: $(OUTPUT)test-libpfm4.bin: $(BUILD) -lpfm +$(OUTPUT)test-bpftool-skeletons.bin: + $(BPFTOOL) version | grep '^features:.*skeletons' \ + > $(@:.bin=.make.output) 2>&1 ############################### clean:
tools/scripts/Makefile.include +3 -0
@@ -91,6 +91,9 @@ LLVM_CONFIG ?= llvm-config LLVM_OBJCOPY ?= llvm-objcopy LLVM_STRIP ?= llvm-strip +# Some tools require bpftool +BPFTOOL ?= bpftool + ifeq ($(CC_NO_CLANG), 1) EXTRA_WARNINGS += -Wstrict-aliasing=3
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 721/1191 tools/build: Allow versioning of all LLVM tools defined in Makefile.include
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit d5a1d1270c898057afc5b51fb6d0f2defa89d56d ]
The version of LLVM tools can be given on the build command with LLVM=-15, but this isn't applied to all tools. For example $(CC) gets versioned, but $(CLANG) doesn't. This causes a Perf build with LTO=1 to fail with an error about mixed clang versions:
ld.lld: error: libperf/core.o: Unknown attribute kind (86)
(Producer: 'LLVM18.1.8' Reader: 'LLVM 15.0.7')
This file has two "ifneq ($(LLVM),)" blocks adjacent to each other, so merge these blocks making it obvious that all tools should be versioned consistently and there is nothing special about each block.
This also reveals that ?= and "allow-override" are used inconsistently between the blocks. "allow-override" is technically only required for builtin variables, but isn't only used on them, and doesn't do any harm if used on a non-builtin. Make them all "allow-override" for consistency. The only functional difference this will cause is if there is a file level definition of one of the variables followed by an "#include of Makefile.include" which will now overwrite. But this isn't done and in a later commit some of the duplicate definitions will be removed for good measure.
There are also some other LLVM tools that are not defined here and will be moved in a later commit.
--- tools/scripts/Makefile.include | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-)
tools/scripts/Makefile.include +20 -17
@@ -59,10 +59,18 @@ LLVM_SUFFIX := $(LLVM) endif $(call allow-override,CC,$(LLVM_PREFIX)clang$(LLVM_SUFFIX)) +$(call allow-override,CLANG,$(LLVM_PREFIX)clang$(LLVM_SUFFIX)) +$(call allow-override,HOSTCC,$(LLVM_PREFIX)clang$(LLVM_SUFFIX)) $(call allow-override,AR,$(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)) +$(call allow-override,HOSTAR,$(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)) $(call allow-override,LD,$(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)) +$(call allow-override,HOSTLD,$(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)) $(call allow-override,CXX,$(LLVM_PREFIX)clang++$(LLVM_SUFFIX)) $(call allow-override,STRIP,$(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)) +$(call allow-override,LLVM_STRIP,$(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)) +$(call allow-override,LLC,$(LLVM_PREFIX)llc$(LLVM_SUFFIX)) +$(call allow-override,LLVM_CONFIG,$(LLVM_PREFIX)llvm-config$(LLVM_SUFFIX)) +$(call allow-override,LLVM_OBJCOPY,$(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)) else # Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. $(call allow-override,CC,$(CROSS_COMPILE)gcc)
@@ -70,26 +78,21 @@ $(call allow-override,AR,$(CROSS_COMPILE)ar) $(call allow-override,LD,$(CROSS_COMPILE)ld) $(call allow-override,CXX,$(CROSS_COMPILE)g++) $(call allow-override,STRIP,$(CROSS_COMPILE)strip) -endif - -CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) -ifneq ($(LLVM),) -HOSTAR ?= $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX) -HOSTCC ?= $(LLVM_PREFIX)clang$(LLVM_SUFFIX) -HOSTLD ?= $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX) -else -HOSTAR ?= ar -HOSTCC ?= gcc -HOSTLD ?= ld +# Host versions aren't prefixed +$(call allow-override,HOSTAR,ar) +$(call allow-override,HOSTCC,gcc) +$(call allow-override,HOSTLD,ld) + +# Some tools still require Clang, LLC and/or LLVM utils +$(call allow-override,CLANG,clang) +$(call allow-override,LLC,llc) +$(call allow-override,LLVM_CONFIG,llvm-config) +$(call allow-override,LLVM_OBJCOPY,llvm-objcopy) +$(call allow-override,LLVM_STRIP,llvm-strip) endif -# Some tools require Clang, LLC and/or LLVM utils -CLANG ?= clang -LLC ?= llc -LLVM_CONFIG ?= llvm-config -LLVM_OBJCOPY ?= llvm-objcopy -LLVM_STRIP ?= llvm-strip +CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) # Some tools require bpftool BPFTOOL ?= bpftool
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 722/1191 power: supply: sbs-battery: Use a per-device serial number buffer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Babanpreet Singh <[email protected]>
[ Upstream commit 6027892925b8d19d2245c2d077e2ae35b49cc2b1 ]
sbs_get_battery_serial_number() formats the battery serial number into sbs_serial[], a single file-scope buffer shared by every sbs-battery instance, and points val->strval at it.
Nothing restricts this driver to one instance. It binds per I2C client, and sbs-manager registers one muxed I2C channel per supported battery specifically so that the smart battery driver can be bound to each of them, so several sbs-battery instances on one system is a supported configuration.
The power supply core reads strval after the driver's get_property() callback has returned: power_supply_show_property() fills a local union power_supply_propval, then formats it with sysfs_emit(). Two concurrent POWER_SUPPLY_PROP_SERIAL_NUMBER reads on different batteries therefore race for the shared buffer - battery B's sprintf() can land between battery A filling the buffer and the core reading it, and battery A then reports battery B's serial number.
Move the buffer into struct sbs_info so that each battery formats into its own storage. It is deliberately not added to the chip->strings[]
array: those entries hold the cached constant strings that sbs_invalidate_cached_props() clears on presence changes, whereas the serial number is re-read from its word register on every access.
--- drivers/power/supply/sbs-battery.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/power/supply/sbs-battery.c +4 -3
@@ -216,6 +216,7 @@ struct sbs_info {u32 flags;int technology;char strings[NR_STRING_BUFFERS ][I2C_SMBUS_BLOCK_MAX +1 ]; +char serial[5 ]; }; static char *sbs_get_string_buf(struct sbs_info *chip,
@@ -820,18 +821,18 @@ static int sbs_get_battery_capacity(struct i2c_client *client,return 0 ; } -static char sbs_serial[5 ];static int sbs_get_battery_serial_number (struct i2c_client *client,union power_supply_propval *val) { +struct sbs_info *chip =i2c_get_clientdata (client);int ret; ret =sbs_read_word_data (client, sbs_data[REG_SERIAL_NUMBER ].addr);if (ret <0 )return ret; -sprintf (sbs_serial,"%04x" , ret); - val->strval = sbs_serial; +sprintf (chip->serial,"%04x" , ret); + val->strval = chip->serial;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 723/1191 scsi: ufs: debugfs: Reserve space for a string terminator
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Qiang <[email protected]>
[ Upstream commit abd26e6b53c4169122d61fdd4cabe09bdd916aac ]
ufs_saved_err_write() copies user input into a zero-initialized stack buffer and passes it to kstrtoint(). A write that fills the entire buffer overwrites its only terminator.
Reject an input whose length leaves no room for the trailing NUL.
--- drivers/ufs/core/ufs-debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufs-debugfs.c +1 -1
@@ -165,7 +165,7 @@ static ssize_t ufs_saved_err_write(struct file *file, const char __user *buf,char val_str[16 ] = { };int val, ret; -if (count >sizeof (val_str)) +if (count >=sizeof (val_str))return -EINVAL ;if (copy_from_user (val_str, buf, count))return -EFAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 724/1191 crypto: keembay - Initialize completion before requesting IRQ
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
[ Upstream commit fce20289dd622cc7ab78d72c8a979a9f8b7cb10e ]
kmb_ocs_aes_probe() requests the device IRQ before initializing irq_completion. Once the handler is registered it can run immediately, and ocs_aes_irq_handler() unconditionally calls complete(). An interrupt in this window would therefore use an uninitialized completion.
Initialize the completion before requesting the IRQ, as the sibling OCS HCU and ECC drivers already do.
--- drivers/crypto/keembay/keembay-ocs-aes-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/keembay/keembay-ocs-aes-core.c +2 -2
@@ -1619,6 +1619,8 @@ static int kmb_ocs_aes_probe(struct platform_device *pdev)if (IS_ERR (aes_dev->base_reg))return PTR_ERR (aes_dev->base_reg); +init_completion (&aes_dev->irq_completion); +/* Get and request IRQ */ aes_dev->irq =platform_get_irq (pdev,0 );if (aes_dev->irq <0 )
@@ -1636,8 +1638,6 @@ static int kmb_ocs_aes_probe(struct platform_device *pdev)list_add_tail (&aes_dev->list, &ocs_aes.dev_list);spin_unlock (&ocs_aes.lock); -init_completion (&aes_dev->irq_completion); -/* Initialize crypto engine */ aes_dev->engine =crypto_engine_alloc_init (dev, true);if (!aes_dev->engine) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 725/1191 crypto: keembay - publish OF module alias for OCS AES/SM4
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
[ Upstream commit 0a94091e29f914e4f233a208599ca4055882c01b ]
The Keem Bay OCS AES/SM4 driver has an OF match table wired to .of_match_table, but does not export the table with MODULE_DEVICE_TABLE().
Although the match table lives in keembay-ocs-aes-core.o, that object is part of the composite keembay-ocs-aes module. Add the missing MODULE_DEVICE_TABLE(of, ...) entry so modpost can generate OF module alias information for OF based module autoloading.
This is a source-level fix. It does not claim dynamic hardware reproduction; the evidence is the driver-owned match table, its use by the platform driver, and the missing module alias publication.
--- drivers/crypto/keembay/keembay-ocs-aes-core.c | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/keembay/keembay-ocs-aes-core.c +1 -0
@@ -1574,6 +1574,7 @@ static const struct of_device_id kmb_ocs_aes_of_match[] = { }, {} }; +MODULE_DEVICE_TABLE (of, kmb_ocs_aes_of_match);static int kmb_ocs_aes_remove (struct platform_device *pdev) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 726/1191 RDMA/mlx5: Fix integer overflow of user QP buffer size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maher Sanalla <[email protected]>
[ Upstream commit dec47e4b0fe34afdf38caa72b4408ba95502e5de ]
set_user_buf_size() computes the QP buffer size by left-shifting the user-supplied rq.wqe_cnt and rq.wqe_shift values as signed integers. A sufficiently large rq.wqe_cnt causes signed integer overflow, which is undefined behavior, and yields a small or negative buf_size, causing ib_umem_get() to map a buffer smaller than the hardware will actually write into.
Replace the shifts and addition with check_shl_overflow() and check_add_overflow(), rejecting invalid user inputs.
Moreover, guard the identical shift computing qp->sq.offset in _create_user_qp() before set_user_buf_size() is reached.
--- drivers/infiniband/hw/mlx5/qp.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +20 -5
@@ -591,6 +591,7 @@ static int set_user_buf_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr) {int desc_sz =1 << qp->sq.wqe_shift; +int rq_buf_size, sq_buf_size;if (desc_sz >MLX5_CAP_GEN (dev->mdev, max_wqe_sz_sq)) { mlx5_ib_warn(dev, "desc_sz %d, max_sq_desc_sz %d\n",
@@ -615,11 +616,21 @@ static int set_user_buf_size(struct mlx5_ib_dev *dev,if (attr->qp_type ==IB_QPT_RAW_PACKET || qp->flags &IB_QP_CREATE_SOURCE_QPN ) { - base->ubuffer.buf_size = qp->rq.wqe_cnt << qp->rq.wqe_shift; - qp->raw_packet_qp.sq.ubuffer.buf_size = qp->sq.wqe_cnt <<6 ; +if (check_shl_overflow (qp->rq.wqe_cnt, qp->rq.wqe_shift, + &base->ubuffer.buf_size)) +return -EINVAL ; +if (check_shl_overflow (qp->sq.wqe_cnt,6 , + &qp->raw_packet_qp.sq.ubuffer.buf_size)) +return -EINVAL ; }else { - base->ubuffer.buf_size = (qp->rq.wqe_cnt << qp->rq.wqe_shift) + - (qp->sq.wqe_cnt <<6 ); +if (check_shl_overflow (qp->rq.wqe_cnt, qp->rq.wqe_shift, + &rq_buf_size)) +return -EINVAL ; +if (check_shl_overflow (qp->sq.wqe_cnt,6 , &sq_buf_size)) +return -EINVAL ; +if (check_add_overflow (rq_buf_size, sq_buf_size, + &base->ubuffer.buf_size)) +return -EINVAL ; }return 0 ;
@@ -943,7 +954,11 @@ static int _create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, qp->rq.offset =0 ; qp->sq.wqe_shift =ilog2 (MLX5_SEND_WQE_BB ); - qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; +if (check_shl_overflow (qp->rq.wqe_cnt, qp->rq.wqe_shift, + &qp->sq.offset)) { + err = -EINVAL ; + goto err_bfreg; + } err =set_user_buf_size (dev, qp, ucmd, base, attr);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 727/1191 isofs: release zisofs block pointer buffer head
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
[ Upstream commit 2f7dd9b86fe4076059e6a4a2a2c5d565afd76b9e ]
zisofs_fill_pages() reads the compressed block pointer table. The error paths release the current buffer_head, the loop also releases the old buffer_head when it advances. However, the success path leaves the last buffer_head referenced. Release it before returning success.
--- fs/isofs/compress.c | 1 + 1 file changed, 1 insertion(+)
fs/isofs/compress.c +1 -0
@@ -293,6 +293,7 @@ static int zisofs_fill_pages(struct inode *inode, int full_page, int pcount,memzero_page (*pages, poffset,PAGE_SIZE - poffset);SetPageUptodate (*pages); } +brelse (bh);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 728/1191 w1: ds2482: Fix signedness bug in ds2482_w1_triplet()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Babanpreet Singh <[email protected]>
[ Upstream commit 4d3721b204f961e905714954ff95633337b768e3 ]
ds2482_wait_1wire_idle() returns the status register value (0..255) on success, or a negative value on I2C failure: -1 when selecting the status register fails, or a negative errno from i2c_smbus_read_byte().
ds2482_w1_triplet() feeds that result into "return (status >> 5);" without checking for errors, and the function returns u8. For a negative status the arithmetic shift keeps the sign and the u8 truncation fabricates a triplet result whose meaning depends on the errno value: -1 and -EIO happen to become 0xff, whose set low bits make w1_search() abort, but -ETIMEDOUT (-110 >> 5 = -4) becomes 0xfc - "devices responded on both branches, wrote 1" - and -EOPNOTSUPP (-95 >> 5 = -3) becomes 0xfd - "only the zero branch responded". w1_search() then continues the ROM search with a fabricated direction bit instead of aborting, and the corrupted id is either rejected by the ROM CRC (existing device missed) or registers a phantom slave.
The function already defines an in-band error value: status is initialized to (3 << 5), which decodes to 3 (both branch bits set, "no device responded") and makes w1_search() terminate the search when sending the triplet command fails. Decode a negative status to the same value.
Found by smatch:drivers/w1/masters/ds2482.c:314 ds2482_w1_triplet() warn: signedness bug returning '(-67108864)'
--- drivers/w1/masters/ds2482.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/w1/masters/ds2482.c +4 -0
@@ -312,6 +312,10 @@ static u8 ds2482_w1_triplet(void *data, u8 dbit)mutex_unlock (&pdev->access_lock); +/* On bus error, decode to 3 (no device responded) to abort the search */ +if (status <0 ) + status =3 <<5 ; +/* Decode the status */ return (status >>5 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 729/1191 remoteproc: core: Drop redundant initialization of ret in rproc_shutdown()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peng Fan <[email protected]>
[ Upstream commit 4531b6bad5af669511c348ad5225d9f697af221b ]
The variable ret is immediately assigned the return value of mutex_lock_interruptible(), making its prior initialization to zero unnecessary. Remove the redundant assignment
No functional changes.
Stable-dep-of: 2482ca875ef5 ("remoteproc: Allow shutdown of crashed processors")
--- drivers/remoteproc/remoteproc_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +1 -1
@@ -1987,7 +1987,7 @@ EXPORT_SYMBOL(rproc_boot);int rproc_shutdown (struct rproc *rproc) {struct device *dev = &rproc->dev; -int ret =0 ; +int ret; ret =mutex_lock_interruptible (&rproc->lock);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 730/1191 remoteproc: Allow shutdown of crashed processors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
[ Upstream commit 2482ca875ef5993df8daee563033d70e2523a25f ]
rproc_shutdown() rejects a remoteproc in RPROC_CRASHED state, and rproc_del() ignores that error. The result of these two decisions is that a user cannot stop a remoteproc that with recovery disabled that has entered a crash state, and removal of an associated remoteproc driver will release resources without first stopping the remoteproc.
Allow rproc_shutdown() to stop crashed processors. Propagate the crash state to subdevice teardown, to allow subdevices to dismantle things appropriately.
--- drivers/remoteproc/remoteproc_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/remoteproc/remoteproc_core.c +5 -2
@@ -1987,6 +1987,7 @@ EXPORT_SYMBOL(rproc_boot);int rproc_shutdown (struct rproc *rproc) {struct device *dev = &rproc->dev; +bool crashed;int ret; ret =mutex_lock_interruptible (&rproc->lock);
@@ -1996,16 +1997,18 @@ int rproc_shutdown(struct rproc *rproc) }if (rproc->state !=RPROC_RUNNING && - rproc->state !=RPROC_ATTACHED ) { + rproc->state !=RPROC_ATTACHED && + rproc->state !=RPROC_CRASHED ) { ret = -EINVAL ; goto out; } + crashed = rproc->state ==RPROC_CRASHED ;/* if the remote proc is still needed, bail out */ if (!atomic_dec_and_test (&rproc->power)) goto out; - ret =rproc_stop (rproc, false); + ret =rproc_stop (rproc, crashed);if (ret) {atomic_inc (&rproc->power); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 731/1191 remoteproc: core: Attach rproc asynchronously in rproc_add() path via schedule_work()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jingyi Wang <[email protected]>
[ Upstream commit 026a3fada43261e403c6c4d9bda9501547e3f108 ]
Unlike the remoteproc firmware load path where rproc_add() call rproc_auto_boot_callback() asynchronously and ignores the return value of rproc_boot(), the attach path calls rproc_boot() synchronously and propagates its return value back to rproc_add(). This means a failure during rproc_attach() causes rproc_add() to fail and triggers resource release, removing the remoteproc from sysfs and making it unavailable for recovery or further boot attempts.
Align the remoteproc attach path with the firmware load path by introducing attach_work and scheduling rproc_boot() asynchronously via schedule_work(). This keeps the remoteproc registered and available in sysfs even if the initial attach attempt fails, and avoids blocking rproc_add() on the attach result.
Stable-dep-of: 74ee3b2f5767 ("remoteproc: Prevent crash handling to race with rproc_del()")
--- drivers/remoteproc/remoteproc_core.c | 20 ++++++++++++-------- include/linux/remoteproc.h | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/remoteproc/remoteproc_core.c +12 -8
@@ -1676,18 +1676,21 @@ static void rproc_auto_boot_callback(const struct firmware *fw, void *context)release_firmware (fw); } +static void rproc_attach_work (struct work_struct *work) +{ + struct rproc *rproc = container_of(work, struct rproc, attach_work); + +rproc_boot (rproc); +} +static int rproc_trigger_auto_boot (struct rproc *rproc) {int ret; -/* -* Since the remote processor is in a detached state, it has already -* been booted by another entity. As such there is no point in waiting -* for a firmware image to be loaded, we can simply initiate the process -* of attaching to it immediately. -*/ -if (rproc->state ==RPROC_DETACHED ) -return rproc_boot (rproc); +if (rproc->state ==RPROC_DETACHED ) { +schedule_work (&rproc->attach_work); +return 0 ; + }/* * We're initiating an asynchronous firmware loading, so we can
@@ -2499,6 +2502,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,INIT_LIST_HEAD (&rproc->dump_segments);INIT_WORK (&rproc->crash_handler, rproc_crash_handler_work); +INIT_WORK (&rproc->attach_work, rproc_attach_work); rproc->state =RPROC_OFFLINE ;
include/linux/remoteproc.h +2 -0
@@ -526,6 +526,7 @@ enum rproc_features {* @subdevs: list of subdevices, to following the running state * @notifyids: idr for dynamically assigning rproc-wide unique notify ids * @index: index of this rproc device +* @attach_work: workqueue for attaching rproc * @crash_handler: workqueue for handling a crash * @crash_cnt: crash counter * @recovery_disabled: flag that state if recovery was disabled
@@ -568,6 +569,7 @@ struct rproc {struct list_head subdevs;struct idr notifyids;int index; +struct work_struct attach_work;struct work_struct crash_handler;unsigned int crash_cnt;bool recovery_disabled;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 732/1191 remoteproc: Prevent crash handling to race with rproc_del()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
[ Upstream commit 74ee3b2f5767447c57959994341e5b95f1079977 ]
There's no synchronization between rproc_crash_handler_work() and rproc_del(), as such it's possible for a driver to be removed while crash-handler work is scheduled, or even executing - resulting in use-after-free issues.
To avoid this the scheduled work need to be cancelled and synchronized against before the removal proceeds.
In order to ensure that this doesn't race with the reporting, and thereby scheduling new work, a "deleting" flag is introduced. This is similar to the RPROC_DELETE state that was introduced to ensure that "start" didn't race with rproc_del(), but the existing mechanism can not be used as it's valid to call rproc_report_crash() in atomic context - and the "state" is protected by a mutex.
In the event that work is cancelled the pm_stay_awake() is left unbalanced and need to be unrolled.
The blocking and cancelling of crash-handler work prior to the actual rproc_shutdown() call does have the explicit side-effect that crashes resulting from the shutdown process will not enter the crash-handling path, and as such will not generate devcoredumps etc. Due to the existing mutual exclusion between these code paths there's no concrete reduction in functionality, but further work would be needed to handle this case.
--- drivers/remoteproc/remoteproc_core.c | 42 +++++++++++++++++++++------ drivers/remoteproc/remoteproc_sysfs.c | 1 - include/linux/remoteproc.h | 13 +++++---- 3 files changed, 41 insertions(+), 15 deletions(-)
drivers/remoteproc/remoteproc_core.c +33 -9
@@ -1839,6 +1839,11 @@ int rproc_trigger_recovery(struct rproc *rproc)if (ret)return ret; +if (READ_ONCE (rproc->deleting)) { + ret = -ENODEV ; + goto unlock_mutex; + } +/* State could have changed before we got the mutex */ if (rproc->state !=RPROC_CRASHED ) goto unlock_mutex;
@@ -1871,6 +1876,11 @@ static void rproc_crash_handler_work(struct work_struct *work)mutex_lock (&rproc->lock); +if (READ_ONCE (rproc->deleting)) { +mutex_unlock (&rproc->lock); + goto out; + } +if (rproc->state ==RPROC_CRASHED ) {/* handle only the first crash detected */ mutex_unlock (&rproc->lock);
@@ -1926,9 +1936,9 @@ int rproc_boot(struct rproc *rproc)return ret; } -if (rproc->state ==RPROC_DELETED ) { +if (READ_ONCE (rproc->deleting)) { ret = -ENODEV ; -dev_err (dev,"can't boot deleted rproc %s\n" , rproc->name); +dev_err (dev,"can't boot deleting rproc %s\n" , rproc->name); goto unlock_mutex; }
@@ -2501,8 +2511,9 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,INIT_LIST_HEAD (&rproc->subdevs);INIT_LIST_HEAD (&rproc->dump_segments); -INIT_WORK (&rproc->crash_handler, rproc_crash_handler_work);INIT_WORK (&rproc->attach_work, rproc_attach_work); +INIT_WORK (&rproc->crash_handler, rproc_crash_handler_work); +spin_lock_init (&rproc->crash_handler_lock); rproc->state =RPROC_OFFLINE ;
@@ -2562,16 +2573,21 @@ EXPORT_SYMBOL(rproc_put);*/ int rproc_del (struct rproc *rproc) { +unsigned long flags; +if (!rproc)return -EINVAL ; +spin_lock_irqsave (&rproc->crash_handler_lock, flags); +WRITE_ONCE (rproc->deleting, true); +spin_unlock_irqrestore (&rproc->crash_handler_lock, flags); + +if (cancel_work_sync (&rproc->crash_handler)) +pm_relax (rproc->dev.parent); +/* TODO: make sure this works with rproc->power > 1 */ rproc_shutdown (rproc); -mutex_lock (&rproc->lock); - rproc->state =RPROC_DELETED ; -mutex_unlock (&rproc->lock); -rproc_delete_debug_dir (rproc);/* the rproc is downref'ed as soon as it's removed from the klist */
@@ -2683,18 +2699,26 @@ EXPORT_SYMBOL(rproc_get_by_child);*/ void rproc_report_crash (struct rproc *rproc,enum rproc_crash_type type) { +unsigned long flags; +if (!rproc) {pr_err ("NULL rproc pointer\n" );return ; } +spin_lock_irqsave (&rproc->crash_handler_lock, flags); +if (READ_ONCE (rproc->deleting)) { +spin_unlock_irqrestore (&rproc->crash_handler_lock, flags); +return ; + } +/* Prevent suspend while the remoteproc is being recovered */ pm_stay_awake (rproc->dev.parent); +queue_work (rproc_recovery_wq, &rproc->crash_handler); +spin_unlock_irqrestore (&rproc->crash_handler_lock, flags);dev_err (&rproc->dev,"crash detected in %s: type %s\n" , rproc->name,rproc_crash_to_string (type)); - -queue_work (rproc_recovery_wq, &rproc->crash_handler); }EXPORT_SYMBOL (rproc_report_crash);
drivers/remoteproc/remoteproc_sysfs.c +0 -1
@@ -168,7 +168,6 @@ static const char * const rproc_state_string[] = { [RPROC_SUSPENDED] = "suspended", [RPROC_RUNNING] = "running", [RPROC_CRASHED] = "crashed", - [RPROC_DELETED] = "deleted", [RPROC_ATTACHED] = "attached", [RPROC_DETACHED] = "detached", [RPROC_LAST] = "invalid",
include/linux/remoteproc.h +8 -5
@@ -37,6 +37,7 @@#include <linux/types.h> #include <linux/mutex.h> +#include <linux/spinlock.h> #include <linux/virtio.h> #include <linux/cdev.h> #include <linux/completion.h>
@@ -412,7 +413,6 @@ struct rproc_ops {* a message. * @RPROC_RUNNING: device is up and running * @RPROC_CRASHED: device has crashed; need to start recovery -* @RPROC_DELETED: device is deleted * @RPROC_ATTACHED: device has been booted by another entity and the core * has attached to it * @RPROC_DETACHED: device has been booted by another entity and waiting
@@ -430,10 +430,9 @@ enum rproc_state {RPROC_SUSPENDED =1 ,RPROC_RUNNING =2 ,RPROC_CRASHED =3 , -RPROC_DELETED =4 , -RPROC_ATTACHED =5 , -RPROC_DETACHED =6 , - RPROC_LAST = 7, +RPROC_ATTACHED =4 , +RPROC_DETACHED =5 , + RPROC_LAST = 6, };/**
@@ -528,6 +527,8 @@ enum rproc_features {* @index: index of this rproc device * @attach_work: workqueue for attaching rproc * @crash_handler: workqueue for handling a crash +* @crash_handler_lock: serializes crash handler queueing and deletion +* @deleting: remoteproc deletion has begun * @crash_cnt: crash counter * @recovery_disabled: flag that state if recovery was disabled * @max_notifyid: largest allocated notify id.
@@ -571,6 +572,8 @@ struct rproc {int index;struct work_struct attach_work;struct work_struct crash_handler; +spinlock_t crash_handler_lock; +bool deleting;unsigned int crash_cnt;bool recovery_disabled;int max_notifyid;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 733/1191 staging: rtl8723bs: use kfree_sensitive() for key material
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivy Lopez <[email protected]>
[ Upstream commit d205dfa8cb825f1954ca1cfa474fc50bf06ee4aa ]
The set_stakey_parm struct contains a 16-byte encryption key. Use kfree_sensitive() instead of kfree() to ensure the key material is zeroed before the memory is freed, preventing potential information leaks.
--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
@@ -895,7 +895,7 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_if (enqueue) { ph2c =rtw_zmalloc (sizeof (struct cmd_obj ));if (!ph2c) { -kfree (psetstakey_para); +kfree_sensitive (psetstakey_para); res = _FAIL; goto exit; }
@@ -903,7 +903,7 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_ psetstakey_rsp =rtw_zmalloc (sizeof (struct set_stakey_rsp ));if (!psetstakey_rsp) {kfree (ph2c); -kfree (psetstakey_para); +kfree_sensitive (psetstakey_para); res = _FAIL; goto exit; }
@@ -914,7 +914,7 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_ res =rtw_enqueue_cmd (pcmdpriv, ph2c); }else {set_stakey_hdl (padapter, (u8 *)psetstakey_para); -kfree (psetstakey_para); +kfree_sensitive (psetstakey_para); } exit:return res;
@@ -954,7 +954,7 @@ u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueu psetstakey_rsp =rtw_zmalloc (sizeof (struct set_stakey_rsp ));if (!psetstakey_rsp) {kfree (ph2c); -kfree (psetstakey_para); +kfree_sensitive (psetstakey_para); res = _FAIL; goto exit; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 734/1191 fs/ntfs3: reject restart table growth beyond U16_MAX entries
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 111f8d74a19d85942ecbb3aba78f6f3c88e59391 ]
During $LogFile replay, log_replay() indexes the transaction table by the transact_id taken from the log record header. check_log_rec() only verifies that transact_id is non-zero and properly aligned, not its magnitude, so a crafted image can request an arbitrarily large index.
alloc_rsttbl_from_idx() grows the table to cover that index via extend_rsttbl(), which passes the new entry count to init_rsttbl():
rt = init_rsttbl(esize, used + add);
used + add is computed as u32 but init_rsttbl() takes a u16, and the count is stored in struct RESTART_TABLE as a __le16. When used + add exceeds U16_MAX it is truncated, init_rsttbl() allocates a table far smaller than the index requires, and alloc_rsttbl_from_idx() then dereferences and writes at the original, untruncated offset -- an out-of-bounds access past the allocation, reachable by mounting a crafted NTFS image.
BUG: KASAN: use-after-free in alloc_rsttbl_from_idx (fs/ntfs3/fslog.c:950) Read of size 4 at addr ffff8880327ffff8 by task exploit alloc_rsttbl_from_idx (fs/ntfs3/fslog.c:950) log_replay (fs/ntfs3/fslog.c:4562) ntfs_loadlog_and_replay (fs/ntfs3/fsntfs.c:324) ntfs_fill_super (fs/ntfs3/super.c:1393) get_tree_bdev_flags vfs_get_tree path_mount __x64_sys_mount
A restart table is limited to U16_MAX entries by its __le16 count, so a larger growth request is invalid input. Reject it in extend_rsttbl(); all callers already handle a NULL return.
--- fs/ntfs3/fslog.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ntfs3/fslog.c +3 -0
@@ -875,6 +875,9 @@ static inline struct RESTART_TABLE *extend_rsttbl(struct RESTART_TABLE *tbl,u32 used =le16_to_cpu (tbl->used);struct RESTART_TABLE *rt; +if (used + add >U16_MAX ) +return NULL ; + rt =init_rsttbl (esize, used + add);if (!rt)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 735/1191 RDMA/efa: Fix PBL chunk length computation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yonatan Nachum <[email protected]>
[ Upstream commit 229b42d7450c1cf96f45ec39ebb69211b06bc036 ]
On register MR, when creating the PBL, if it's an indirect PBL we create a chunk list to hold the PBL pages pointers. Each chunk is 4KB in size and can hold 510 addresses (EFA_PTRS_PER_CHUNK) and has a 12-byte control buffer at the end of it holding the next chunk's pointer and its length.
If the PBL number of pages is a multiple of EFA_PTRS_PER_CHUNK, the calculated last chunk length is wrongly computed as 0, even though that chunk is fully populated with 510 real page pointers. This wrong length is used both to DMA map the chunk and is propagated to the device, causing the device to see the chunk as empty and reject the memory registration.
Fix the calculation so it will be performed only if the number of pages isn't a multiple of EFA_PTRS_PER_CHUNK, if it is, its already handled in the above loop correctly.
Also prevent out-of-bounds reach in the chunks array in such scenario.
--- drivers/infiniband/hw/efa/efa_verbs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/infiniband/hw/efa/efa_verbs.c +9 -4
@@ -1286,9 +1286,11 @@ static int pbl_chunk_list_create(struct efa_dev *dev, struct pbl_context *pbl) chunk_list->chunks[i].length =EFA_CHUNK_USED_SIZE ; } - chunk_list->chunks[chunk_list_size -1 ].length = - ((page_cnt %EFA_PTRS_PER_CHUNK ) *EFA_CHUNK_PAYLOAD_PTR_SIZE ) + -EFA_CHUNK_PTR_SIZE ; + +if (page_cnt %EFA_PTRS_PER_CHUNK !=0 ) + chunk_list->chunks[chunk_list_size -1 ].length = + ((page_cnt %EFA_PTRS_PER_CHUNK ) *EFA_CHUNK_PAYLOAD_PTR_SIZE ) + +EFA_CHUNK_PTR_SIZE ;/* fill the dma addresses of sg list pages to chunks: */ chunk_idx =0 ;
@@ -1300,9 +1302,12 @@ static int pbl_chunk_list_create(struct efa_dev *dev, struct pbl_context *pbl)rdma_block_iter_dma_address (&biter);if (payload_idx ==EFA_PTRS_PER_CHUNK ) { + payload_idx =0 ; chunk_idx++; +if (chunk_idx >= chunk_list_size) +break ; + cur_chunk_buf = chunk_list->chunks[chunk_idx].buf; - payload_idx =0 ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 736/1191 arm64: dts: allwinner: sun50i-a64-pinephone: Fix mpu6050 mount matrix
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ondrej Jirman <[email protected]>
[ Upstream commit dfc735fd93e4814e65894916ec5f807f25a391d1 ]
The current mount matrix for mpu6050 is wrong. The mount matrix is a simple transform from the sensor coordinate space to the device coordinate space described in DT, where, looking at the screen, X points to the right, Y to the top, and Z towards the user.
The mpu6050 is mounted like this (looking at the screen from the front; the sensor is on the near side of the PCB, so its Z axis points towards the user; o marks the pin 1 corner):
+Xs
^
|
+------+
+Ys <--| |
| o |
+------+so this gives:
Xd = -Ys [0, -1, 0] Yd = Xs [1, 0, 0] Zd = Zs [0, 0, 1]
--- arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi +2 -2
@@ -202,8 +202,8 @@ accelerometer@68 { interrupts = <7 5 IRQ_TYPE_EDGE_RISING>; /* PH5 */ vdd-supply = <®_dldo1>; vddio-supply = <®_dldo1>; - mount-matrix = "0", "1", "0", - "-1", "0", "0", + mount-matrix = "0", "-1", "0", + "1", "0", "0", "0", "0", "1"; }; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 737/1191 clk: tegra: tegra124-emc: put EMC node on register failure
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 f726279f5eab813f9a8b6f38ddf2a4b062d038ff ]
tegra124_clk_register_emc() stores a device node reference returned by of_parse_phandle() in tegra->emc_node.
If clk_register() fails, the function returns an error before that reference can be consumed and released by the normal runtime path. The tegra_clk_emc object is freed on this failure path, but freeing the object does not drop the OF node reference stored in it.
Drop the EMC node reference before freeing the tegra_clk_emc object. of_node_put() is safe for a NULL node, so this also covers the case where the phandle is absent.
--- drivers/clk/tegra/clk-tegra124-emc.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/tegra/clk-tegra124-emc.c +1 -0
@@ -539,6 +539,7 @@ struct clk *tegra124_clk_register_emc(void __iomem *base, struct device_node *np clk =clk_register (NULL , &tegra->hw);if (IS_ERR (clk)) { +of_node_put (tegra->emc_node);kfree (tegra);return clk; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 738/1191 clk: palmas: Manage external-control prepare with devm
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit ccda84fcbf3a972973f772384935928f41817b3a ]
palmas_clks_init_configure() prepares the clock when an external control pin is configured. The current driver only drops that prepare reference when external control configuration fails.
If provider registration fails after that point, or if the driver is later removed, the prepare reference remains held.
Register a device-managed action after clk_prepare() succeeds. This balances the prepare reference on subsequent probe failure and driver removal.
--- drivers/clk/clk-palmas.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/clk/clk-palmas.c +13 -1
@@ -195,6 +195,13 @@ static void palmas_clks_get_clk_data(struct platform_device *pdev, cinfo->ext_control_pin = prop; } +static void palmas_clks_unprepare_ext_control (void *data) +{ +struct palmas_clock_info *cinfo = data; + +clk_unprepare (cinfo->hw.clk); +} +static int palmas_clks_init_configure (struct palmas_clock_info *cinfo) {int ret;
@@ -215,13 +222,18 @@ static int palmas_clks_init_configure(struct palmas_clock_info *cinfo)return ret; } + ret =devm_add_action_or_reset (cinfo->dev, + palmas_clks_unprepare_ext_control, + cinfo); +if (ret) +return ret; + ret =palmas_ext_control_req_config (cinfo->palmas, cinfo->clk_desc->sleep_reqstr_id, cinfo->ext_control_pin, true);if (ret <0 ) {dev_err (cinfo->dev,"Ext config for %s failed, %d\n" , cinfo->clk_desc->clk_name, ret); -clk_unprepare (cinfo->hw.clk);return ret; } }
Signature · 1 line
2.53.0