Skip to contentSkip to conversation

f2fs: add additional sanity check in f2fs_acl_from_disk()

PATCH In review Chengguang Xu 4 participants 10 messages Aug 30, 2018 – Sep 5, 2018 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: add additional sanity check in f2fs_acl_from_disk()

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
 fs/f2fs/acl.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/acl.c +3 -0
index 111824199a88..79e9ea773070 100644
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
 	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
 	const char *end = value + size;
 
+	if (size < sizeof(f2fs_acl_header))
+		return ERR_PTR(-EINVAL);
+
 	if (hdr->a_version != cpu_to_le32(F2FS_ACL_VERSION))
 		return ERR_PTR(-EINVAL);
 
Signature · 6 lines
2.17.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
maintainer
#1 lore raw

Hi Chengguang,

Quoted 14 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
 fs/f2fs/acl.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 57

Quoted 5 lines
fs/f2fs/acl.c +2 -0
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
 	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
 	const char *end = value + size;
 
+	if (size < sizeof(f2fs_acl_header))
+		return ERR_PTR(-EINVAL);

I guess below codes have checked that already?

	count = f2fs_acl_count(size);
	if (count < 0)
		return ERR_PTR(-EINVAL);

Thanks,

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 61

Quoted 5 lines
fs/f2fs/acl.c +1 -0
+
 	if (hdr->a_version != cpu_to_le32(F2FS_ACL_VERSION))
 		return ERR_PTR(-EINVAL);
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

author
#2 lore raw
Quoted 20 lines · Chao Yu

Hi Chengguang,

Quoted 17 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
  fs/f2fs/acl.c | 3 +++
  1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
  	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
  	const char *end = value + size;
 
Quoted 7 lines

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 57

Quoted 2 lines
fs/f2fs/acl.c +2 -0
+	if (size < sizeof(f2fs_acl_header))
+		return ERR_PTR(-EINVAL);

I guess below codes have checked that already?

	count = f2fs_acl_count(size);
	if (count < 0)
		return ERR_PTR(-EINVAL);

Hi Chao,

Thanks for prompt reply.

I still think in a rare case, it can pass the check in f2fs_acl_count() and cause unexpected behavior.

For example, like below code path in f2fs_acl_count().

-> if (s < 0) {
            if (size % sizeof(struct f2fs_acl_entry_short)) return -1;
->        return size / sizeof(struct f2fs_acl_entry_short); }

Thanks,
Chengguang

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
Quoted 30 lines · On 2018/8/31 0:19, cgxu519 wrote:
Quoted 20 lines · Chao Yu

Hi Chengguang,

Quoted 17 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
  fs/f2fs/acl.c | 3 +++
  1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
  	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
  	const char *end = value + size;
 
Quoted 7 lines

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 57

Quoted 2 lines
fs/f2fs/acl.c +2 -0
+	if (size < sizeof(f2fs_acl_header))
+		return ERR_PTR(-EINVAL);

I guess below codes have checked that already?

	count = f2fs_acl_count(size);
	if (count < 0)
		return ERR_PTR(-EINVAL);
Quoted 8 lines

Hi Chao,

Thanks for prompt reply.

I still think in a rare case, it can pass the check in f2fs_acl_count() and cause unexpected behavior.

For example, like below code path in f2fs_acl_count().

if size < sizeof(f2fs_acl_header)

size -= sizeof(struct f2fs_acl_header);

size should be smaller than zero, right?

Quoted 5 lines

-> if (s < 0) {
            if (size % sizeof(struct f2fs_acl_entry_short)) return -1;
->        return size / sizeof(struct f2fs_acl_entry_short);

So the return value should be smaller than zero?

Thanks,

Quoted 17 lines

}

Thanks,
Chengguang

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 47 lines · Chao Yu
Quoted 30 lines · On 2018/8/31 0:19, cgxu519 wrote:
Quoted 20 lines · Chao Yu

Hi Chengguang,

Quoted 17 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
  fs/f2fs/acl.c | 3 +++
  1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
  	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
  	const char *end = value + size;
 
Quoted 7 lines

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 57

Quoted 2 lines
fs/f2fs/acl.c +2 -0
+	if (size < sizeof(f2fs_acl_header))
+		return ERR_PTR(-EINVAL);

I guess below codes have checked that already?

	count = f2fs_acl_count(size);
	if (count < 0)
		return ERR_PTR(-EINVAL);
Quoted 8 lines

Hi Chao,

Thanks for prompt reply.

I still think in a rare case, it can pass the check in f2fs_acl_count() and cause unexpected behavior.

For example, like below code path in f2fs_acl_count().

if size < sizeof(f2fs_acl_header)

size -= sizeof(struct f2fs_acl_header);

size should be smaller than zero, right?

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

