Skip to contentSkip to conversation

exfat: fix range validation error in alloc and free cluster

PATCH Applied hyeongseok.kim 3 participants 3 messages Jun 4, 2020 – Jun 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exfat: fix range validation error in alloc and free cluster

There is check error in range condition that can never be entered even with invalid input.
Replace incorrent checking code with already existing valid checker.

---
 fs/exfat/fatent.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/exfat/fatent.c +2 -2
index 267e5e0..4e5c5c9 100644
@@ -169,7 +169,7 @@ int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
 		return 0;
 
 	/* check cluster validation */
-	if (p_chain->dir < 2 && p_chain->dir >= sbi->num_clusters) {
+	if (!is_valid_cluster(sbi, p_chain->dir)) {
 		exfat_err(sb, "invalid start cluster (%u)", p_chain->dir);
 		return -EIO;
 	}
@@ -346,7 +346,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
 	}
 
 	/* check cluster validation */
-	if (hint_clu < EXFAT_FIRST_CLUSTER && hint_clu >= sbi->num_clusters) {
+	if (!is_valid_cluster(sbi, hint_clu)) {
 		exfat_err(sb, "hint_cluster is invalid (%u)",
 			hint_clu);
 		hint_clu = EXFAT_FIRST_CLUSTER;
Signature · 1 line
2.7.4
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines

There is check error in range condition that can never be entered even with invalid input.
Replace incorrent checking code with already existing valid checker.

Looks good. Thank you!

Quoted 31 lines
---
 fs/exfat/fatent.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/exfat/fatent.c index 267e5e0..4e5c5c9 renamed from fs/exfat/fatent.c +0 -0

100644

fs/exfat/fatent.c +1 -1
@@ -169,7 +169,7 @@ int exfat_free_cluster(struct inode *inode, struct
 exfat_chain *p_chain)
 		return 0;
 
 	/* check cluster validation */
-	if (p_chain->dir < 2 && p_chain->dir >= sbi->num_clusters) {
+	if (!is_valid_cluster(sbi, p_chain->dir)) {
 		exfat_err(sb, "invalid start cluster (%u)", p_chain->dir);
 		return -EIO;
fs/exfat/fatent.c +1 -1
 	}
@@ -346,7 +346,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned
 int num_alloc,
 	}
 
 	/* check cluster validation */
-	if (hint_clu < EXFAT_FIRST_CLUSTER && hint_clu >= sbi->num_clusters)
 {
+	if (!is_valid_cluster(sbi, hint_clu)) {
 		exfat_err(sb, "hint_cluster is invalid (%u)",
fs/exfat/fatent.c +0 -1
 			hint_clu);
 		hint_clu = EXFAT_FIRST_CLUSTER;
--

2.7.4