|
Kmods SIG |
8b815c |
From b8155e95de38b25a69dfb03e4731fd6c5a28531e Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
8b815c |
From: Dan Carpenter <dan.carpenter@oracle.com>
|
|
Kmods SIG |
8b815c |
Date: Tue, 24 Aug 2021 10:51:04 +0300
|
|
Kmods SIG |
8b815c |
Subject: [Backport b8155e95de38] src: Fix error handling in
|
|
Kmods SIG |
8b815c |
indx_insert_into_root()
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
There are three bugs in this code:
|
|
Kmods SIG |
8b815c |
1) If indx_get_root() fails, then return -EINVAL instead of success.
|
|
Kmods SIG |
8b815c |
2) On the "/* make root external */" -EOPNOTSUPP; error path it should
|
|
Kmods SIG |
8b815c |
free "re" but it has a memory leak.
|
|
Kmods SIG |
8b815c |
3) If indx_new() fails then it will lead to an error pointer dereference
|
|
Kmods SIG |
8b815c |
when we call put_indx_node().
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
I've re-written the error handling to be more clear.
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
Fixes: 82cae269cfa9 ("src: Add initialization of super block")
|
|
Kmods SIG |
8b815c |
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
|
|
Kmods SIG |
8b815c |
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
|
|
Kmods SIG |
8b815c |
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
|
|
Kmods SIG |
8b815c |
---
|
|
Kmods SIG |
8b815c |
src/index.c | 36 ++++++++++++++++--------------------
|
|
Kmods SIG |
8b815c |
1 file changed, 16 insertions(+), 20 deletions(-)
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
diff --git a/src/index.c b/src/index.c
|
|
Kmods SIG |
8b815c |
index f4729aa50671f27de961305744b3839588696108..69c6c4e0b4d9bd76b79de148f164fec98b7fac9f 100644
|
|
Kmods SIG |
8b815c |
--- a/src/index.c
|
|
Kmods SIG |
8b815c |
+++ b/src/index.c
|
|
Kmods SIG |
8b815c |
@@ -1555,12 +1555,12 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
u32 root_size, new_root_size;
|
|
Kmods SIG |
8b815c |
struct ntfs_sb_info *sbi;
|
|
Kmods SIG |
8b815c |
int ds_root;
|
|
Kmods SIG |
8b815c |
- struct INDEX_ROOT *root, *a_root = NULL;
|
|
Kmods SIG |
8b815c |
+ struct INDEX_ROOT *root, *a_root;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/* Get the record this root placed in */
|
|
Kmods SIG |
8b815c |
root = indx_get_root(indx, ni, &attr, &mi);
|
|
Kmods SIG |
8b815c |
if (!root)
|
|
Kmods SIG |
8b815c |
- goto out;
|
|
Kmods SIG |
8b815c |
+ return -EINVAL;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/*
|
|
Kmods SIG |
8b815c |
* Try easy case:
|
|
Kmods SIG |
8b815c |
@@ -1592,10 +1592,8 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/* Make a copy of root attribute to restore if error */
|
|
Kmods SIG |
8b815c |
a_root = kmemdup(attr, asize, GFP_NOFS);
|
|
Kmods SIG |
8b815c |
- if (!a_root) {
|
|
Kmods SIG |
8b815c |
- err = -ENOMEM;
|
|
Kmods SIG |
8b815c |
- goto out;
|
|
Kmods SIG |
8b815c |
- }
|
|
Kmods SIG |
8b815c |
+ if (!a_root)
|
|
Kmods SIG |
8b815c |
+ return -ENOMEM;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/* copy all the non-end entries from the index root to the new buffer.*/
|
|
Kmods SIG |
8b815c |
to_move = 0;
|
|
Kmods SIG |
8b815c |
@@ -1605,7 +1603,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
for (e = e0;; e = hdr_next_de(hdr, e)) {
|
|
Kmods SIG |
8b815c |
if (!e) {
|
|
Kmods SIG |
8b815c |
err = -EINVAL;
|
|
Kmods SIG |
8b815c |
- goto out;
|
|
Kmods SIG |
8b815c |
+ goto out_free_root;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
if (de_is_last(e))
|
|
Kmods SIG |
8b815c |
@@ -1613,14 +1611,13 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
to_move += le16_to_cpu(e->size);
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
- n = NULL;
|
|
Kmods SIG |
8b815c |
if (!to_move) {
|
|
Kmods SIG |
8b815c |
re = NULL;
|
|
Kmods SIG |
8b815c |
} else {
|
|
Kmods SIG |
8b815c |
re = kmemdup(e0, to_move, GFP_NOFS);
|
|
Kmods SIG |
8b815c |
if (!re) {
|
|
Kmods SIG |
8b815c |
err = -ENOMEM;
|
|
Kmods SIG |
8b815c |
- goto out;
|
|
Kmods SIG |
8b815c |
+ goto out_free_root;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
@@ -1637,7 +1634,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
if (ds_root > 0 && used + ds_root > sbi->max_bytes_per_attr) {
|
|
Kmods SIG |
8b815c |
/* make root external */
|
|
Kmods SIG |
8b815c |
err = -EOPNOTSUPP;
|
|
Kmods SIG |
8b815c |
- goto out;
|
|
Kmods SIG |
8b815c |
+ goto out_free_re;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
if (ds_root)
|
|
Kmods SIG |
8b815c |
@@ -1667,7 +1664,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
/* bug? */
|
|
Kmods SIG |
8b815c |
ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
|
|
Kmods SIG |
8b815c |
err = -EINVAL;
|
|
Kmods SIG |
8b815c |
- goto out1;
|
|
Kmods SIG |
8b815c |
+ goto out_free_re;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
if (err) {
|
|
Kmods SIG |
8b815c |
@@ -1678,7 +1675,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
/* bug? */
|
|
Kmods SIG |
8b815c |
ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
- goto out1;
|
|
Kmods SIG |
8b815c |
+ goto out_free_re;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
e = (struct NTFS_DE *)(root + 1);
|
|
Kmods SIG |
8b815c |
@@ -1689,7 +1686,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
n = indx_new(indx, ni, new_vbn, sub_vbn);
|
|
Kmods SIG |
8b815c |
if (IS_ERR(n)) {
|
|
Kmods SIG |
8b815c |
err = PTR_ERR(n);
|
|
Kmods SIG |
8b815c |
- goto out1;
|
|
Kmods SIG |
8b815c |
+ goto out_free_re;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
hdr = &n->index->ihdr;
|
|
Kmods SIG |
8b815c |
@@ -1716,7 +1713,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
put_indx_node(n);
|
|
Kmods SIG |
8b815c |
fnd_clear(fnd);
|
|
Kmods SIG |
8b815c |
err = indx_insert_entry(indx, ni, new_de, ctx, fnd);
|
|
Kmods SIG |
8b815c |
- goto out;
|
|
Kmods SIG |
8b815c |
+ goto out_free_root;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/*
|
|
Kmods SIG |
8b815c |
@@ -1726,7 +1723,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
e = hdr_insert_de(indx, hdr, new_de, NULL, ctx);
|
|
Kmods SIG |
8b815c |
if (!e) {
|
|
Kmods SIG |
8b815c |
err = -EINVAL;
|
|
Kmods SIG |
8b815c |
- goto out1;
|
|
Kmods SIG |
8b815c |
+ goto out_put_n;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
fnd_push(fnd, n, e);
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
@@ -1735,12 +1732,11 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
n = NULL;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
-out1:
|
|
Kmods SIG |
8b815c |
+out_put_n:
|
|
Kmods SIG |
8b815c |
+ put_indx_node(n);
|
|
Kmods SIG |
8b815c |
+out_free_re:
|
|
Kmods SIG |
8b815c |
kfree(re);
|
|
Kmods SIG |
8b815c |
- if (n)
|
|
Kmods SIG |
8b815c |
- put_indx_node(n);
|
|
Kmods SIG |
8b815c |
-
|
|
Kmods SIG |
8b815c |
-out:
|
|
Kmods SIG |
8b815c |
+out_free_root:
|
|
Kmods SIG |
8b815c |
kfree(a_root);
|
|
Kmods SIG |
8b815c |
return err;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
--
|
|
Kmods SIG |
8b815c |
2.31.1
|
|
Kmods SIG |
8b815c |
|