]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
fs/ntfs3: Validate ff offset
authorlei lu <llfamsec@gmail.com>
Tue, 28 May 2024 18:52:22 +0000 (02:52 +0800)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Wed, 26 Jun 2024 12:48:51 +0000 (15:48 +0300)
This adds sanity checks for ff offset. There is a check
on rt->first_free at first, but walking through by ff
without any check. If the second ff is a large offset.
We may encounter an out-of-bound read.

Signed-off-by: lei lu <llfamsec@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/fslog.c

index 763644f90094bb64c72ee493db4e84fff48382be..6c18dc6c4cec3f81a334a3ef73bbaf576fc5cb31 100644 (file)
@@ -724,7 +724,8 @@ static bool check_rstbl(const struct RESTART_TABLE *rt, size_t bytes)
 
        if (!rsize || rsize > bytes ||
            rsize + sizeof(struct RESTART_TABLE) > bytes || bytes < ts ||
-           le16_to_cpu(rt->total) > ne || ff > ts || lf > ts ||
+           le16_to_cpu(rt->total) > ne ||
+                       ff > ts - sizeof(__le32) || lf > ts - sizeof(__le32) ||
            (ff && ff < sizeof(struct RESTART_TABLE)) ||
            (lf && lf < sizeof(struct RESTART_TABLE))) {
                return false;
@@ -754,6 +755,9 @@ static bool check_rstbl(const struct RESTART_TABLE *rt, size_t bytes)
                        return false;
 
                off = le32_to_cpu(*(__le32 *)Add2Ptr(rt, off));
+
+               if (off > ts - sizeof(__le32))
+                       return false;
        }
 
        return true;