power: supply: cros_usbpd: provide ID table for avoiding fallback match
Subsystems (3)
Sasha Levin
maintainerPATCH 1/4 power: supply: cros_usbpd: provide ID table for avoiding fallback match
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit 0f8678c34cbfdc63569a9b0ede1fe235ec6ec693 ]
Instead of using fallback driver name match, provide ID table[1] for the primary match.
[1]: https://elixir.bootlin.com/linux/v6.8/source/drivers/base/platform.c#L1353
--- drivers/power/supply/cros_usbpd-charger.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/power/supply/cros_usbpd-charger.c +9 -2
@@ -5,6 +5,7 @@* Copyright (c) 2014 - 2018 Google, Inc */ +#include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/platform_data/cros_ec_commands.h> #include <linux/platform_data/cros_ec_proto.h>
@@ -711,16 +712,22 @@ static int cros_usbpd_charger_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(cros_usbpd_charger_pm_ops, NULL, cros_usbpd_charger_resume); +static const struct platform_device_id cros_usbpd_charger_id[] = { + {DRV_NAME ,0 }, + {} +}; +MODULE_DEVICE_TABLE (platform, cros_usbpd_charger_id); +static struct platform_driver cros_usbpd_charger_driver = { .driver = { .name =DRV_NAME , .pm = &cros_usbpd_charger_pm_ops, }, - .probe = cros_usbpd_charger_probe + .probe = cros_usbpd_charger_probe, + .id_table = cros_usbpd_charger_id, };module_platform_driver (cros_usbpd_charger_driver);MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("ChromeOS EC USBPD charger" ); -MODULE_ALIAS ("platform:" DRV_NAME );
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 2/4 iommu/arm-smmu-v3: Free MSIs in case of ENOMEM
From: Aleksandr Aprelkov <[email protected]>
[ Upstream commit 80fea979dd9d48d67c5b48d2f690c5da3e543ebd ]
If devm_add_action() returns -ENOMEM, then MSIs are allocated but not not freed on teardown. Use devm_add_action_or_reset() instead to keep the static analyser happy.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1 -1
@@ -3193,7 +3193,7 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu) smmu->priq.q.irq =msi_get_virq (dev,PRIQ_MSI_INDEX );/* Add callback to free MSIs on teardown */ -devm_add_action (dev, arm_smmu_free_msis, dev); +devm_add_action_or_reset (dev, arm_smmu_free_msis, dev); }static void arm_smmu_setup_unique_irqs (struct arm_smmu_device *smmu)
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 3/4 ext4: fix uninitialized ratelimit_state->lock access in __ext4_fill_super()
In reply to Sasha LevinFrom: Baokun Li <[email protected]>
[ Upstream commit b4b4fda34e535756f9e774fb2d09c4537b7dfd1c ]
In the following concurrency we will access the uninitialized rs->lock:
ext4_fill_super
ext4_register_sysfs
// sysfs registered msg_ratelimit_interval_ms
// Other processes modify rs->interval to
// non-zero via msg_ratelimit_interval_ms
ext4_orphan_cleanup
ext4_msg(sb, KERN_INFO, "Errors on filesystem, "
__ext4_msg
___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state)
if (!rs->interval) // do nothing if interval is 0
return 1;
raw_spin_trylock_irqsave(&rs->lock, flags)
raw_spin_trylock(lock)
_raw_spin_trylock
__raw_spin_trylock
spin_acquire(&lock->dep_map, 0, 1, _RET_IP_)
lock_acquire
__lock_acquire
register_lock_class
assign_lock_key
dump_stack();
ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);
raw_spin_lock_init(&rs->lock);
// init rs->lock hereand get the following dump_stack:
=========================================================
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator.
CPU: 12 PID: 753 Comm: mount Tainted: G E 6.7.0-rc6-next-20231222 #504 [...] Call Trace: dump_stack_lvl+0xc5/0x170 dump_stack+0x18/0x30 register_lock_class+0x740/0x7c0 __lock_acquire+0x69/0x13a0 lock_acquire+0x120/0x450 _raw_spin_trylock+0x98/0xd0 ___ratelimit+0xf6/0x220 __ext4_msg+0x7f/0x160 [ext4] ext4_orphan_cleanup+0x665/0x740 [ext4] __ext4_fill_super+0x21ea/0x2b10 [ext4] ext4_fill_super+0x14d/0x360 [ext4]
[...]
=========================================================
Normally interval is 0 until s_msg_ratelimit_state is initialized, so ___ratelimit() does nothing. But registering sysfs precedes initializing rs->lock, so it is possible to change rs->interval to a non-zero value via the msg_ratelimit_interval_ms interface of sysfs while rs->lock is uninitialized, and then a call to ext4_msg triggers the problem by accessing an uninitialized rs->lock. Therefore register sysfs after all initializations are complete to avoid such problems.
--- fs/ext4/super.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
fs/ext4/super.c +10 -12
@@ -5556,19 +5556,15 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)if (err) goto failed_mount6; - err =ext4_register_sysfs (sb); -if (err) - goto failed_mount7; - err =ext4_init_orphan_info (sb);if (err) - goto failed_mount8; + goto failed_mount7;#ifdef CONFIG_QUOTA /* Enable quota usage during mount. */ if (ext4_has_feature_quota (sb) && !sb_rdonly (sb)) { err =ext4_enable_quotas (sb);if (err) - goto failed_mount9; + goto failed_mount8; }#endif /* CONFIG_QUOTA */
@@ -5594,7 +5590,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)ext4_msg (sb,KERN_INFO ,"recovery complete" ); err =ext4_mark_recovery_complete (sb, es);if (err) - goto failed_mount10; + goto failed_mount9; }if (test_opt (sb,DISCARD ) && !bdev_max_discard_sectors (sb->s_bdev))
@@ -5611,15 +5607,17 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)atomic_set (&sbi->s_warning_count,0 );atomic_set (&sbi->s_msg_count,0 ); +/* Register sysfs after all initializations are complete. */ + err =ext4_register_sysfs (sb); +if (err) + goto failed_mount9; +return 0 ; -failed_mount10: +failed_mount9:ext4_quotas_off (sb,EXT4_MAXQUOTAS ); -failed_mount9:__maybe_unused +failed_mount8:__maybe_unused ext4_release_orphan_info (sb); -failed_mount8: -ext4_unregister_sysfs (sb); -kobject_put (&sbi->s_kobj); failed_mount7:ext4_unregister_li_request (sb); failed_mount6:
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 4/4 kprobe/ftrace: bail out if ftrace was killed
In reply to Sasha LevinFrom: Stephen Brennan <[email protected]>
[ Upstream commit 1a7d0890dd4a502a202aaec792a6c04e6e049547 ]
If an error happens in ftrace, ftrace_kill() will prevent disarming kprobes. Eventually, the ftrace_ops associated with the kprobes will be freed, yet the kprobes will still be active, and when triggered, they will use the freed memory, likely resulting in a page fault and panic.
This behavior can be reproduced quite easily, by creating a kprobe and then triggering a ftrace_kill(). For simplicity, we can simulate an ftrace error with a kernel module like [1]:
[1]: https://github.com/brenns10/kernel_stuff/tree/master/ftrace_killer
sudo perf probe --add commit_creds sudo perf trace -e probe:commit_creds # In another terminal make sudo insmod ftrace_killer.ko # calls ftrace_kill(), simulating bug # Back to perf terminal # ctrl-c sudo perf probe --del commit_creds
After a short period, a page fault and panic would occur as the kprobe continues to execute and uses the freed ftrace_ops. While ftrace_kill() is supposed to be used only in extreme circumstances, it is invoked in FTRACE_WARN_ON() and so there are many places where an unexpected bug could be triggered, yet the system may continue operating, possibly without the administrator noticing. If ftrace_kill() does not panic the system, then we should do everything we can to continue operating, rather than leave a ticking time bomb.
--- arch/csky/kernel/probes/ftrace.c | 3 +++ arch/loongarch/kernel/ftrace_dyn.c | 3 +++ arch/parisc/kernel/ftrace.c | 3 +++ arch/powerpc/kernel/kprobes-ftrace.c | 3 +++ arch/riscv/kernel/probes/ftrace.c | 3 +++ arch/s390/kernel/ftrace.c | 3 +++ arch/x86/kernel/kprobes/ftrace.c | 3 +++ include/linux/kprobes.h | 7 +++++++ kernel/kprobes.c | 6 ++++++ kernel/trace/ftrace.c | 1 + 10 files changed, 35 insertions(+)
arch/csky/kernel/probes/ftrace.c +3 -0
@@ -12,6 +12,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,struct kprobe_ctlblk *kcb;struct pt_regs *regs; +if (unlikely (kprobe_ftrace_disabled)) +return ; + bit =ftrace_test_recursion_trylock (ip, parent_ip);if (bit <0 )return ;
arch/loongarch/kernel/ftrace_dyn.c +3 -0
@@ -287,6 +287,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,struct kprobe *p;struct kprobe_ctlblk *kcb; +if (unlikely (kprobe_ftrace_disabled)) +return ; + bit =ftrace_test_recursion_trylock (ip, parent_ip);if (bit <0 )return ;
arch/parisc/kernel/ftrace.c +3 -0
@@ -206,6 +206,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,struct kprobe *p;int bit; +if (unlikely (kprobe_ftrace_disabled)) +return ; + bit =ftrace_test_recursion_trylock (ip, parent_ip);if (bit <0 )return ;
arch/powerpc/kernel/kprobes-ftrace.c +3 -0
@@ -21,6 +21,9 @@ void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip,struct pt_regs *regs;int bit; +if (unlikely (kprobe_ftrace_disabled)) +return ; + bit =ftrace_test_recursion_trylock (nip, parent_nip);if (bit <0 )return ;
arch/riscv/kernel/probes/ftrace.c +3 -0
@@ -11,6 +11,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,struct kprobe_ctlblk *kcb;int bit; +if (unlikely (kprobe_ftrace_disabled)) +return ; + bit =ftrace_test_recursion_trylock (ip, parent_ip);if (bit <0 )return ;
arch/s390/kernel/ftrace.c +3 -0
@@ -296,6 +296,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,struct kprobe *p;int bit; +if (unlikely (kprobe_ftrace_disabled)) +return ; + bit =ftrace_test_recursion_trylock (ip, parent_ip);if (bit <0 )return ;
arch/x86/kernel/kprobes/ftrace.c +3 -0
@@ -21,6 +21,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,struct kprobe_ctlblk *kcb;int bit; +if (unlikely (kprobe_ftrace_disabled)) +return ; + bit =ftrace_test_recursion_trylock (ip, parent_ip);if (bit <0 )return ;
include/linux/kprobes.h +7 -0
@@ -383,11 +383,15 @@ static inline void wait_for_kprobe_optimizer(void) { }extern void kprobe_ftrace_handler (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *ops,struct ftrace_regs *fregs);extern int arch_prepare_kprobe_ftrace (struct kprobe *p); +/* Set when ftrace has been killed: kprobes on ftrace must be disabled for safety */ +extern bool kprobe_ftrace_disabled__read_mostly ; +extern void kprobe_ftrace_kill (void );#else static inline int arch_prepare_kprobe_ftrace (struct kprobe *p) {return -EINVAL ; } +static inline void kprobe_ftrace_kill (void ) {}#endif /* CONFIG_KPROBES_ON_FTRACE */ /* Get the kprobe at this addr (if any) - called with preemption disabled */
@@ -496,6 +500,9 @@ static inline void kprobe_flush_task(struct task_struct *tk)static inline void kprobe_free_init_mem (void ) { } +static inline void kprobe_ftrace_kill (void ) +{ +}static inline int disable_kprobe (struct kprobe *kp) {return -EOPNOTSUPP ;
kernel/kprobes.c +6 -0
@@ -1068,6 +1068,7 @@ static struct ftrace_ops kprobe_ipmodify_ops __read_mostly = {static int kprobe_ipmodify_enabled;static int kprobe_ftrace_enabled; +bool kprobe_ftrace_disabled;static int __arm_kprobe_ftrace (struct kprobe *p,struct ftrace_ops *ops,int *cnt)
@@ -1136,6 +1137,11 @@ static int disarm_kprobe_ftrace(struct kprobe *p) ipmodify ? &kprobe_ipmodify_ops : &kprobe_ftrace_ops, ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled); } + +void kprobe_ftrace_kill () +{ + kprobe_ftrace_disabled = true; +}#else /* !CONFIG_KPROBES_ON_FTRACE */ static inline int arm_kprobe_ftrace (struct kprobe *p) {
kernel/trace/ftrace.c +1 -0
@@ -7892,6 +7892,7 @@ void ftrace_kill(void) ftrace_disabled =1 ; ftrace_enabled =0 ; ftrace_trace_function = ftrace_stub; +kprobe_ftrace_kill (); }/**
Signature · 1 line
2.43.0