locking/lockdep: Iterate lock_classes directly when reading lockdep files
Subsystems (3)
Sasha Levin
maintainerPATCH 5/8 f2fs: fix to do sanity check on curseg->alloc_type
In reply to Sasha LevinFrom: Chao Yu <[email protected]>
[ Upstream commit f41ee8b91c00770d718be2ff4852a80017ae9ab3 ]
As Wenqing Liu reported in bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=215657
- Overview
UBSAN: array-index-out-of-bounds in fs/f2fs/segment.c:3460:2 when mount and operate a corrupted image
- Reproduce
tested on kernel 5.17-rc4, 5.17-rc6
1. mkdir test_crash
2. cd test_crash
3. unzip tmp2.zip
4. mkdir mnt
5. ./single_test.sh f2fs 2
- Kernel dump
[ 46.434454] loop0: detected capacity change from 0 to 131072 [ 46.529839] F2FS-fs (loop0): Mounted with checkpoint version = 7548c2d9 [ 46.738319] ================================================================================ [ 46.738412] UBSAN: array-index-out-of-bounds in fs/f2fs/segment.c:3460:2 [ 46.738475] index 231 is out of range for type 'unsigned int [2]' [ 46.738539] CPU: 2 PID: 939 Comm: umount Not tainted 5.17.0-rc6 #1 [ 46.738547] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 46.738551] Call Trace: [ 46.738556] <TASK> [ 46.738563] dump_stack_lvl+0x47/0x5c [ 46.738581] ubsan_epilogue+0x5/0x50 [ 46.738592] __ubsan_handle_out_of_bounds+0x68/0x80 [ 46.738604] f2fs_allocate_data_block+0xdff/0xe60 [f2fs] [ 46.738819] do_write_page+0xef/0x210 [f2fs] [ 46.738934] f2fs_do_write_node_page+0x3f/0x80 [f2fs] [ 46.739038] __write_node_page+0x2b7/0x920 [f2fs] [ 46.739162] f2fs_sync_node_pages+0x943/0xb00 [f2fs] [ 46.739293] f2fs_write_checkpoint+0x7bb/0x1030 [f2fs] [ 46.739405] kill_f2fs_super+0x125/0x150 [f2fs] [ 46.739507] deactivate_locked_super+0x60/0xc0 [ 46.739517] deactivate_super+0x70/0xb0 [ 46.739524] cleanup_mnt+0x11a/0x200 [ 46.739532] __cleanup_mnt+0x16/0x20 [ 46.739538] task_work_run+0x67/0xa0 [ 46.739547] exit_to_user_mode_prepare+0x18c/0x1a0 [ 46.739559] syscall_exit_to_user_mode+0x26/0x40 [ 46.739568] do_syscall_64+0x46/0xb0 [ 46.739584] entry_SYSCALL_64_after_hwframe+0x44/0xae
The root cause is we missed to do sanity check on curseg->alloc_type, result in out-of-bound accessing on sbi->block_count[] array, fix it.
--- fs/f2fs/segment.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/f2fs/segment.c +7 -0
@@ -4650,6 +4650,13 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)sanity_check_seg_type (sbi, curseg->seg_type); +if (curseg->alloc_type !=LFS && curseg->alloc_type !=SSR ) { +f2fs_err (sbi, +"Current segment has invalid alloc_type:%d" , + curseg->alloc_type); +return -EFSCORRUPTED ; + } +if (f2fs_test_bit (blkofs, se->cur_valid_map)) goto out;
Signature · 8 lines
2.34.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Sasha Levin
maintainerPATCH 7/8 f2fs: compress: fix to print raw data size in error path of lz4 decompression
In reply to Sasha LevinFrom: Chao Yu <[email protected]>
[ Upstream commit d284af43f703760e261b1601378a0c13a19d5f1f ]
In lz4_decompress_pages(), if size of decompressed data is not equal to expected one, we should print the size rather than size of target buffer for decompressed data, fix it.
--- fs/f2fs/compress.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/f2fs/compress.c +2 -3
@@ -286,10 +286,9 @@ static int lz4_decompress_pages(struct decompress_io_ctx *dic) }if (ret !=PAGE_SIZE << dic->log_cluster_size) { -printk_ratelimited ("%sF2FS-fs (%s): lz4 invalid rlen:%zu, " +printk_ratelimited ("%sF2FS-fs (%s): lz4 invalid ret:%d, " "expected:%lu\n" ,KERN_ERR , -F2FS_I_SB (dic->inode)->sb->s_id, - dic->rlen, +F2FS_I_SB (dic->inode)->sb->s_id, ret,PAGE_SIZE << dic->log_cluster_size);return -EIO ; }
Signature · 8 lines
2.34.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Sasha Levin
maintainerPATCH 2/8 ext4: correct cluster len and clusters changed accounting in ext4_mb_mark_bb
In reply to Sasha LevinFrom: Ritesh Harjani <[email protected]>
[ Upstream commit a5c0e2fdf7cea535ba03259894dc184e5a4c2800 ]
ext4_mb_mark_bb() currently wrongly calculates cluster len (clen) and flex_group->free_clusters. This patch fixes that.
Identified based on code review of ext4_mb_mark_bb() function.
--- fs/ext4/mballoc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
fs/ext4/mballoc.c +12 -7
@@ -3320,10 +3320,11 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,struct ext4_sb_info *sbi =EXT4_SB (sb);ext4_group_t group;ext4_grpblk_t blkoff; -int i, clen, err; +int i, err;int already; +unsigned int clen, clen_changed; - clen =EXT4_B2C (sbi, len); + clen =EXT4_NUM_B2C (sbi, len);ext4_get_group_no_and_offset (sb, block, &group, &blkoff); bitmap_bh =ext4_read_block_bitmap (sb, group);
@@ -3344,6 +3345,7 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,if (!mb_test_bit (blkoff + i, bitmap_bh->b_data) == !state) already++; + clen_changed = clen - already;if (state)ext4_set_bits (bitmap_bh->b_data, blkoff, clen);else
@@ -3356,9 +3358,9 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, group, gdp)); }if (state) - clen =ext4_free_group_clusters (sb, gdp) - clen + already; + clen =ext4_free_group_clusters (sb, gdp) - clen_changed;else - clen =ext4_free_group_clusters (sb, gdp) + clen - already; + clen =ext4_free_group_clusters (sb, gdp) + clen_changed;ext4_free_group_clusters_set (sb, gdp, clen);ext4_block_bitmap_csum_set (sb, group, gdp, bitmap_bh);
@@ -3368,10 +3370,13 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,if (sbi->s_log_groups_per_flex) {ext4_group_t flex_group =ext4_flex_group (sbi, group); +struct flex_groups *fg =sbi_array_rcu_deref (sbi, + s_flex_groups, flex_group); -atomic64_sub (len, - &sbi_array_rcu_deref (sbi, s_flex_groups, - flex_group)->free_clusters); +if (state) +atomic64_sub (clen_changed, &fg->free_clusters); +else +atomic64_add (clen_changed, &fg->free_clusters); } err =ext4_handle_dirty_metadata (NULL ,NULL , bitmap_bh);
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 3/8 ext4: fix ext4_mb_mark_bb() with flex_bg with fast_commit
In reply to Sasha LevinFrom: Ritesh Harjani <[email protected]>
[ Upstream commit bfdc502a4a4c058bf4cbb1df0c297761d528f54d ]
In case of flex_bg feature (which is by default enabled), extents for any given inode might span across blocks from two different block group. ext4_mb_mark_bb() only reads the buffer_head of block bitmap once for the starting block group, but it fails to read it again when the extent length boundary overflows to another block group. Then in this below loop it accesses memory beyond the block group bitmap buffer_head and results into a data abort.
for (i = 0; i < clen; i++) if (!mb_test_bit(blkoff + i, bitmap_bh->b_data) == !state) already++;
This patch adds this functionality for checking block group boundary in ext4_mb_mark_bb() and update the buffer_head(bitmap_bh) for every different block group.
w/o this patch, I was easily able to hit a data access abort using Power platform.
<...>
[ 74.327662] EXT4-fs error (device loop3): ext4_mb_generate_buddy:1141: group 11, block bitmap and bg descriptor inconsistent: 21248 vs 23294 free clusters
[ 74.533214] EXT4-fs (loop3): shut down requested (2)
[ 74.536705] Aborting journal on device loop3-8.
[ 74.702705] BUG: Unable to handle kernel data access on read at 0xc00000005e980000
[ 74.703727] Faulting instruction address: 0xc0000000007bffb8
cpu 0xd: Vector: 300 (Data Access) at [c000000015db7060]
pc: c0000000007bffb8: ext4_mb_mark_bb+0x198/0x5a0
lr: c0000000007bfeec: ext4_mb_mark_bb+0xcc/0x5a0
sp: c000000015db7300
msr: 800000000280b033
dar: c00000005e980000
dsisr: 40000000
current = 0xc000000027af6880
paca = 0xc00000003ffd5200 irqmask: 0x03 irq_happened: 0x01
pid = 5167, comm = mount<...>
enter ? for help
[c000000015db7380] c000000000782708 ext4_ext_clear_bb+0x378/0x410 [c000000015db7400] c000000000813f14 ext4_fc_replay+0x1794/0x2000 [c000000015db7580] c000000000833f7c do_one_pass+0xe9c/0x12a0 [c000000015db7710] c000000000834504 jbd2_journal_recover+0x184/0x2d0 [c000000015db77c0] c000000000841398 jbd2_journal_load+0x188/0x4a0 [c000000015db7880] c000000000804de8 ext4_fill_super+0x2638/0x3e10 [c000000015db7a40] c0000000005f8404 get_tree_bdev+0x2b4/0x350 [c000000015db7ae0] c0000000007ef058 ext4_get_tree+0x28/0x40 [c000000015db7b00] c0000000005f6344 vfs_get_tree+0x44/0x100 [c000000015db7b70] c00000000063c408 path_mount+0xdd8/0xe70 [c000000015db7c40] c00000000063c8f0 sys_mount+0x450/0x550 [c000000015db7d50] c000000000035770 system_call_exception+0x4a0/0x4e0 [c000000015db7e10] c00000000000c74c system_call_common+0xec/0x250
--- fs/ext4/mballoc.c | 131 +++++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 55 deletions(-)
fs/ext4/mballoc.c +76 -55
@@ -3322,72 +3322,93 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,ext4_grpblk_t blkoff;int i, err;int already; -unsigned int clen, clen_changed; +unsigned int clen, clen_changed, thisgrp_len; - clen =EXT4_NUM_B2C (sbi, len); - -ext4_get_group_no_and_offset (sb, block, &group, &blkoff); - bitmap_bh =ext4_read_block_bitmap (sb, group); -if (IS_ERR (bitmap_bh)) { - err =PTR_ERR (bitmap_bh); - bitmap_bh =NULL ; - goto out_err; - } - - err = -EIO ; - gdp =ext4_get_group_desc (sb, group, &gdp_bh); -if (!gdp) - goto out_err; +while (len >0 ) { +ext4_get_group_no_and_offset (sb, block, &group, &blkoff); -ext4_lock_group (sb, group); - already =0 ; -for (i =0 ; i < clen; i++) -if (!mb_test_bit (blkoff + i, bitmap_bh->b_data) == !state) - already++; - - clen_changed = clen - already; -if (state) -ext4_set_bits (bitmap_bh->b_data, blkoff, clen); -else -mb_test_and_clear_bits (bitmap_bh->b_data, blkoff, clen); -if (ext4_has_group_desc_csum (sb) && - (gdp->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT ))) { - gdp->bg_flags &=cpu_to_le16 (~EXT4_BG_BLOCK_UNINIT ); -ext4_free_group_clusters_set (sb, gdp, -ext4_free_clusters_after_init (sb, - group, gdp)); - } -if (state) - clen =ext4_free_group_clusters (sb, gdp) - clen_changed; -else - clen =ext4_free_group_clusters (sb, gdp) + clen_changed; +/* +* Check to see if we are freeing blocks across a group +* boundary. +* In case of flex_bg, this can happen that (block, len) may +* span across more than one group. In that case we need to +* get the corresponding group metadata to work with. +* For this we have goto again loop. +*/ + thisgrp_len = min_t(unsigned int, (unsigned int)len, +EXT4_BLOCKS_PER_GROUP (sb) -EXT4_C2B (sbi, blkoff)); + clen =EXT4_NUM_B2C (sbi, thisgrp_len); -ext4_free_group_clusters_set (sb, gdp, clen); -ext4_block_bitmap_csum_set (sb, group, gdp, bitmap_bh); -ext4_group_desc_csum_set (sb, group, gdp); + bitmap_bh =ext4_read_block_bitmap (sb, group); +if (IS_ERR (bitmap_bh)) { + err =PTR_ERR (bitmap_bh); + bitmap_bh =NULL ; +break ; + } -ext4_unlock_group (sb, group); + err = -EIO ; + gdp =ext4_get_group_desc (sb, group, &gdp_bh); +if (!gdp) +break ; -if (sbi->s_log_groups_per_flex) { -ext4_group_t flex_group =ext4_flex_group (sbi, group); -struct flex_groups *fg =sbi_array_rcu_deref (sbi, - s_flex_groups, flex_group); +ext4_lock_group (sb, group); + already =0 ; +for (i =0 ; i < clen; i++) +if (!mb_test_bit (blkoff + i, bitmap_bh->b_data) == + !state) + already++; + clen_changed = clen - already;if (state) -atomic64_sub (clen_changed, &fg->free_clusters); +ext4_set_bits (bitmap_bh->b_data, blkoff, clen);else -atomic64_add (clen_changed, &fg->free_clusters); +mb_test_and_clear_bits (bitmap_bh->b_data, blkoff, clen); +if (ext4_has_group_desc_csum (sb) && + (gdp->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT ))) { + gdp->bg_flags &=cpu_to_le16 (~EXT4_BG_BLOCK_UNINIT ); +ext4_free_group_clusters_set (sb, gdp, +ext4_free_clusters_after_init (sb, group, gdp)); + } +if (state) + clen =ext4_free_group_clusters (sb, gdp) - clen_changed; +else + clen =ext4_free_group_clusters (sb, gdp) + clen_changed; + +ext4_free_group_clusters_set (sb, gdp, clen); +ext4_block_bitmap_csum_set (sb, group, gdp, bitmap_bh); +ext4_group_desc_csum_set (sb, group, gdp); + +ext4_unlock_group (sb, group); + +if (sbi->s_log_groups_per_flex) { +ext4_group_t flex_group =ext4_flex_group (sbi, group); +struct flex_groups *fg =sbi_array_rcu_deref (sbi, + s_flex_groups, flex_group); + +if (state) +atomic64_sub (clen_changed, &fg->free_clusters); +else +atomic64_add (clen_changed, &fg->free_clusters); + + } + + err =ext4_handle_dirty_metadata (NULL ,NULL , bitmap_bh); +if (err) +break ; +sync_dirty_buffer (bitmap_bh); + err =ext4_handle_dirty_metadata (NULL ,NULL , gdp_bh); +sync_dirty_buffer (gdp_bh); +if (err) +break ; + + block += thisgrp_len; + len -= thisgrp_len; +brelse (bitmap_bh); +BUG_ON (len <0 ); } - err =ext4_handle_dirty_metadata (NULL ,NULL , bitmap_bh);if (err) - goto out_err; -sync_dirty_buffer (bitmap_bh); - err =ext4_handle_dirty_metadata (NULL ,NULL , gdp_bh); -sync_dirty_buffer (gdp_bh); - -out_err: -brelse (bitmap_bh); +brelse (bitmap_bh); }/*
Signature · 1 line
2.34.1
syzbot
syzbotRe: [PATCH AUTOSEL 5.10 4/8] ext4: don't BUG if someone dirty pages without asking ext4 first
In reply to Sasha LevinI see the command but can't find the corresponding bug. The email is sent to [email protected] address but the HASH does not correspond to any known bug. Please double check the…
Quoted 79 lines
From: Theodore Ts'o <[email protected]>
[ Upstream commit
cc5095747edfb054ca2068d01af20be3fcc3634f][un]pin_user_pages_remote is dirtying pages without properly warning the file system in advance. A related race was noted by Jan Kara in 2018[1]; however, more recently instead of it being a very hard-to-hit race, it could be reliably triggered by
process_vm_writev(2)which was discovered by Syzbot[2].This is technically a bug in
mm/gup.c, but arguably ext4 is fragile in that if some other kernel subsystem dirty pages without properly notifying the file system usingpage_mkwrite(), ext4 will BUG, while other file systems will not BUG (although data will still be lost).So instead of crashing with a BUG, issue a warning (since there may be potential data loss) and just mark the page as clean to avoid unprivileged denial of service attacks until the problem can be properly fixed. More discussion and background can be found in the thread starting at [2].
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/r/[email protected]Reported-by Lee Jones <[email protected]>Signed-off-by Theodore Ts'o <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- fs/ext4/inode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)fs/ext4/inode.c +25
-0@@ -2023,6 +2023,15 @@ static int ext4_writepage(struct page *page,else len =PAGE_SIZE ; +/* Should never happen but for bugs in other kernel subsystems */ +if (!page_has_buffers (page)) { +ext4_warning_inode (inode, +"page %lu does not have buffers attached" , page->index); +ClearPageDirty (page); +unlock_page (page); +return 0 ; + } + page_bufs =page_buffers (page);/* * We cannot do block allocation or other extent handling in this @@ -2626,6 +2635,22 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)wait_on_page_writeback (page);BUG_ON (PageWriteback (page)); +/* +* Should never happen but for buggy code in +* other subsystems that call +* set_page_dirty() without properly warning +* the file system first. See [1] for more +* information. +* +* [1] https://lore.kernel.org/linux-mm/[email protected] +*/ +if (!page_has_buffers (page)) { +ext4_warning_inode (mpd->inode,"page %lu does not have buffers attached" , page->index); +ClearPageDirty (page); +unlock_page (page); +continue ; + } +if (mpd->map.m_len ==0 ) mpd->first_page = page->index; mpd->next_page = page->index +1 ;Signature · 1 line
2.34.1
I see the command but can't find the corresponding bug. The email is sent to [email protected] address but the HASH does not correspond to any known bug. Please double check the address.
Sasha Levin
maintainerPATCH 4/8 ext4: don't BUG if someone dirty pages without asking ext4 first
In reply to Sasha LevinFrom: Theodore Ts'o <[email protected]>
[ Upstream commit cc5095747edfb054ca2068d01af20be3fcc3634f ]
[un]pin_user_pages_remote is dirtying pages without properly warning the file system in advance. A related race was noted by Jan Kara in 2018[1]; however, more recently instead of it being a very hard-to-hit race, it could be reliably triggered by process_vm_writev(2) which was discovered by Syzbot[2].
This is technically a bug in mm/gup.c, but arguably ext4 is fragile in that if some other kernel subsystem dirty pages without properly notifying the file system using page_mkwrite(), ext4 will BUG, while other file systems will not BUG (although data will still be lost).
So instead of crashing with a BUG, issue a warning (since there may be potential data loss) and just mark the page as clean to avoid unprivileged denial of service attacks until the problem can be properly fixed. More discussion and background can be found in the thread starting at [2].
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/r/[email protected]
--- fs/ext4/inode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
fs/ext4/inode.c +25 -0
@@ -2023,6 +2023,15 @@ static int ext4_writepage(struct page *page,else len =PAGE_SIZE ; +/* Should never happen but for bugs in other kernel subsystems */ +if (!page_has_buffers (page)) { +ext4_warning_inode (inode, +"page %lu does not have buffers attached" , page->index); +ClearPageDirty (page); +unlock_page (page); +return 0 ; + } + page_bufs =page_buffers (page);/* * We cannot do block allocation or other extent handling in this
@@ -2626,6 +2635,22 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)wait_on_page_writeback (page);BUG_ON (PageWriteback (page)); +/* +* Should never happen but for buggy code in +* other subsystems that call +* set_page_dirty() without properly warning +* the file system first. See [1] for more +* information. +* +* [1] https://lore.kernel.org/linux-mm/[email protected] +*/ +if (!page_has_buffers (page)) { +ext4_warning_inode (mpd->inode,"page %lu does not have buffers attached" , page->index); +ClearPageDirty (page); +unlock_page (page); +continue ; + } +if (mpd->map.m_len ==0 ) mpd->first_page = page->index; mpd->next_page = page->index +1 ;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 6/8 NFSD: Fix nfsd_breaker_owns_lease() return values
In reply to Sasha LevinFrom: Chuck Lever <[email protected]>
[ Upstream commit 50719bf3442dd6cd05159e9c98d020b3919ce978 ]
These have been incorrect since the function was introduced.
A proper kerneldoc comment is added since this function, though static, is part of an external interface.
--- fs/nfsd/nfs4state.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +10 -2
@@ -4607,6 +4607,14 @@ nfsd_break_deleg_cb(struct file_lock *fl)return ret; } +/** +* nfsd_breaker_owns_lease - Check if lease conflict was resolved +* @fl: Lock state to check +* +* Return values: +* %true: Lease conflict was resolved +* %false: Lease conflict was not resolved. +*/ static bool nfsd_breaker_owns_lease (struct file_lock *fl) {struct nfs4_delegation *dl = fl->fl_owner;
@@ -4614,11 +4622,11 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl)struct nfs4_client *clp;if (!i_am_nfsd ()) -return NULL ; +return false; rqst =kthread_data (current);/* Note rq_prog == NFS_ACL_PROGRAM is also possible: */ if (rqst->rq_prog !=NFS_PROGRAM || rqst->rq_vers <4 ) -return NULL ; +return false; clp = *(rqst->rq_lease_breaker);return dl->dl_stid.sc_client == clp; }
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 1/8 locking/lockdep: Iterate lock_classes directly when reading lockdep files
From: Waiman Long <[email protected]>
[ Upstream commit fb7275acd6fb988313dddd8d3d19efa70d9015ad ]
When dumping lock_classes information via /proc/lockdep, we can't take the lockdep lock as the lock hold time is indeterminate. Iterating over all_lock_classes without holding lock can be dangerous as there is a slight chance that it may branch off to other lists leading to infinite loop or even access invalid memory if changes are made to all_lock_classes list in parallel.
To avoid this problem, iteration of lock classes is now done directly on the lock_classes array itself. The lock_classes_in_use bitmap is checked to see if the lock class is being used. To avoid iterating the full array all the times, a new max_lock_class_idx value is added to track the maximum lock_class index that is currently being used.
We can theoretically take the lockdep lock for iterating all_lock_classes when other lockdep files (lockdep_stats and lock_stat) are accessed as the lock hold time will be shorter for them. For consistency, they are also modified to iterate the lock_classes array directly.
--- kernel/locking/lockdep.c | 14 +++++--- kernel/locking/lockdep_internals.h | 6 ++-- kernel/locking/lockdep_proc.c | 51 +++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 15 deletions(-)
kernel/locking/lockdep.c +9 -5
@@ -182,11 +182,9 @@ static DECLARE_BITMAP(list_entries_in_use, MAX_LOCKDEP_ENTRIES);static struct hlist_head lock_keys_hash[KEYHASH_SIZE ];unsigned long nr_lock_classes;unsigned long nr_zapped_classes; -#ifndef CONFIG_DEBUG_LOCKDEP -static -#endif +unsigned long max_lock_class_idx;struct lock_class lock_classes[MAX_LOCKDEP_KEYS ]; -static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS); +DECLARE_BITMAP (lock_classes_in_use,MAX_LOCKDEP_KEYS );static inline struct lock_class *hlock_class (struct held_lock *hlock) {
@@ -337,7 +335,7 @@ static inline void lock_release_holdtime(struct held_lock *hlock)* elements. These elements are linked together by the lock_entry member in * struct lock_class. */ -LIST_HEAD (all_lock_classes); +static LIST_HEAD (all_lock_classes);static LIST_HEAD (free_lock_classes);/**
@@ -1239,6 +1237,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)struct lockdep_subclass_key *key;struct hlist_head *hash_head;struct lock_class *class; +int idx;DEBUG_LOCKS_WARN_ON (!irqs_disabled ());
@@ -1304,6 +1303,9 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)* of classes. */ list_move_tail (&class->lock_entry, &all_lock_classes); + idx = class - lock_classes; +if (idx > max_lock_class_idx) + max_lock_class_idx = idx;if (verbose (class)) {graph_unlock ();
@@ -5919,6 +5921,8 @@ static void zap_class(struct pending_free *pf, struct lock_class *class)WRITE_ONCE (class->name,NULL ); nr_lock_classes--;__clear_bit (class - lock_classes, lock_classes_in_use); +if (class - lock_classes == max_lock_class_idx) + max_lock_class_idx--; }else {WARN_ONCE (true,"%s() failed for class %s\n" , __func__, class->name);
kernel/locking/lockdep_internals.h +4 -2
@@ -121,7 +121,6 @@ static const unsigned long LOCKF_USED_IN_IRQ_READ =#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5) -extern struct list_head all_lock_classes;extern struct lock_chain lock_chains[];#define LOCK_USAGE_CHARS (2*XXX_LOCK_USAGE_STATES + 1)
@@ -151,6 +150,10 @@ extern unsigned int nr_large_chain_blocks;extern unsigned int max_lockdep_depth;extern unsigned int max_bfs_queue_depth; +extern unsigned long max_lock_class_idx; + +extern struct lock_class lock_classes[MAX_LOCKDEP_KEYS ]; +extern unsigned long lock_classes_in_use[];#ifdef CONFIG_PROVE_LOCKING extern unsigned long lockdep_count_forward_deps (struct lock_class *);
@@ -205,7 +208,6 @@ struct lockdep_stats { }; DECLARE_PER_CPU(struct lockdep_stats, lockdep_stats); -extern struct lock_class lock_classes[MAX_LOCKDEP_KEYS ];#define __debug_atomic_inc (ptr) \ this_cpu_inc(lockdep_stats.ptr);
kernel/locking/lockdep_proc.c +43 -8
117 lines not on this page · raw message
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 8/8 ntfs: add sanity check on allocation size
From: Dongliang Mu <[email protected]>
[ Upstream commit 714fbf2647b1a33d914edd695d4da92029c7e7c0 ]
ntfs_read_inode_mount invokes ntfs_malloc_nofs with zero allocation size. It triggers one BUG in the __ntfs_malloc function.
Fix this by adding sanity check on ni->attr_list_size.
--- fs/ntfs/inode.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ntfs/inode.c +4 -0
@@ -1881,6 +1881,10 @@ int ntfs_read_inode_mount(struct inode *vi) }/* Now allocate memory for the attribute list. */ ni->attr_list_size = (u32 )ntfs_attr_size (a); +if (!ni->attr_list_size) { +ntfs_error (sb,"Attr_list_size is zero" ); + goto put_err_out; + } ni->attr_list =ntfs_malloc_nofs (ni->attr_list_size);if (!ni->attr_list) { ntfs_error(sb, "Not enough memory to allocate buffer "
Signature · 1 line
2.34.1