From e9c81ca97e0a1e911d94d6e3a35c732b824907cc Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 20 Jun 2022 11:57:29 +0200 Subject: [PATCH] 5.15-stable patches added patches: cfi-fix-__cfi_slowpath_diag-rcu-usage-with-cpuidle.patch dm-mirror-log-round-up-region-bitmap-size-to-bits_per_long.patch drm-amd-display-cap-oled-brightness-per-max-frame-average-luminance.patch ext4-add-reserved-gdt-blocks-check.patch ext4-fix-bug_on-ext4_mb_use_inode_pa.patch ext4-fix-super-block-checksum-incorrect-after-mount.patch ext4-make-variable-count-signed.patch kvm-arm64-don-t-read-a-hw-interrupt-pending-state-in-user-context.patch --- ...slowpath_diag-rcu-usage-with-cpuidle.patch | 76 +++++++++++++ ...-region-bitmap-size-to-bits_per_long.patch | 39 +++++++ ...ness-per-max-frame-average-luminance.patch | 63 +++++++++++ .../ext4-add-reserved-gdt-blocks-check.patch | 74 ++++++++++++ ...ext4-fix-bug_on-ext4_mb_use_inode_pa.patch | 97 ++++++++++++++++ ...block-checksum-incorrect-after-mount.patch | 73 ++++++++++++ .../ext4-make-variable-count-signed.patch | 35 ++++++ ...errupt-pending-state-in-user-context.patch | 106 ++++++++++++++++++ queue-5.15/series | 8 ++ 9 files changed, 571 insertions(+) create mode 100644 queue-5.15/cfi-fix-__cfi_slowpath_diag-rcu-usage-with-cpuidle.patch create mode 100644 queue-5.15/dm-mirror-log-round-up-region-bitmap-size-to-bits_per_long.patch create mode 100644 queue-5.15/drm-amd-display-cap-oled-brightness-per-max-frame-average-luminance.patch create mode 100644 queue-5.15/ext4-add-reserved-gdt-blocks-check.patch create mode 100644 queue-5.15/ext4-fix-bug_on-ext4_mb_use_inode_pa.patch create mode 100644 queue-5.15/ext4-fix-super-block-checksum-incorrect-after-mount.patch create mode 100644 queue-5.15/ext4-make-variable-count-signed.patch create mode 100644 queue-5.15/kvm-arm64-don-t-read-a-hw-interrupt-pending-state-in-user-context.patch diff --git a/queue-5.15/cfi-fix-__cfi_slowpath_diag-rcu-usage-with-cpuidle.patch b/queue-5.15/cfi-fix-__cfi_slowpath_diag-rcu-usage-with-cpuidle.patch new file mode 100644 index 00000000000..385beef6dae --- /dev/null +++ b/queue-5.15/cfi-fix-__cfi_slowpath_diag-rcu-usage-with-cpuidle.patch @@ -0,0 +1,76 @@ +From 57cd6d157eb479f0a8e820fd36b7240845c8a937 Mon Sep 17 00:00:00 2001 +From: Sami Tolvanen +Date: Tue, 31 May 2022 10:59:10 -0700 +Subject: cfi: Fix __cfi_slowpath_diag RCU usage with cpuidle + +From: Sami Tolvanen + +commit 57cd6d157eb479f0a8e820fd36b7240845c8a937 upstream. + +RCU_NONIDLE usage during __cfi_slowpath_diag can result in an invalid +RCU state in the cpuidle code path: + + WARNING: CPU: 1 PID: 0 at kernel/rcu/tree.c:613 rcu_eqs_enter+0xe4/0x138 + ... + Call trace: + rcu_eqs_enter+0xe4/0x138 + rcu_idle_enter+0xa8/0x100 + cpuidle_enter_state+0x154/0x3a8 + cpuidle_enter+0x3c/0x58 + do_idle.llvm.6590768638138871020+0x1f4/0x2ec + cpu_startup_entry+0x28/0x2c + secondary_start_kernel+0x1b8/0x220 + __secondary_switched+0x94/0x98 + +Instead, call rcu_irq_enter/exit to wake up RCU only when needed and +disable interrupts for the entire CFI shadow/module check when we do. + +Signed-off-by: Sami Tolvanen +Link: https://lore.kernel.org/r/20220531175910.890307-1-samitolvanen@google.com +Fixes: cf68fffb66d6 ("add support for Clang CFI") +Cc: stable@vger.kernel.org +Signed-off-by: Kees Cook +Signed-off-by: Greg Kroah-Hartman +--- + kernel/cfi.c | 22 ++++++++++++++++------ + 1 file changed, 16 insertions(+), 6 deletions(-) + +--- a/kernel/cfi.c ++++ b/kernel/cfi.c +@@ -281,6 +281,8 @@ static inline cfi_check_fn find_module_c + static inline cfi_check_fn find_check_fn(unsigned long ptr) + { + cfi_check_fn fn = NULL; ++ unsigned long flags; ++ bool rcu_idle; + + if (is_kernel_text(ptr)) + return __cfi_check; +@@ -290,13 +292,21 @@ static inline cfi_check_fn find_check_fn + * the shadow and __module_address use RCU, so we need to wake it + * up if necessary. + */ +- RCU_NONIDLE({ +- if (IS_ENABLED(CONFIG_CFI_CLANG_SHADOW)) +- fn = find_shadow_check_fn(ptr); ++ rcu_idle = !rcu_is_watching(); ++ if (rcu_idle) { ++ local_irq_save(flags); ++ rcu_irq_enter(); ++ } + +- if (!fn) +- fn = find_module_check_fn(ptr); +- }); ++ if (IS_ENABLED(CONFIG_CFI_CLANG_SHADOW)) ++ fn = find_shadow_check_fn(ptr); ++ if (!fn) ++ fn = find_module_check_fn(ptr); ++ ++ if (rcu_idle) { ++ rcu_irq_exit(); ++ local_irq_restore(flags); ++ } + + return fn; + } diff --git a/queue-5.15/dm-mirror-log-round-up-region-bitmap-size-to-bits_per_long.patch b/queue-5.15/dm-mirror-log-round-up-region-bitmap-size-to-bits_per_long.patch new file mode 100644 index 00000000000..a9552a7bd19 --- /dev/null +++ b/queue-5.15/dm-mirror-log-round-up-region-bitmap-size-to-bits_per_long.patch @@ -0,0 +1,39 @@ +From 85e123c27d5cbc22cfdc01de1e2ca1d9003a02d0 Mon Sep 17 00:00:00 2001 +From: Mikulas Patocka +Date: Thu, 16 Jun 2022 13:28:57 -0400 +Subject: dm mirror log: round up region bitmap size to BITS_PER_LONG + +From: Mikulas Patocka + +commit 85e123c27d5cbc22cfdc01de1e2ca1d9003a02d0 upstream. + +The code in dm-log rounds up bitset_size to 32 bits. It then uses +find_next_zero_bit_le on the allocated region. find_next_zero_bit_le +accesses the bitmap using unsigned long pointers. So, on 64-bit +architectures, it may access 4 bytes beyond the allocated size. + +Fix this bug by rounding up bitset_size to BITS_PER_LONG. + +This bug was found by running the lvm2 testsuite with kasan. + +Fixes: 29121bd0b00e ("[PATCH] dm mirror log: bitset_size fix") +Cc: stable@vger.kernel.org +Signed-off-by: Mikulas Patocka +Signed-off-by: Mike Snitzer +Signed-off-by: Greg Kroah-Hartman +--- + drivers/md/dm-log.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +--- a/drivers/md/dm-log.c ++++ b/drivers/md/dm-log.c +@@ -415,8 +415,7 @@ static int create_log_context(struct dm_ + /* + * Work out how many "unsigned long"s we need to hold the bitset. + */ +- bitset_size = dm_round_up(region_count, +- sizeof(*lc->clean_bits) << BYTE_SHIFT); ++ bitset_size = dm_round_up(region_count, BITS_PER_LONG); + bitset_size >>= BYTE_SHIFT; + + lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits); diff --git a/queue-5.15/drm-amd-display-cap-oled-brightness-per-max-frame-average-luminance.patch b/queue-5.15/drm-amd-display-cap-oled-brightness-per-max-frame-average-luminance.patch new file mode 100644 index 00000000000..b2c164ed31e --- /dev/null +++ b/queue-5.15/drm-amd-display-cap-oled-brightness-per-max-frame-average-luminance.patch @@ -0,0 +1,63 @@ +From 4fd17f2ac0aa4e48823ac2ede5b050fb70300bf4 Mon Sep 17 00:00:00 2001 +From: Roman Li +Date: Thu, 19 May 2022 14:41:16 -0400 +Subject: drm/amd/display: Cap OLED brightness per max frame-average luminance + +From: Roman Li + +commit 4fd17f2ac0aa4e48823ac2ede5b050fb70300bf4 upstream. + +[Why] +For OLED eDP the Display Manager uses max_cll value as a limit +for brightness control. +max_cll defines the content light luminance for individual pixel. +Whereas max_fall defines frame-average level luminance. +The user may not observe the difference in brightness in between +max_fall and max_cll. +That negatively impacts the user experience. + +[How] +Use max_fall value instead of max_cll as a limit for brightness control. + +Reviewed-by: Rodrigo Siqueira +Acked-by: Hamza Mahfooz +Signed-off-by: Roman Li +Tested-by: Daniel Wheeler +Signed-off-by: Alex Deucher +Cc: stable@vger.kernel.org +Signed-off-by: Greg Kroah-Hartman +--- + drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c ++++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +@@ -2417,7 +2417,7 @@ static struct drm_mode_config_helper_fun + + static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector) + { +- u32 max_cll, min_cll, max, min, q, r; ++ u32 max_avg, min_cll, max, min, q, r; + struct amdgpu_dm_backlight_caps *caps; + struct amdgpu_display_manager *dm; + struct drm_connector *conn_base; +@@ -2447,7 +2447,7 @@ static void update_connector_ext_caps(st + caps = &dm->backlight_caps[i]; + caps->ext_caps = &aconnector->dc_link->dpcd_sink_ext_caps; + caps->aux_support = false; +- max_cll = conn_base->hdr_sink_metadata.hdmi_type1.max_cll; ++ max_avg = conn_base->hdr_sink_metadata.hdmi_type1.max_fall; + min_cll = conn_base->hdr_sink_metadata.hdmi_type1.min_cll; + + if (caps->ext_caps->bits.oled == 1 /*|| +@@ -2475,8 +2475,8 @@ static void update_connector_ext_caps(st + * The results of the above expressions can be verified at + * pre_computed_values. + */ +- q = max_cll >> 5; +- r = max_cll % 32; ++ q = max_avg >> 5; ++ r = max_avg % 32; + max = (1 << q) * pre_computed_values[r]; + + // min luminance: maxLum * (CV/255)^2 / 100 diff --git a/queue-5.15/ext4-add-reserved-gdt-blocks-check.patch b/queue-5.15/ext4-add-reserved-gdt-blocks-check.patch new file mode 100644 index 00000000000..9a77582a077 --- /dev/null +++ b/queue-5.15/ext4-add-reserved-gdt-blocks-check.patch @@ -0,0 +1,74 @@ +From b55c3cd102a6f48b90e61c44f7f3dda8c290c694 Mon Sep 17 00:00:00 2001 +From: Zhang Yi +Date: Wed, 1 Jun 2022 17:27:17 +0800 +Subject: ext4: add reserved GDT blocks check + +From: Zhang Yi + +commit b55c3cd102a6f48b90e61c44f7f3dda8c290c694 upstream. + +We capture a NULL pointer issue when resizing a corrupt ext4 image which +is freshly clear resize_inode feature (not run e2fsck). It could be +simply reproduced by following steps. The problem is because of the +resize_inode feature was cleared, and it will convert the filesystem to +meta_bg mode in ext4_resize_fs(), but the es->s_reserved_gdt_blocks was +not reduced to zero, so could we mistakenly call reserve_backup_gdb() +and passing an uninitialized resize_inode to it when adding new group +descriptors. + + mkfs.ext4 /dev/sda 3G + tune2fs -O ^resize_inode /dev/sda #forget to run requested e2fsck + mount /dev/sda /mnt + resize2fs /dev/sda 8G + + ======== + BUG: kernel NULL pointer dereference, address: 0000000000000028 + CPU: 19 PID: 3243 Comm: resize2fs Not tainted 5.18.0-rc7-00001-gfde086c5ebfd #748 + ... + RIP: 0010:ext4_flex_group_add+0xe08/0x2570 + ... + Call Trace: + + ext4_resize_fs+0xbec/0x1660 + __ext4_ioctl+0x1749/0x24e0 + ext4_ioctl+0x12/0x20 + __x64_sys_ioctl+0xa6/0x110 + do_syscall_64+0x3b/0x90 + entry_SYSCALL_64_after_hwframe+0x44/0xae + RIP: 0033:0x7f2dd739617b + ======== + +The fix is simple, add a check in ext4_resize_begin() to make sure that +the es->s_reserved_gdt_blocks is zero when the resize_inode feature is +disabled. + +Cc: stable@kernel.org +Signed-off-by: Zhang Yi +Reviewed-by: Ritesh Harjani +Reviewed-by: Jan Kara +Link: https://lore.kernel.org/r/20220601092717.763694-1-yi.zhang@huawei.com +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/resize.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +--- a/fs/ext4/resize.c ++++ b/fs/ext4/resize.c +@@ -53,6 +53,16 @@ int ext4_resize_begin(struct super_block + return -EPERM; + + /* ++ * If the reserved GDT blocks is non-zero, the resize_inode feature ++ * should always be set. ++ */ ++ if (EXT4_SB(sb)->s_es->s_reserved_gdt_blocks && ++ !ext4_has_feature_resize_inode(sb)) { ++ ext4_error(sb, "resize_inode disabled but reserved GDT blocks non-zero"); ++ return -EFSCORRUPTED; ++ } ++ ++ /* + * If we are not using the primary superblock/GDT copy don't resize, + * because the user tools have no way of handling this. Probably a + * bad time to do it anyways. diff --git a/queue-5.15/ext4-fix-bug_on-ext4_mb_use_inode_pa.patch b/queue-5.15/ext4-fix-bug_on-ext4_mb_use_inode_pa.patch new file mode 100644 index 00000000000..16663e40f47 --- /dev/null +++ b/queue-5.15/ext4-fix-bug_on-ext4_mb_use_inode_pa.patch @@ -0,0 +1,97 @@ +From a08f789d2ab5242c07e716baf9a835725046be89 Mon Sep 17 00:00:00 2001 +From: Baokun Li +Date: Sat, 28 May 2022 19:00:15 +0800 +Subject: ext4: fix bug_on ext4_mb_use_inode_pa + +From: Baokun Li + +commit a08f789d2ab5242c07e716baf9a835725046be89 upstream. + +Hulk Robot reported a BUG_ON: +================================================================== +kernel BUG at fs/ext4/mballoc.c:3211! +[...] +RIP: 0010:ext4_mb_mark_diskspace_used.cold+0x85/0x136f +[...] +Call Trace: + ext4_mb_new_blocks+0x9df/0x5d30 + ext4_ext_map_blocks+0x1803/0x4d80 + ext4_map_blocks+0x3a4/0x1a10 + ext4_writepages+0x126d/0x2c30 + do_writepages+0x7f/0x1b0 + __filemap_fdatawrite_range+0x285/0x3b0 + file_write_and_wait_range+0xb1/0x140 + ext4_sync_file+0x1aa/0xca0 + vfs_fsync_range+0xfb/0x260 + do_fsync+0x48/0xa0 +[...] +================================================================== + +Above issue may happen as follows: +------------------------------------- +do_fsync + vfs_fsync_range + ext4_sync_file + file_write_and_wait_range + __filemap_fdatawrite_range + do_writepages + ext4_writepages + mpage_map_and_submit_extent + mpage_map_one_extent + ext4_map_blocks + ext4_mb_new_blocks + ext4_mb_normalize_request + >>> start + size <= ac->ac_o_ex.fe_logical + ext4_mb_regular_allocator + ext4_mb_simple_scan_group + ext4_mb_use_best_found + ext4_mb_new_preallocation + ext4_mb_new_inode_pa + ext4_mb_use_inode_pa + >>> set ac->ac_b_ex.fe_len <= 0 + ext4_mb_mark_diskspace_used + >>> BUG_ON(ac->ac_b_ex.fe_len <= 0); + +we can easily reproduce this problem with the following commands: + `fallocate -l100M disk` + `mkfs.ext4 -b 1024 -g 256 disk` + `mount disk /mnt` + `fsstress -d /mnt -l 0 -n 1000 -p 1` + +The size must be smaller than or equal to EXT4_BLOCKS_PER_GROUP. +Therefore, "start + size <= ac->ac_o_ex.fe_logical" may occur +when the size is truncated. So start should be the start position of +the group where ac_o_ex.fe_logical is located after alignment. +In addition, when the value of fe_logical or EXT4_BLOCKS_PER_GROUP +is very large, the value calculated by start_off is more accurate. + +Cc: stable@kernel.org +Fixes: cd648b8a8fd5 ("ext4: trim allocation requests to group size") +Reported-by: Hulk Robot +Signed-off-by: Baokun Li +Reviewed-by: Ritesh Harjani +Link: https://lore.kernel.org/r/20220528110017.354175-2-libaokun1@huawei.com +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/mballoc.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +--- a/fs/ext4/mballoc.c ++++ b/fs/ext4/mballoc.c +@@ -4099,6 +4099,15 @@ ext4_mb_normalize_request(struct ext4_al + size = size >> bsbits; + start = start_off >> bsbits; + ++ /* ++ * For tiny groups (smaller than 8MB) the chosen allocation ++ * alignment may be larger than group size. Make sure the ++ * alignment does not move allocation to a different group which ++ * makes mballoc fail assertions later. ++ */ ++ start = max(start, rounddown(ac->ac_o_ex.fe_logical, ++ (ext4_lblk_t)EXT4_BLOCKS_PER_GROUP(ac->ac_sb))); ++ + /* don't cover already allocated blocks in selected range */ + if (ar->pleft && start <= ar->lleft) { + size -= ar->lleft + 1 - start; diff --git a/queue-5.15/ext4-fix-super-block-checksum-incorrect-after-mount.patch b/queue-5.15/ext4-fix-super-block-checksum-incorrect-after-mount.patch new file mode 100644 index 00000000000..65b4ac91a9a --- /dev/null +++ b/queue-5.15/ext4-fix-super-block-checksum-incorrect-after-mount.patch @@ -0,0 +1,73 @@ +From 9b6641dd95a0c441b277dd72ba22fed8d61f76ad Mon Sep 17 00:00:00 2001 +From: Ye Bin +Date: Wed, 25 May 2022 09:29:04 +0800 +Subject: ext4: fix super block checksum incorrect after mount +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Ye Bin + +commit 9b6641dd95a0c441b277dd72ba22fed8d61f76ad upstream. + +We got issue as follows: +[home]# mount /dev/sda test +EXT4-fs (sda): warning: mounting fs with errors, running e2fsck is recommended +[home]# dmesg +EXT4-fs (sda): warning: mounting fs with errors, running e2fsck is recommended +EXT4-fs (sda): Errors on filesystem, clearing orphan list. +EXT4-fs (sda): recovery complete +EXT4-fs (sda): mounted filesystem with ordered data mode. Quota mode: none. +[home]# debugfs /dev/sda +debugfs 1.46.5 (30-Dec-2021) +Checksum errors in superblock! Retrying... + +Reason is ext4_orphan_cleanup will reset ‘s_last_orphan’ but not update +super block checksum. + +To solve above issue, defer update super block checksum after +ext4_orphan_cleanup. + +Signed-off-by: Ye Bin +Cc: stable@kernel.org +Reviewed-by: Jan Kara +Reviewed-by: Ritesh Harjani +Link: https://lore.kernel.org/r/20220525012904.1604737-1-yebin10@huawei.com +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/super.c | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -4909,14 +4909,6 @@ no_journal: + err = percpu_counter_init(&sbi->s_freeinodes_counter, freei, + GFP_KERNEL); + } +- /* +- * Update the checksum after updating free space/inode +- * counters. Otherwise the superblock can have an incorrect +- * checksum in the buffer cache until it is written out and +- * e2fsprogs programs trying to open a file system immediately +- * after it is mounted can fail. +- */ +- ext4_superblock_csum_set(sb); + if (!err) + err = percpu_counter_init(&sbi->s_dirs_counter, + ext4_count_dirs(sb), GFP_KERNEL); +@@ -4974,6 +4966,14 @@ no_journal: + EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; + ext4_orphan_cleanup(sb, es); + EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; ++ /* ++ * Update the checksum after updating free space/inode counters and ++ * ext4_orphan_cleanup. Otherwise the superblock can have an incorrect ++ * checksum in the buffer cache until it is written out and ++ * e2fsprogs programs trying to open a file system immediately ++ * after it is mounted can fail. ++ */ ++ ext4_superblock_csum_set(sb); + if (needs_recovery) { + ext4_msg(sb, KERN_INFO, "recovery complete"); + err = ext4_mark_recovery_complete(sb, es); diff --git a/queue-5.15/ext4-make-variable-count-signed.patch b/queue-5.15/ext4-make-variable-count-signed.patch new file mode 100644 index 00000000000..5040c363c93 --- /dev/null +++ b/queue-5.15/ext4-make-variable-count-signed.patch @@ -0,0 +1,35 @@ +From bc75a6eb856cb1507fa907bf6c1eda91b3fef52f Mon Sep 17 00:00:00 2001 +From: Ding Xiang +Date: Mon, 30 May 2022 18:00:47 +0800 +Subject: ext4: make variable "count" signed + +From: Ding Xiang + +commit bc75a6eb856cb1507fa907bf6c1eda91b3fef52f upstream. + +Since dx_make_map() may return -EFSCORRUPTED now, so change "count" to +be a signed integer so we can correctly check for an error code returned +by dx_make_map(). + +Fixes: 46c116b920eb ("ext4: verify dir block before splitting it") +Cc: stable@kernel.org +Signed-off-by: Ding Xiang +Link: https://lore.kernel.org/r/20220530100047.537598-1-dingxiang@cmss.chinamobile.com +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/namei.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/fs/ext4/namei.c ++++ b/fs/ext4/namei.c +@@ -1929,7 +1929,8 @@ static struct ext4_dir_entry_2 *do_split + struct dx_hash_info *hinfo) + { + unsigned blocksize = dir->i_sb->s_blocksize; +- unsigned count, continued; ++ unsigned continued; ++ int count; + struct buffer_head *bh2; + ext4_lblk_t newblock; + u32 hash2; diff --git a/queue-5.15/kvm-arm64-don-t-read-a-hw-interrupt-pending-state-in-user-context.patch b/queue-5.15/kvm-arm64-don-t-read-a-hw-interrupt-pending-state-in-user-context.patch new file mode 100644 index 00000000000..ed826af2f45 --- /dev/null +++ b/queue-5.15/kvm-arm64-don-t-read-a-hw-interrupt-pending-state-in-user-context.patch @@ -0,0 +1,106 @@ +From 2cdea19a34c2340b3aa69508804efe4e3750fcec Mon Sep 17 00:00:00 2001 +From: Marc Zyngier +Date: Tue, 7 Jun 2022 14:14:25 +0100 +Subject: KVM: arm64: Don't read a HW interrupt pending state in user context + +From: Marc Zyngier + +commit 2cdea19a34c2340b3aa69508804efe4e3750fcec upstream. + +Since 5bfa685e62e9 ("KVM: arm64: vgic: Read HW interrupt pending state +from the HW"), we're able to source the pending bit for an interrupt +that is stored either on the physical distributor or on a device. + +However, this state is only available when the vcpu is loaded, +and is not intended to be accessed from userspace. Unfortunately, +the GICv2 emulation doesn't provide specific userspace accessors, +and we fallback with the ones that are intended for the guest, +with fatal consequences. + +Add a new vgic_uaccess_read_pending() accessor for userspace +to use, build on top of the existing vgic_mmio_read_pending(). + +Reported-by: Eric Auger +Reviewed-by: Eric Auger +Tested-by: Eric Auger +Signed-off-by: Marc Zyngier +Fixes: 5bfa685e62e9 ("KVM: arm64: vgic: Read HW interrupt pending state from the HW") +Link: https://lore.kernel.org/r/20220607131427.1164881-2-maz@kernel.org +Cc: stable@vger.kernel.org +Signed-off-by: Greg Kroah-Hartman +--- + arch/arm64/kvm/vgic/vgic-mmio-v2.c | 4 ++-- + arch/arm64/kvm/vgic/vgic-mmio.c | 19 ++++++++++++++++--- + arch/arm64/kvm/vgic/vgic-mmio.h | 3 +++ + 3 files changed, 21 insertions(+), 5 deletions(-) + +--- a/arch/arm64/kvm/vgic/vgic-mmio-v2.c ++++ b/arch/arm64/kvm/vgic/vgic-mmio-v2.c +@@ -418,11 +418,11 @@ static const struct vgic_register_region + VGIC_ACCESS_32bit), + REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_SET, + vgic_mmio_read_pending, vgic_mmio_write_spending, +- NULL, vgic_uaccess_write_spending, 1, ++ vgic_uaccess_read_pending, vgic_uaccess_write_spending, 1, + VGIC_ACCESS_32bit), + REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR, + vgic_mmio_read_pending, vgic_mmio_write_cpending, +- NULL, vgic_uaccess_write_cpending, 1, ++ vgic_uaccess_read_pending, vgic_uaccess_write_cpending, 1, + VGIC_ACCESS_32bit), + REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_ACTIVE_SET, + vgic_mmio_read_active, vgic_mmio_write_sactive, +--- a/arch/arm64/kvm/vgic/vgic-mmio.c ++++ b/arch/arm64/kvm/vgic/vgic-mmio.c +@@ -226,8 +226,9 @@ int vgic_uaccess_write_cenable(struct kv + return 0; + } + +-unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu, +- gpa_t addr, unsigned int len) ++static unsigned long __read_pending(struct kvm_vcpu *vcpu, ++ gpa_t addr, unsigned int len, ++ bool is_user) + { + u32 intid = VGIC_ADDR_TO_INTID(addr, 1); + u32 value = 0; +@@ -248,7 +249,7 @@ unsigned long vgic_mmio_read_pending(str + IRQCHIP_STATE_PENDING, + &val); + WARN_RATELIMIT(err, "IRQ %d", irq->host_irq); +- } else if (vgic_irq_is_mapped_level(irq)) { ++ } else if (!is_user && vgic_irq_is_mapped_level(irq)) { + val = vgic_get_phys_line_level(irq); + } else { + val = irq_is_pending(irq); +@@ -263,6 +264,18 @@ unsigned long vgic_mmio_read_pending(str + return value; + } + ++unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu, ++ gpa_t addr, unsigned int len) ++{ ++ return __read_pending(vcpu, addr, len, false); ++} ++ ++unsigned long vgic_uaccess_read_pending(struct kvm_vcpu *vcpu, ++ gpa_t addr, unsigned int len) ++{ ++ return __read_pending(vcpu, addr, len, true); ++} ++ + static bool is_vgic_v2_sgi(struct kvm_vcpu *vcpu, struct vgic_irq *irq) + { + return (vgic_irq_is_sgi(irq->intid) && +--- a/arch/arm64/kvm/vgic/vgic-mmio.h ++++ b/arch/arm64/kvm/vgic/vgic-mmio.h +@@ -149,6 +149,9 @@ int vgic_uaccess_write_cenable(struct kv + unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu, + gpa_t addr, unsigned int len); + ++unsigned long vgic_uaccess_read_pending(struct kvm_vcpu *vcpu, ++ gpa_t addr, unsigned int len); ++ + void vgic_mmio_write_spending(struct kvm_vcpu *vcpu, + gpa_t addr, unsigned int len, + unsigned long val); diff --git a/queue-5.15/series b/queue-5.15/series index 1cad237fab1..d84d1ad73c8 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -92,3 +92,11 @@ usb-gadget-f_fs-change-ep-ep-safe-in-ffs_epfile_io.patch tty-n_gsm-debug-output-allocation-must-use-gfp_atomic.patch serial-8250-store-to-lsr_save_flags-after-lsr-read.patch bus-fsl-mc-bus-fix-kasan-use-after-free-in-fsl_mc_bus_remove.patch +dm-mirror-log-round-up-region-bitmap-size-to-bits_per_long.patch +drm-amd-display-cap-oled-brightness-per-max-frame-average-luminance.patch +cfi-fix-__cfi_slowpath_diag-rcu-usage-with-cpuidle.patch +ext4-fix-super-block-checksum-incorrect-after-mount.patch +ext4-fix-bug_on-ext4_mb_use_inode_pa.patch +ext4-make-variable-count-signed.patch +ext4-add-reserved-gdt-blocks-check.patch +kvm-arm64-don-t-read-a-hw-interrupt-pending-state-in-user-context.patch -- 2.47.3