[bug report] btrfs: Add type check when reading a chunk

5 messages, 3 authors, 2018-07-20 · open the first message on its own page

[bug report] btrfs: Add type check when reading a chunk

From: Dan Carpenter <hidden>
Date: 2018-07-19 08:53:19

Hello Gu Jinxiang,

The patch 72e75ed03c8d: "btrfs: Add type check when reading a chunk"
from Jul 4, 2018, leads to the following static checker warning:

	fs/btrfs/volumes.c:6388 btrfs_check_chunk_valid()
	warn: AND to zero '0x4 & 0x1'

fs/btrfs/volumes.c
  6356          if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
  6357                  btrfs_err(fs_info, "invalid chunk stripe length: %llu",
  6358                            stripe_len);
  6359                  return -EIO;
  6360          }
  6361          if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6362              type) {
  6363                  btrfs_err(fs_info, "unrecognized chunk type: %llu",
  6364                            ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
  6365                              BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6366                            btrfs_chunk_type(leaf, chunk));
  6367                  return -EIO;
  6368          }
  6369  
  6370          if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) {
  6371                  btrfs_err(fs_info, "missing chunk type flag: %llu", type);
  6372                  return -EIO;
  6373          }
  6374  
  6375          if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
  6376              (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
  6377                  btrfs_err(fs_info,
  6378                          "system chunk with data or metadata type: %llu", type);
  6379                  return -EIO;
  6380          }
  6381  
  6382          features = btrfs_super_incompat_flags(fs_info->super_copy);
  6383          if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
  6384                  mixed = 1;
  6385  
  6386          if (!mixed) {
  6387                  if (type &
  6388                      (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) {
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Was this supposed to be | or perhaps check that both are set?

  6389                          btrfs_err(fs_info,
  6390                          "mixed chunk type in non-mixed mode: %llu", type);
  6391                          return -EIO;
  6392                  }
  6393          }

regards,
dan carpenter

RE: [bug report] btrfs: Add type check when reading a chunk

From: Gu, Jinxiang <hidden>
Date: 2018-07-19 09:00:27

-----Original Message-----
From: Dan Carpenter [mailto:dan.carpenter@oracle.com]
Sent: Thursday, July 19, 2018 4:11 PM
To: Gu, Jinxiang/顾 金香 <redacted>
Cc: linux-btrfs@vger.kernel.org
Subject: [bug report] btrfs: Add type check when reading a chunk

Hello Gu Jinxiang,

The patch 72e75ed03c8d: "btrfs: Add type check when reading a chunk"
from Jul 4, 2018, leads to the following static checker warning:

	fs/btrfs/volumes.c:6388 btrfs_check_chunk_valid()
	warn: AND to zero '0x4 & 0x1'

fs/btrfs/volumes.c
  6356          if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
  6357                  btrfs_err(fs_info, "invalid chunk stripe length: %llu",
  6358                            stripe_len);
  6359                  return -EIO;
  6360          }
  6361          if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6362              type) {
  6363                  btrfs_err(fs_info, "unrecognized chunk type: %llu",
  6364                            ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
  6365                              BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6366                            btrfs_chunk_type(leaf, chunk));
  6367                  return -EIO;
  6368          }
  6369
  6370          if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) {
  6371                  btrfs_err(fs_info, "missing chunk type flag: %llu", type);
  6372                  return -EIO;
  6373          }
  6374
  6375          if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
  6376              (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
  6377                  btrfs_err(fs_info,
  6378                          "system chunk with data or metadata type: %llu", type);
  6379                  return -EIO;
  6380          }
  6381
  6382          features = btrfs_super_incompat_flags(fs_info->super_copy);
  6383          if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
  6384                  mixed = 1;
  6385
  6386          if (!mixed) {
  6387                  if (type &
  6388                      (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) {
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Was this supposed to be | or perhaps check that both are set?
Yes. It should be |.
Thank you, I'll send a patch to fix it.
  6389                          btrfs_err(fs_info,
  6390                          "mixed chunk type in non-mixed mode: %llu", type);
  6391                          return -EIO;
  6392                  }
  6393          }

regards,
dan carpenter


�翳�{.n�+�������+%���遍荻��w��{.n�+�伐�{饼�k~镶��^n�r■�z���h�ㄨ��&{�z夸z罐��+��+zf"�h���~����i�������赙z_璁�j:+v���)撸�m

Re: [bug report] btrfs: Add type check when reading a chunk

From: David Sterba <hidden>
Date: 2018-07-19 10:04:23

On Thu, Jul 19, 2018 at 08:18:25AM +0000, Gu, Jinxiang wrote:
quoted
-----Original Message-----
From: Dan Carpenter [mailto:dan.carpenter@oracle.com]
Sent: Thursday, July 19, 2018 4:11 PM
To: Gu, Jinxiang/顾 金香 <redacted>
Cc: linux-btrfs@vger.kernel.org
Subject: [bug report] btrfs: Add type check when reading a chunk

Hello Gu Jinxiang,

The patch 72e75ed03c8d: "btrfs: Add type check when reading a chunk"
from Jul 4, 2018, leads to the following static checker warning:

	fs/btrfs/volumes.c:6388 btrfs_check_chunk_valid()
	warn: AND to zero '0x4 & 0x1'

fs/btrfs/volumes.c
  6356          if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
  6357                  btrfs_err(fs_info, "invalid chunk stripe length: %llu",
  6358                            stripe_len);
  6359                  return -EIO;
  6360          }
  6361          if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6362              type) {
  6363                  btrfs_err(fs_info, "unrecognized chunk type: %llu",
  6364                            ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
  6365                              BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6366                            btrfs_chunk_type(leaf, chunk));
  6367                  return -EIO;
  6368          }
  6369
  6370          if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) {
  6371                  btrfs_err(fs_info, "missing chunk type flag: %llu", type);
  6372                  return -EIO;
  6373          }
  6374
  6375          if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
  6376              (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
  6377                  btrfs_err(fs_info,
  6378                          "system chunk with data or metadata type: %llu", type);
  6379                  return -EIO;
  6380          }
  6381
  6382          features = btrfs_super_incompat_flags(fs_info->super_copy);
  6383          if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
  6384                  mixed = 1;
  6385
  6386          if (!mixed) {
  6387                  if (type &
  6388                      (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) {
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Was this supposed to be | or perhaps check that both are set?
Yes. It should be |.
Thank you, I'll send a patch to fix it.
Not needed, I'll fix the patch directly.

Re: [bug report] btrfs: Add type check when reading a chunk

From: David Sterba <hidden>
Date: 2018-07-19 10:56:37

On Thu, Jul 19, 2018 at 11:22:01AM +0200, David Sterba wrote:
On Thu, Jul 19, 2018 at 08:18:25AM +0000, Gu, Jinxiang wrote:
quoted
quoted
-----Original Message-----
From: Dan Carpenter [mailto:dan.carpenter@oracle.com]
Sent: Thursday, July 19, 2018 4:11 PM
To: Gu, Jinxiang/顾 金香 <redacted>
Cc: linux-btrfs@vger.kernel.org
Subject: [bug report] btrfs: Add type check when reading a chunk

Hello Gu Jinxiang,

The patch 72e75ed03c8d: "btrfs: Add type check when reading a chunk"
from Jul 4, 2018, leads to the following static checker warning:

	fs/btrfs/volumes.c:6388 btrfs_check_chunk_valid()
	warn: AND to zero '0x4 & 0x1'

fs/btrfs/volumes.c
  6356          if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
  6357                  btrfs_err(fs_info, "invalid chunk stripe length: %llu",
  6358                            stripe_len);
  6359                  return -EIO;
  6360          }
  6361          if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6362              type) {
  6363                  btrfs_err(fs_info, "unrecognized chunk type: %llu",
  6364                            ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
  6365                              BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6366                            btrfs_chunk_type(leaf, chunk));
  6367                  return -EIO;
  6368          }
  6369
  6370          if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) {
  6371                  btrfs_err(fs_info, "missing chunk type flag: %llu", type);
  6372                  return -EIO;
  6373          }
  6374
  6375          if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
  6376              (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
  6377                  btrfs_err(fs_info,
  6378                          "system chunk with data or metadata type: %llu", type);
  6379                  return -EIO;
  6380          }
  6381
  6382          features = btrfs_super_incompat_flags(fs_info->super_copy);
  6383          if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
  6384                  mixed = 1;
  6385
  6386          if (!mixed) {
  6387                  if (type &
  6388                      (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) {
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Was this supposed to be | or perhaps check that both are set?
Yes. It should be |.
Thank you, I'll send a patch to fix it.
Not needed, I'll fix the patch directly.
And that leads to failed mount:

[   10.867868] BTRFS error (device vda): mixed chunk type in non-mixed mode: 1
[   10.871084] BTRFS error (device vda): failed to read chunk tree: -5
[   10.908541] BTRFS error (device vda): open_ctree failed

Please send fixed version.

RE: [bug report] btrfs: Add type check when reading a chunk

From: Gu, Jinxiang <hidden>
Date: 2018-07-20 06:19:23

-----Original Message-----
From: David Sterba [mailto:dsterba@suse.cz]
Sent: Thursday, July 19, 2018 6:14 PM
To: dsterba@suse.cz; Gu, Jinxiang/顾 金香 <redacted>; Dan Carpenter <redacted>;
linux-btrfs@vger.kernel.org
Subject: Re: [bug report] btrfs: Add type check when reading a chunk

On Thu, Jul 19, 2018 at 11:22:01AM +0200, David Sterba wrote:
quoted
On Thu, Jul 19, 2018 at 08:18:25AM +0000, Gu, Jinxiang wrote:
quoted
quoted
-----Original Message-----
From: Dan Carpenter [mailto:dan.carpenter@oracle.com]
Sent: Thursday, July 19, 2018 4:11 PM
To: Gu, Jinxiang/顾 金香 <redacted>
Cc: linux-btrfs@vger.kernel.org
Subject: [bug report] btrfs: Add type check when reading a chunk

Hello Gu Jinxiang,

The patch 72e75ed03c8d: "btrfs: Add type check when reading a chunk"
from Jul 4, 2018, leads to the following static checker warning:

	fs/btrfs/volumes.c:6388 btrfs_check_chunk_valid()
	warn: AND to zero '0x4 & 0x1'

fs/btrfs/volumes.c
  6356          if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
  6357                  btrfs_err(fs_info, "invalid chunk stripe length: %llu",
  6358                            stripe_len);
  6359                  return -EIO;
  6360          }
  6361          if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6362              type) {
  6363                  btrfs_err(fs_info, "unrecognized chunk type: %llu",
  6364                            ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
  6365                              BTRFS_BLOCK_GROUP_PROFILE_MASK) &
  6366                            btrfs_chunk_type(leaf, chunk));
  6367                  return -EIO;
  6368          }
  6369
  6370          if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) {
  6371                  btrfs_err(fs_info, "missing chunk type flag: %llu", type);
  6372                  return -EIO;
  6373          }
  6374
  6375          if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
  6376              (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
  6377                  btrfs_err(fs_info,
  6378                          "system chunk with data or metadata type: %llu", type);
  6379                  return -EIO;
  6380          }
  6381
  6382          features = btrfs_super_incompat_flags(fs_info->super_copy);
  6383          if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
  6384                  mixed = 1;
  6385
  6386          if (!mixed) {
  6387                  if (type &
  6388                      (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) {
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Was this supposed to be | or perhaps check that both are set?
Yes. It should be |.
Thank you, I'll send a patch to fix it.
Not needed, I'll fix the patch directly.
And that leads to failed mount:

[   10.867868] BTRFS error (device vda): mixed chunk type in non-mixed mode: 1
[   10.871084] BTRFS error (device vda): failed to read chunk tree: -5
[   10.908541] BTRFS error (device vda): open_ctree failed

Please send fixed version.
I send a patch to fix this.
Patch: btrfs: fix bug of chunk type check
And, if possible, please just fold it into 72e75ed03c8d: "btrfs: Add type check when reading a chunk".

Thanks, Gu Jinxiang


���{.n�+�������+%�����ݶ��w��{.n�+����{���k~���^n�r���z���h����&���z��z�ޗ�+��+zf���h���~����i��������z_��j:+v���)ߣ�m
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help