power: supply: cros_usbpd: provide ID table for avoiding fallback match
Subsystems (3)
Sasha Levin
maintainerPATCH 1/5 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/5 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
@@ -3402,7 +3402,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/5 ext4: do not create EA inode under buffer lock
In reply to Sasha LevinFrom: Jan Kara <[email protected]>
[ Upstream commit 0a46ef234756dca04623b7591e8ebb3440622f0b ]
ext4_xattr_set_entry() creates new EA inodes while holding buffer lock on the external xattr block. This is problematic as it nests all the allocation locking (which acquires locks on other buffers) under the buffer lock. This can even deadlock when the filesystem is corrupted and e.g. quota file is setup to contain xattr block as data block. Move the allocation of EA inode out of ext4_xattr_set_entry() into the callers.
--- fs/ext4/xattr.c | 113 +++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 60 deletions(-)
fs/ext4/xattr.c +53 -60
@@ -1619,6 +1619,7 @@ static struct inode *ext4_xattr_inode_lookup_create(handle_t *handle,static int ext4_xattr_set_entry (struct ext4_xattr_info *i,struct ext4_xattr_search *s,handle_t *handle,struct inode *inode, +struct inode *new_ea_inode,bool is_block) {struct ext4_xattr_entry *last, *next;
@@ -1626,7 +1627,6 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,size_t min_offs = s->end - s->base, name_len =strlen (i->name);int in_inode = i->in_inode;struct inode *old_ea_inode =NULL ; -struct inode *new_ea_inode =NULL ;size_t old_size, new_size;int ret;
@@ -1711,38 +1711,11 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, old_ea_inode =NULL ; goto out; } - } -if (i->value && in_inode) { -WARN_ON_ONCE (!i->value_len); - - new_ea_inode =ext4_xattr_inode_lookup_create (handle, inode, - i->value, i->value_len); -if (IS_ERR (new_ea_inode)) { - ret =PTR_ERR (new_ea_inode); - new_ea_inode =NULL ; - goto out; - } - } -if (old_ea_inode) {/* We are ready to release ref count on the old_ea_inode. */ ret =ext4_xattr_inode_dec_ref (handle, old_ea_inode); -if (ret) { -/* Release newly required ref count on new_ea_inode. */ -if (new_ea_inode) { -int err; - - err =ext4_xattr_inode_dec_ref (handle, - new_ea_inode); -if (err) -ext4_warning_inode (new_ea_inode, -"dec ref new_ea_inode err=%d" , - err); -ext4_xattr_inode_free_quota (inode, new_ea_inode, - i->value_len); - } +if (ret) goto out; - }ext4_xattr_inode_free_quota (inode, old_ea_inode,le32_to_cpu (here->e_value_size));
@@ -1866,7 +1839,6 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, ret =0 ; out:iput (old_ea_inode); -iput (new_ea_inode);return ret; }
@@ -1929,9 +1901,21 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,size_t old_ea_inode_quota =0 ;unsigned int ea_ino; -#define header (x) ((struct ext4_xattr_header *)(x)) +/* If we need EA inode, prepare it before locking the buffer */ +if (i->value && i->in_inode) { +WARN_ON_ONCE (!i->value_len); + + ea_inode =ext4_xattr_inode_lookup_create (handle, inode, + i->value, i->value_len); +if (IS_ERR (ea_inode)) { + error =PTR_ERR (ea_inode); + ea_inode =NULL ; + goto cleanup; + } + } +if (s->base) {int offset = (char *)s->here - bs->bh->b_data;
@@ -1940,6 +1924,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, EXT4_JTR_NONE);if (error) goto cleanup; +lock_buffer (bs->bh);if (header (s->base)->h_refcount ==cpu_to_le32 (1 )) {
@@ -1966,7 +1951,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, }ea_bdebug (bs->bh,"modifying in-place" ); error =ext4_xattr_set_entry (i, s, handle, inode, - true/* is_block */ ); + ea_inode, true/* is_block */ );ext4_xattr_block_csum_set (inode, bs->bh);unlock_buffer (bs->bh);if (error == -EFSCORRUPTED )
@@ -2034,29 +2019,13 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, s->end = s->base + sb->s_blocksize; } - error =ext4_xattr_set_entry (i, s, handle, inode, true/* is_block */ ); + error =ext4_xattr_set_entry (i, s, handle, inode, ea_inode, + true/* is_block */ );if (error == -EFSCORRUPTED ) goto bad_block;if (error) goto cleanup; -if (i->value && s->here->e_value_inum) { -/* -* A ref count on ea_inode has been taken as part of the call to -* ext4_xattr_set_entry() above. We would like to drop this -* extra ref but we have to wait until the xattr block is -* initialized and has its own ref count on the ea_inode. -*/ - ea_ino =le32_to_cpu (s->here->e_value_inum); - error =ext4_xattr_inode_iget (inode, ea_ino, -le32_to_cpu (s->here->e_hash), - &ea_inode); -if (error) { - ea_inode =NULL ; - goto cleanup; - } - } - inserted:if (!IS_LAST_ENTRY (s->first)) { new_bh = ext4_xattr_block_cache_find(inode, header(s->base),
@@ -2198,17 +2167,16 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, cleanup:if (ea_inode) { -int error2; - - error2 =ext4_xattr_inode_dec_ref (handle, ea_inode); -if (error2) -ext4_warning_inode (ea_inode,"dec ref error=%d" , - error2); +if (error) { +int error2; -/* If there was an error, revert the quota charge. */ -if (error) + error2 =ext4_xattr_inode_dec_ref (handle, ea_inode); +if (error2) +ext4_warning_inode (ea_inode,"dec ref error=%d" , + error2);ext4_xattr_inode_free_quota (inode, ea_inode,i_size_read (ea_inode)); + }iput (ea_inode); }if (ce)
@@ -2266,14 +2234,38 @@ int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode, {struct ext4_xattr_ibody_header *header;struct ext4_xattr_search *s = &is->s; +struct inode *ea_inode =NULL ;int error;if (!EXT4_INODE_HAS_XATTR_SPACE (inode))return -ENOSPC ; - error =ext4_xattr_set_entry (i, s, handle, inode, false/* is_block */ ); -if (error) +/* If we need EA inode, prepare it before locking the buffer */ +if (i->value && i->in_inode) { +WARN_ON_ONCE (!i->value_len); + + ea_inode =ext4_xattr_inode_lookup_create (handle, inode, + i->value, i->value_len); +if (IS_ERR (ea_inode)) +return PTR_ERR (ea_inode); + } + error =ext4_xattr_set_entry (i, s, handle, inode, ea_inode, + false/* is_block */ ); +if (error) { +if (ea_inode) { +int error2; + + error2 =ext4_xattr_inode_dec_ref (handle, ea_inode); +if (error2) +ext4_warning_inode (ea_inode,"dec ref error=%d" , + error2); + +ext4_xattr_inode_free_quota (inode, ea_inode, +i_size_read (ea_inode)); +iput (ea_inode); + }return error; + } header =IHDR (inode,ext4_raw_inode (&is->iloc));if (!IS_LAST_ENTRY (s->first)) { header->h_magic =cpu_to_le32 (EXT4_XATTR_MAGIC );
@@ -2282,6 +2274,7 @@ int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode, header->h_magic =cpu_to_le32 (0 );ext4_clear_inode_state (inode,EXT4_STATE_XATTR ); } +iput (ea_inode);return 0 ; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 4/5 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
@@ -5551,19 +5551,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 */
@@ -5589,7 +5585,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))
@@ -5606,15 +5602,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 5/5 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
@@ -378,11 +378,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 */
@@ -495,6 +499,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
@@ -7895,6 +7895,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