nilfs2: validate file block counts during recovery
Subsystems (2)
PATCH 1/1 nilfs2: validate file block counts during recovery
nilfs_scan_dsync_log() trusts the block counts in each on-disk file information entry. If fi_ndatablk is greater than fi_nblocks, the data block loop can consume excessive summary entries and the later subtraction used to derive the number of node blocks underflows.
Reject inconsistent file information entries before consuming their block information.
--- fs/nilfs2/recovery.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/nilfs2/recovery.c +5 -0
@@ -322,6 +322,7 @@ static void nilfs_skip_summary_info(struct the_nilfs *nilfs,* * Return: 0 on success, or one of the following negative error codes on * failure: +* * %-EINVAL - Invalid block counts in a file information entry. * * %-EIO - I/O error. * * %-ENOMEM - Insufficient memory available. */
@@ -359,6 +360,10 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, ino =le64_to_cpu (finfo->fi_ino); nblocks =le32_to_cpu (finfo->fi_nblocks); ndatablk =le32_to_cpu (finfo->fi_ndatablk); +if (ndatablk > nblocks) { + err = -EINVAL ; + goto out; + } nnodeblk = nblocks - ndatablk;while (ndatablk-- >0 ) {
Signature · 1 line
2.43.0
Viacheslav Dubeyko
maintainerQuoted 33 lines · Aldo Ariel Panzardo
nilfs_scan_dsync_log()trusts the block counts in each on-disk file information entry. Iffi_ndatablkis greater thanfi_nblocks, the data
block loop can consume excessive summary entries and the later subtraction
used to derive the number of node blocks underflows.Reject inconsistent file information entries before consuming their block
information.Fixes 0f3e1c7f23f8 ("nilfs2: recovery functions")Signed-off-by Aldo Ariel Panzardo <[email protected]>---
fs/nilfs2/recovery.c | 5 +++++1 file changed, 5 insertions(+)fs/nilfs2/recovery.c +0
-0@@ -322,6 +322,7 @@ static void nilfs_skip_summary_info(structthe_nilfs *nilfs, * * Return: 0 on success, or one of the following negative errorcodes on
* failure:
+ * * %-EINVAL - Invalid block counts in a file information entry.
* * %-EIO - I/O error.
* * %-ENOMEM - Insufficient memory available.
*/
fs/nilfs2/recovery.c static int nilfs_scan_dsync_log(struct the_nilfs · line 365
Quoted 6 lines
fs/nilfs2/recovery.c +2
-0@@ -359,6 +360,10 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, ino = le64_to_cpu(finfo->fi_ino); nblocks = le32_to_cpu(finfo->fi_nblocks); ndatablk = le32_to_cpu(finfo->fi_ndatablk); +if (ndatablk > nblocks) { + err = -EINVAL ;
It sounds like -EIO because we have corrupted state of on-disk metadata.
Thanks,
Slava.
Quoted 5 lines
fs/nilfs2/recovery.c +2
-0+ goto out; + } nnodeblk = nblocks - ndatablk;
while (ndatablk-- > 0) {
Hi Slava,
Right, -EIO is more appropriate for corrupt on-disk metadata. Will fix in v2.
Aldo
PATCH v2 1/1 nilfs2: validate file block counts during recovery
In reply to Aldo Ariel Panzardonilfs_scan_dsync_log() trusts the block counts in each on-disk file information entry. If fi_ndatablk is greater than fi_nblocks, the data block loop can consume excessive summary entries and the later subtraction used to derive the number of node blocks underflows.
Reject inconsistent file information entries before consuming their block information.
--- fs/nilfs2/recovery.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/nilfs2/recovery.c +4 -0
@@ -359,6 +359,10 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, ino =le64_to_cpu (finfo->fi_ino); nblocks =le32_to_cpu (finfo->fi_nblocks); ndatablk =le32_to_cpu (finfo->fi_ndatablk); +if (ndatablk > nblocks) { + err = -EIO ; + goto out; + } nnodeblk = nblocks - ndatablk;while (ndatablk-- >0 ) {
Signature · 1 line
2.43.0
Quoted 32 lines · Aldo Ariel Panzardo
nilfs_scan_dsync_log()trusts the block counts in each on-disk file information entry. Iffi_ndatablkis greater thanfi_nblocks, the data
block loop can consume excessive summary entries and the later subtraction
used to derive the number of node blocks underflows.Reject inconsistent file information entries before consuming their block
information.Fixes 0f3e1c7f23f8 ("nilfs2: recovery functions")Signed-off-by Aldo Ariel Panzardo <[email protected]>---
fs/nilfs2/recovery.c | 4 ++++1 file changed, 4 insertions(+)fs/nilfs2/recovery.c +4
-0@@ -359,6 +359,10 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, ino = le64_to_cpu(finfo->fi_ino); nblocks = le32_to_cpu(finfo->fi_nblocks); ndatablk = le32_to_cpu(finfo->fi_ndatablk); +if (ndatablk > nblocks) { + err = -EIO ; + goto out; + } nnodeblk = nblocks - ndatablk;
Quoted 2 lines
while (ndatablk-- > 0) {
Looks good.
Thanks,
Slava.
Quoted 40 lines · Aldo Ariel Panzardo
nilfs_scan_dsync_log()trusts the block counts in each on-disk file information entry. Iffi_ndatablkis greater thanfi_nblocks, the data block loop can consume excessive summary entries and the later subtraction used to derive the number of node blocks underflows.Reject inconsistent file information entries before consuming their block information.
Fixes 0f3e1c7f23f8 ("nilfs2: recovery functions")Signed-off-by Aldo Ariel Panzardo <[email protected]>--- fs/nilfs2/recovery.c | 5 +++++ 1 file changed, 5 insertions(+)fs/nilfs2/recovery.c +5
-1@@ -322,6 +322,7 @@ static void nilfs_skip_summary_info(struct the_nilfs *nilfs,* * Return: 0 on success, or one of the following negative error codes on * failure: +* * %-EINVAL - Invalid block counts in a file information entry. * * %-EIO - I/O error. * * %-ENOMEM - Insufficient memory available. */ @@ -359,6 +360,10 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, ino =le64_to_cpu (finfo->fi_ino); nblocks =le32_to_cpu (finfo->fi_nblocks); ndatablk =le32_to_cpu (finfo->fi_ndatablk); +if (ndatablk > nblocks) { + err = -EINVAL ; + goto out; + } nnodeblk = nblocks - ndatablk;while (ndatablk-- >0 ) { --
Quoted 1 line
2.43.0
Hi Viacheslav,
Please apply this v1 patch instead of the v2 patch.
This function is called as part of mount operations. When format errors are detected during superblock reading or log scanning at mount time, returning -EINVAL rather than -EIO is in line with the mount system call behavior, so the v1 implementation is the correct one.
Also, please replace the 'Cc: stable' tag with the following tag, as with the previous patch:
Cc: [email protected] # Non-fatal bug fix; defer backport until a real issue is reported
I actually ran a test where a pseudo underflow of the nnodeblk variable occurred, but no issues that compromise system stability happened.
Even if nnodeblk becomes a large value, long-duration block device scanning does not occur; it simply skips the position and abandons roll-forward recovery midway. Since the mount normally succeeds, if anything, this silent failure is the issue.
However, this is based on the assumption that the file system image was intentionally tampered with (anything goes) with root privileges, including log checksums. Therefore, as long as it does not break the system, I do not believe it meets the stable kernel rules for backporting.
Thanks,
Ryusuke Konishi
Quoted 53 lines · Ryusuke Konishi
Quoted 44 lines · Aldo Ariel Panzardo
nilfs_scan_dsync_log()trusts the block counts in each on-disk file information entry. Iffi_ndatablkis greater thanfi_nblocks, the data
block loop can consume excessive summary entries and the later subtraction
used to derive the number of node blocks underflows.Reject inconsistent file information entries before consuming their block
information.Fixes 0f3e1c7f23f8 ("nilfs2: recovery functions")Signed-off-by Aldo Ariel Panzardo <[email protected]>---
fs/nilfs2/recovery.c | 5 +++++1 file changed, 5 insertions(+)fs/nilfs2/recovery.c +0
-0@@ -322,6 +322,7 @@ static void nilfs_skip_summary_info(structthe_nilfs *nilfs, * * Return: 0 on success, or one of the following negative errorcodes on
* failure:
+ * * %-EINVAL - Invalid block counts in a file information entry.
* * %-EIO - I/O error.
* * %-ENOMEM - Insufficient memory available.
*/fs/nilfs2/recovery.c +4
-0@@ -359,6 +360,10 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, ino = le64_to_cpu(finfo->fi_ino); nblocks = le32_to_cpu(finfo->fi_nblocks); ndatablk = le32_to_cpu(finfo->fi_ndatablk); + if (ndatablk > nblocks) { + err = -EINVAL; + goto out; + } nnodeblk = nblocks - ndatablk;Quoted 3 lines
while (ndatablk-- > 0) {
--
2.43.0Acked-by Ryusuke Konishi <[email protected]>Hi Viacheslav,
Quoted 7 lines
Please apply this v1 patch instead of the v2 patch.
This function is called as part of mount operations. When format errors are detected during superblock reading or log scanning at mount
time, returning-EINVALrather than-EIOis in line with the mount system call behavior, so the v1 implementation is the correct one.
I missed that. Thanks for the explanation.
Quoted 6 lines
Also, please replace the 'Cc: stable' tag with the following tag, as with the previous patch:
Cc: [email protected] # Non-fatal bug fix; defer backport until a real issue is reported
Damn! I missed this request. I already pushed the commit. Are you OK with that? :)
Quoted 10 lines
I actually ran a test where a pseudo underflow of the nnodeblk variable occurred, but no issues that compromise system stability happened.
Even if nnodeblk becomes a large value, long-duration block device scanning does not occur; it simply skips the position and abandons roll-forward recovery midway. Since the mount normally succeeds, if anything, this silent failure is the issue.
Quoted 6 lines
However, this is based on the assumption that the file system image was intentionally tampered with (anything goes) with root privileges, including log checksums. Therefore, as long as it does not break the system, I do not believe it meets the stable kernel rules for backporting.
Applied.
Thanks,
Slava.
Ryusuke Konishi
maintainerQuoted 10 lines · Viacheslav Dubeyko
Quoted 5 lines · Ryusuke Konishi
Also, please replace the 'Cc: stable' tag with the following tag, as with the previous patch:
Cc: [email protected] # Non-fatal bug fix; defer backport until a real issue is reported
Damn! I missed this request. I already pushed the commit. Are you OK with that? :)
Viacheslav,
Since we haven't hit the merge window yet, and linux-next (the destination where your for-next branch is integrated) is a daily integration tree intended to be rebased before being pulled into Linus's tree, updating the commit message on your branch now should be completely fine.
As documented in Documentation/maintainer/rebasing-and-merging.rst:
"Some trees (linux-next being a significant example) are frequently rebased by their nature..."
I think it would be better to fix the tag and overwrite-push it now rather than leaving it as is, though of course it will need to be frozen once we hit the merge window (or after the official release).
Thanks,
Ryusuke Konishi
Viacheslav Dubeyko
maintainerQuoted 24 lines · Ryusuke Konishi
Quoted 6 lines · Viacheslav Dubeyko
Quoted 4 lines · Ryusuke Konishi
Also, please replace the 'Cc: stable' tag with the following tag, as
with the previous patch:Quoted 7 lines
Quoted 3 lines
Cc: [email protected] # Non-fatal bug fix; defer backport
until a real issue is reportedDamn! I missed this request. I already pushed the commit. Are you OK
with that? :)Viacheslav,
Since we haven't hit the merge window yet, and linux-next (the destination where your for-next branch is integrated) is a daily integration tree intended to be rebased before being pulled into Linus's tree, updating the commit message on your branch now should be
completely fine.
Quoted 8 lines
As documented in
Documentation/maintainer/rebasing-and-merging.rst:
"Some trees (linux-next being a significant example) are frequently rebased by their nature..."I think it would be better to fix the tag and overwrite-push it now rather than leaving it as is, though of course it will need to be frozen once we hit the merge window (or after the official release).
Sorry, I have too busy day.
The commit message has been updated and pushed.
Thanks,
Slava.
Ryusuke Konishi
maintainerQuoted 35 lines · Viacheslav Dubeyko
Quoted 24 lines · Ryusuke Konishi
Quoted 6 lines · Viacheslav Dubeyko
Quoted 4 lines · Ryusuke Konishi
Also, please replace the 'Cc: stable' tag with the following tag, as
with the previous patch:Quoted 7 lines
Quoted 3 lines
Cc: [email protected] # Non-fatal bug fix; defer backport
until a real issue is reportedDamn! I missed this request. I already pushed the commit. Are you OK
with that? :)Viacheslav,
Since we haven't hit the merge window yet, and linux-next (the destination where your for-next branch is integrated) is a daily integration tree intended to be rebased before being pulled into Linus's tree, updating the commit message on your branch now should be
completely fine.Quoted 8 lines
As documented in
Documentation/maintainer/rebasing-and-merging.rst:
"Some trees (linux-next being a significant example) are frequently rebased by their nature..."I think it would be better to fix the tag and overwrite-push it now rather than leaving it as is, though of course it will need to be frozen once we hit the merge window (or after the official release).
Quoted 6 lines
Sorry, I have too busy day.
The commit message has been updated and pushed.
Thanks,
Slava.
No problem.
Thanks for handling this.
Ryusuke Konishi