-> if (s < 0) {
            if (size % sizeof(struct f2fs_acl_entry_short)) return -1;
->        return size / sizeof(struct f2fs_acl_entry_short);

So the return value should be smaller than zero?

size is unsigned so the return value will not be negative here.

Thanks,
Chengguang

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#5 lore raw
Quoted 51 lines · Chengguang Xu
Quoted 47 lines · Chao Yu
Quoted 30 lines · On 2018/8/31 0:19, cgxu519 wrote:
Quoted 20 lines · Chao Yu

Hi Chengguang,

Quoted 17 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
  fs/f2fs/acl.c | 3 +++
  1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
  	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
  	const char *end = value + size;
 
Quoted 7 lines

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 57

Quoted 2 lines
fs/f2fs/acl.c +2 -0
+	if (size < sizeof(f2fs_acl_header))
+		return ERR_PTR(-EINVAL);

I guess below codes have checked that already?

	count = f2fs_acl_count(size);
	if (count < 0)
		return ERR_PTR(-EINVAL);
Quoted 8 lines

Hi Chao,

Thanks for prompt reply.

I still think in a rare case, it can pass the check in f2fs_acl_count() and cause unexpected behavior.

For example, like below code path in f2fs_acl_count().

if size < sizeof(f2fs_acl_header)

size -= sizeof(struct f2fs_acl_header);

size should be smaller than zero, right?

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

-> if (s < 0) {
            if (size % sizeof(struct f2fs_acl_entry_short)) return -1;
->        return size / sizeof(struct f2fs_acl_entry_short);

So the return value should be smaller than zero?

size is unsigned so the return value will not be negative here.

You're right, I misread size_t as ssize_t, sorry.

Thanks,

Quoted 6 lines

Thanks,
Chengguang

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reviewed-by on v1 1/1
#6 lore raw
In reply to Chengguang Xu
Quoted 5 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

Thanks,

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer
#7 lore raw
In reply to Chengguang Xu
Quoted 14 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
 fs/f2fs/acl.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 56

Quoted 4 lines
fs/f2fs/acl.c +1 -0
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
 	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
 	const char *end = value + size;
 
+	if (size < sizeof(f2fs_acl_header))

sizeof(struct f2fs_acl_header)

I fixed the above, and merged.

Thanks,

Quoted 7 lines
fs/f2fs/acl.c +2 -0
+		return ERR_PTR(-EINVAL);
+
 	if (hdr->a_version != cpu_to_le32(F2FS_ACL_VERSION))
 		return ERR_PTR(-EINVAL);
 
Signature · 1 line
2.17.1

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#8 lore raw

Hi Jaegeuk,

Could you update dev-test branch? so I can rebase my patch on it. :)

Quoted 31 lines · Jaegeuk Kim
Quoted 14 lines · Chengguang Xu

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
 fs/f2fs/acl.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 56

Quoted 4 lines
fs/f2fs/acl.c +1 -0
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
 	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
 	const char *end = value + size;
 
+	if (size < sizeof(f2fs_acl_header))

sizeof(struct f2fs_acl_header)

I fixed the above, and merged.

Thanks,

Quoted 5 lines
fs/f2fs/acl.c +2 -0
+		return ERR_PTR(-EINVAL);
+
 	if (hdr->a_version != cpu_to_le32(F2FS_ACL_VERSION))
 		return ERR_PTR(-EINVAL);
 
Quoted 5 lines
Quoted 2 lines
Signature · 1 line
2.17.1

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer
#9 lore raw
Quoted 3 lines · Chao Yu

Hi Jaegeuk,

Could you update dev-test branch? so I can rebase my patch on it. :)

Will do soon. :)

Quoted 33 lines · Jaegeuk Kim
Quoted 31 lines · Chengguang Xu
Quoted 14 lines

Add additinal sanity check for irregular case(e.g. corruption). If size of extended attribution is smaller than size of acl header, then return -EINVAL.

---
 fs/f2fs/acl.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/acl.c +0 -0
index 111824199a88..79e9ea773070 100644

fs/f2fs/acl.c static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size) · line 56

Quoted 4 lines
fs/f2fs/acl.c +1 -0
@@ -53,6 +53,9 @@ static struct posix_acl *f2fs_acl_from_disk(const char *value, size_t size)
 	struct f2fs_acl_entry *entry = (struct f2fs_acl_entry *)(hdr + 1);
 	const char *end = value + size;
 
+	if (size < sizeof(f2fs_acl_header))

sizeof(struct f2fs_acl_header)

I fixed the above, and merged.

Thanks,

Quoted 5 lines
fs/f2fs/acl.c +2 -0
+		return ERR_PTR(-EINVAL);
+
 	if (hdr->a_version != cpu_to_le32(F2FS_ACL_VERSION))
 		return ERR_PTR(-EINVAL);
 
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Signature · 1 line
2.17.1

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot