lkml.org 
[lkml]   [2018]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/1] f2fs: fix validation of the block count in sanity_check_raw_super
Hi Martin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on f2fs/dev-test]
[also build test WARNING on v4.20-rc7 next-20181221]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Martin-Blumenstingl/f2fs-fix-sanity_check_raw_super-on-big-endian-machines/20181222-142616
base: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test
config: i386-randconfig-x006-201850 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386

All warnings (new ones prefixed by >>):

fs/f2fs/super.c: In function 'sanity_check_raw_super':
>> fs/f2fs/super.c:2498:46: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'long long unsigned int' [-Wformat=]
"Wrong segment_count / block_count (%u > %u)",
~^
%llu

vim +2498 fs/f2fs/super.c

9a59b62fd Chao Yu 2015-12-15 2382
df728b0f6 Jaegeuk Kim 2016-03-23 2383 static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
fd694733d Jaegeuk Kim 2016-03-20 2384 struct buffer_head *bh)
aff063e26 Jaegeuk Kim 2012-11-02 2385 {
0cfe75c5b Jaegeuk Kim 2018-04-27 2386 block_t segment_count, segs_per_sec, secs_per_zone;
0cfe75c5b Jaegeuk Kim 2018-04-27 2387 block_t total_sections, blocks_per_seg;
fd694733d Jaegeuk Kim 2016-03-20 2388 struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
fd694733d Jaegeuk Kim 2016-03-20 2389 (bh->b_data + F2FS_SUPER_OFFSET);
df728b0f6 Jaegeuk Kim 2016-03-23 2390 struct super_block *sb = sbi->sb;
aff063e26 Jaegeuk Kim 2012-11-02 2391 unsigned int blocksize;
d440c52d3 Junling Zheng 2018-09-28 2392 size_t crc_offset = 0;
d440c52d3 Junling Zheng 2018-09-28 2393 __u32 crc = 0;
d440c52d3 Junling Zheng 2018-09-28 2394
d440c52d3 Junling Zheng 2018-09-28 2395 /* Check checksum_offset and crc in superblock */
7beb01f74 Chao Yu 2018-10-24 2396 if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) {
d440c52d3 Junling Zheng 2018-09-28 2397 crc_offset = le32_to_cpu(raw_super->checksum_offset);
d440c52d3 Junling Zheng 2018-09-28 2398 if (crc_offset !=
d440c52d3 Junling Zheng 2018-09-28 2399 offsetof(struct f2fs_super_block, crc)) {
d440c52d3 Junling Zheng 2018-09-28 2400 f2fs_msg(sb, KERN_INFO,
d440c52d3 Junling Zheng 2018-09-28 2401 "Invalid SB checksum offset: %zu",
d440c52d3 Junling Zheng 2018-09-28 2402 crc_offset);
d440c52d3 Junling Zheng 2018-09-28 2403 return 1;
d440c52d3 Junling Zheng 2018-09-28 2404 }
d440c52d3 Junling Zheng 2018-09-28 2405 crc = le32_to_cpu(raw_super->crc);
d440c52d3 Junling Zheng 2018-09-28 2406 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
d440c52d3 Junling Zheng 2018-09-28 2407 f2fs_msg(sb, KERN_INFO,
d440c52d3 Junling Zheng 2018-09-28 2408 "Invalid SB checksum value: %u", crc);
d440c52d3 Junling Zheng 2018-09-28 2409 return 1;
d440c52d3 Junling Zheng 2018-09-28 2410 }
d440c52d3 Junling Zheng 2018-09-28 2411 }
aff063e26 Jaegeuk Kim 2012-11-02 2412
a07ef7843 Namjae Jeon 2012-12-30 2413 if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) {
a07ef7843 Namjae Jeon 2012-12-30 2414 f2fs_msg(sb, KERN_INFO,
a07ef7843 Namjae Jeon 2012-12-30 2415 "Magic Mismatch, valid(0x%x) - read(0x%x)",
a07ef7843 Namjae Jeon 2012-12-30 2416 F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
aff063e26 Jaegeuk Kim 2012-11-02 2417 return 1;
a07ef7843 Namjae Jeon 2012-12-30 2418 }
aff063e26 Jaegeuk Kim 2012-11-02 2419
5c9b46929 majianpeng 2013-02-01 2420 /* Currently, support only 4KB page cache size */
09cbfeaf1 Kirill A. Shutemov 2016-04-01 2421 if (F2FS_BLKSIZE != PAGE_SIZE) {
5c9b46929 majianpeng 2013-02-01 2422 f2fs_msg(sb, KERN_INFO,
14d7e9de0 majianpeng 2013-02-01 2423 "Invalid page_cache_size (%lu), supports only 4KB\n",
09cbfeaf1 Kirill A. Shutemov 2016-04-01 2424 PAGE_SIZE);
5c9b46929 majianpeng 2013-02-01 2425 return 1;
5c9b46929 majianpeng 2013-02-01 2426 }
5c9b46929 majianpeng 2013-02-01 2427
aff063e26 Jaegeuk Kim 2012-11-02 2428 /* Currently, support only 4KB block size */
aff063e26 Jaegeuk Kim 2012-11-02 2429 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
5c9b46929 majianpeng 2013-02-01 2430 if (blocksize != F2FS_BLKSIZE) {
a07ef7843 Namjae Jeon 2012-12-30 2431 f2fs_msg(sb, KERN_INFO,
a07ef7843 Namjae Jeon 2012-12-30 2432 "Invalid blocksize (%u), supports only 4KB\n",
a07ef7843 Namjae Jeon 2012-12-30 2433 blocksize);
aff063e26 Jaegeuk Kim 2012-11-02 2434 return 1;
a07ef7843 Namjae Jeon 2012-12-30 2435 }
5c9b46929 majianpeng 2013-02-01 2436
9a59b62fd Chao Yu 2015-12-15 2437 /* check log blocks per segment */
9a59b62fd Chao Yu 2015-12-15 2438 if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) {
9a59b62fd Chao Yu 2015-12-15 2439 f2fs_msg(sb, KERN_INFO,
9a59b62fd Chao Yu 2015-12-15 2440 "Invalid log blocks per segment (%u)\n",
9a59b62fd Chao Yu 2015-12-15 2441 le32_to_cpu(raw_super->log_blocks_per_seg));
9a59b62fd Chao Yu 2015-12-15 2442 return 1;
9a59b62fd Chao Yu 2015-12-15 2443 }
9a59b62fd Chao Yu 2015-12-15 2444
55cf9cb63 Chao Yu 2014-09-15 2445 /* Currently, support 512/1024/2048/4096 bytes sector size */
55cf9cb63 Chao Yu 2014-09-15 2446 if (le32_to_cpu(raw_super->log_sectorsize) >
55cf9cb63 Chao Yu 2014-09-15 2447 F2FS_MAX_LOG_SECTOR_SIZE ||
55cf9cb63 Chao Yu 2014-09-15 2448 le32_to_cpu(raw_super->log_sectorsize) <
55cf9cb63 Chao Yu 2014-09-15 2449 F2FS_MIN_LOG_SECTOR_SIZE) {
55cf9cb63 Chao Yu 2014-09-15 2450 f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize (%u)",
55cf9cb63 Chao Yu 2014-09-15 2451 le32_to_cpu(raw_super->log_sectorsize));
aff063e26 Jaegeuk Kim 2012-11-02 2452 return 1;
a07ef7843 Namjae Jeon 2012-12-30 2453 }
55cf9cb63 Chao Yu 2014-09-15 2454 if (le32_to_cpu(raw_super->log_sectors_per_block) +
55cf9cb63 Chao Yu 2014-09-15 2455 le32_to_cpu(raw_super->log_sectorsize) !=
55cf9cb63 Chao Yu 2014-09-15 2456 F2FS_MAX_LOG_SECTOR_SIZE) {
55cf9cb63 Chao Yu 2014-09-15 2457 f2fs_msg(sb, KERN_INFO,
55cf9cb63 Chao Yu 2014-09-15 2458 "Invalid log sectors per block(%u) log sectorsize(%u)",
55cf9cb63 Chao Yu 2014-09-15 2459 le32_to_cpu(raw_super->log_sectors_per_block),
55cf9cb63 Chao Yu 2014-09-15 2460 le32_to_cpu(raw_super->log_sectorsize));
aff063e26 Jaegeuk Kim 2012-11-02 2461 return 1;
a07ef7843 Namjae Jeon 2012-12-30 2462 }
9a59b62fd Chao Yu 2015-12-15 2463
0cfe75c5b Jaegeuk Kim 2018-04-27 2464 segment_count = le32_to_cpu(raw_super->segment_count);
0cfe75c5b Jaegeuk Kim 2018-04-27 2465 segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
0cfe75c5b Jaegeuk Kim 2018-04-27 2466 secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
0cfe75c5b Jaegeuk Kim 2018-04-27 2467 total_sections = le32_to_cpu(raw_super->section_count);
0cfe75c5b Jaegeuk Kim 2018-04-27 2468
0cfe75c5b Jaegeuk Kim 2018-04-27 2469 /* blocks_per_seg should be 512, given the above check */
0cfe75c5b Jaegeuk Kim 2018-04-27 2470 blocks_per_seg = 1 << le32_to_cpu(raw_super->log_blocks_per_seg);
0cfe75c5b Jaegeuk Kim 2018-04-27 2471
0cfe75c5b Jaegeuk Kim 2018-04-27 2472 if (segment_count > F2FS_MAX_SEGMENT ||
0cfe75c5b Jaegeuk Kim 2018-04-27 2473 segment_count < F2FS_MIN_SEGMENTS) {
0cfe75c5b Jaegeuk Kim 2018-04-27 2474 f2fs_msg(sb, KERN_INFO,
0cfe75c5b Jaegeuk Kim 2018-04-27 2475 "Invalid segment count (%u)",
0cfe75c5b Jaegeuk Kim 2018-04-27 2476 segment_count);
0cfe75c5b Jaegeuk Kim 2018-04-27 2477 return 1;
0cfe75c5b Jaegeuk Kim 2018-04-27 2478 }
0cfe75c5b Jaegeuk Kim 2018-04-27 2479
0cfe75c5b Jaegeuk Kim 2018-04-27 2480 if (total_sections > segment_count ||
0cfe75c5b Jaegeuk Kim 2018-04-27 2481 total_sections < F2FS_MIN_SEGMENTS ||
0cfe75c5b Jaegeuk Kim 2018-04-27 2482 segs_per_sec > segment_count || !segs_per_sec) {
0cfe75c5b Jaegeuk Kim 2018-04-27 2483 f2fs_msg(sb, KERN_INFO,
0cfe75c5b Jaegeuk Kim 2018-04-27 2484 "Invalid segment/section count (%u, %u x %u)",
0cfe75c5b Jaegeuk Kim 2018-04-27 2485 segment_count, total_sections, segs_per_sec);
0cfe75c5b Jaegeuk Kim 2018-04-27 2486 return 1;
0cfe75c5b Jaegeuk Kim 2018-04-27 2487 }
0cfe75c5b Jaegeuk Kim 2018-04-27 2488
0cfe75c5b Jaegeuk Kim 2018-04-27 2489 if ((segment_count / segs_per_sec) < total_sections) {
0cfe75c5b Jaegeuk Kim 2018-04-27 2490 f2fs_msg(sb, KERN_INFO,
0cfe75c5b Jaegeuk Kim 2018-04-27 2491 "Small segment_count (%u < %u * %u)",
0cfe75c5b Jaegeuk Kim 2018-04-27 2492 segment_count, segs_per_sec, total_sections);
0cfe75c5b Jaegeuk Kim 2018-04-27 2493 return 1;
0cfe75c5b Jaegeuk Kim 2018-04-27 2494 }
0cfe75c5b Jaegeuk Kim 2018-04-27 2495
096ee6221 Martin Blumenstingl 2018-12-21 2496 if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) {
0cfe75c5b Jaegeuk Kim 2018-04-27 2497 f2fs_msg(sb, KERN_INFO,
0cfe75c5b Jaegeuk Kim 2018-04-27 @2498 "Wrong segment_count / block_count (%u > %u)",
096ee6221 Martin Blumenstingl 2018-12-21 2499 segment_count, le64_to_cpu(raw_super->block_count));
0cfe75c5b Jaegeuk Kim 2018-04-27 2500 return 1;
0cfe75c5b Jaegeuk Kim 2018-04-27 2501 }
0cfe75c5b Jaegeuk Kim 2018-04-27 2502
42bf546c1 Chao Yu 2018-06-23 2503 if (secs_per_zone > total_sections || !secs_per_zone) {
0cfe75c5b Jaegeuk Kim 2018-04-27 2504 f2fs_msg(sb, KERN_INFO,
42bf546c1 Chao Yu 2018-06-23 2505 "Wrong secs_per_zone / total_sections (%u, %u)",
0cfe75c5b Jaegeuk Kim 2018-04-27 2506 secs_per_zone, total_sections);
0cfe75c5b Jaegeuk Kim 2018-04-27 2507 return 1;
0cfe75c5b Jaegeuk Kim 2018-04-27 2508 }
0cfe75c5b Jaegeuk Kim 2018-04-27 2509 if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION ||
0cfe75c5b Jaegeuk Kim 2018-04-27 2510 raw_super->hot_ext_count > F2FS_MAX_EXTENSION ||
0cfe75c5b Jaegeuk Kim 2018-04-27 2511 (le32_to_cpu(raw_super->extension_count) +
0cfe75c5b Jaegeuk Kim 2018-04-27 2512 raw_super->hot_ext_count) > F2FS_MAX_EXTENSION) {
0cfe75c5b Jaegeuk Kim 2018-04-27 2513 f2fs_msg(sb, KERN_INFO,
0cfe75c5b Jaegeuk Kim 2018-04-27 2514 "Corrupted extension count (%u + %u > %u)",
0cfe75c5b Jaegeuk Kim 2018-04-27 2515 le32_to_cpu(raw_super->extension_count),
0cfe75c5b Jaegeuk Kim 2018-04-27 2516 raw_super->hot_ext_count,
0cfe75c5b Jaegeuk Kim 2018-04-27 2517 F2FS_MAX_EXTENSION);
0cfe75c5b Jaegeuk Kim 2018-04-27 2518 return 1;
0cfe75c5b Jaegeuk Kim 2018-04-27 2519 }
0cfe75c5b Jaegeuk Kim 2018-04-27 2520
0cfe75c5b Jaegeuk Kim 2018-04-27 2521 if (le32_to_cpu(raw_super->cp_payload) >
0cfe75c5b Jaegeuk Kim 2018-04-27 2522 (blocks_per_seg - F2FS_CP_PACKS)) {
0cfe75c5b Jaegeuk Kim 2018-04-27 2523 f2fs_msg(sb, KERN_INFO,
0cfe75c5b Jaegeuk Kim 2018-04-27 2524 "Insane cp_payload (%u > %u)",
0cfe75c5b Jaegeuk Kim 2018-04-27 2525 le32_to_cpu(raw_super->cp_payload),
0cfe75c5b Jaegeuk Kim 2018-04-27 2526 blocks_per_seg - F2FS_CP_PACKS);
0cfe75c5b Jaegeuk Kim 2018-04-27 2527 return 1;
0cfe75c5b Jaegeuk Kim 2018-04-27 2528 }
0cfe75c5b Jaegeuk Kim 2018-04-27 2529
9a59b62fd Chao Yu 2015-12-15 2530 /* check reserved ino info */
9a59b62fd Chao Yu 2015-12-15 2531 if (le32_to_cpu(raw_super->node_ino) != 1 ||
9a59b62fd Chao Yu 2015-12-15 2532 le32_to_cpu(raw_super->meta_ino) != 2 ||
9a59b62fd Chao Yu 2015-12-15 2533 le32_to_cpu(raw_super->root_ino) != 3) {
9a59b62fd Chao Yu 2015-12-15 2534 f2fs_msg(sb, KERN_INFO,
9a59b62fd Chao Yu 2015-12-15 2535 "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
9a59b62fd Chao Yu 2015-12-15 2536 le32_to_cpu(raw_super->node_ino),
9a59b62fd Chao Yu 2015-12-15 2537 le32_to_cpu(raw_super->meta_ino),
9a59b62fd Chao Yu 2015-12-15 2538 le32_to_cpu(raw_super->root_ino));
9a59b62fd Chao Yu 2015-12-15 2539 return 1;
9a59b62fd Chao Yu 2015-12-15 2540 }
9a59b62fd Chao Yu 2015-12-15 2541
9a59b62fd Chao Yu 2015-12-15 2542 /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
df728b0f6 Jaegeuk Kim 2016-03-23 2543 if (sanity_check_area_boundary(sbi, bh))
9a59b62fd Chao Yu 2015-12-15 2544 return 1;
9a59b62fd Chao Yu 2015-12-15 2545
aff063e26 Jaegeuk Kim 2012-11-02 2546 return 0;
aff063e26 Jaegeuk Kim 2012-11-02 2547 }
aff063e26 Jaegeuk Kim 2012-11-02 2548

:::::: The code at line 2498 was first introduced by commit
:::::: 0cfe75c5b011994651a4ca6d74f20aa997bfc69a f2fs: enhance sanity_check_raw_super() to avoid potential overflows

:::::: TO: Jaegeuk Kim <jaegeuk@kernel.org>
:::::: CC: Jaegeuk Kim <jaegeuk@kernel.org>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[unhandled content-type:application/gzip]
\
 
 \ /
  Last update: 2018-12-22 17:56    [W:0.118 / U:2.756 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site